Moved fetching assets into a function as preparation for supporting API changes in 1.106.1
This commit is contained in:
parent
8b9c7722d9
commit
aab24346d1
1 changed files with 24 additions and 18 deletions
|
@ -141,23 +141,9 @@ def create_album_name(path_chunks):
|
||||||
logging.debug("album_name_chunks = %s", album_name_chunks)
|
logging.debug("album_name_chunks = %s", album_name_chunks)
|
||||||
return album_level_separator.join(album_name_chunks)
|
return album_level_separator.join(album_name_chunks)
|
||||||
|
|
||||||
requests_kwargs = {
|
# Fetches assets from the Immich API
|
||||||
'headers' : {
|
# Takes different API versions into account for compatibility
|
||||||
'x-api-key': api_key,
|
def fetchAssets():
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Accept': 'application/json'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# append trailing slash to all root paths
|
|
||||||
for i in range(len(root_paths)):
|
|
||||||
if root_paths[i][-1] != '/':
|
|
||||||
root_paths[i] = root_paths[i] + '/'
|
|
||||||
# append trailing slash to root URL
|
|
||||||
if root_url[-1] != '/':
|
|
||||||
root_url = root_url + '/'
|
|
||||||
|
|
||||||
logging.info("Requesting all assets")
|
|
||||||
assets = []
|
assets = []
|
||||||
# Initial API call, let's fetch our first chunk
|
# Initial API call, let's fetch our first chunk
|
||||||
r = requests.get(root_url+'asset?take='+str(number_of_assets_to_fetch_per_request), **requests_kwargs)
|
r = requests.get(root_url+'asset?take='+str(number_of_assets_to_fetch_per_request), **requests_kwargs)
|
||||||
|
@ -176,6 +162,26 @@ while len(r.json()) == number_of_assets_to_fetch_per_request:
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
logging.debug("Received %s assets with chunk", len(r.json()))
|
logging.debug("Received %s assets with chunk", len(r.json()))
|
||||||
assets = assets + r.json()
|
assets = assets + r.json()
|
||||||
|
return assets
|
||||||
|
|
||||||
|
requests_kwargs = {
|
||||||
|
'headers' : {
|
||||||
|
'x-api-key': api_key,
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Accept': 'application/json'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# append trailing slash to all root paths
|
||||||
|
for i in range(len(root_paths)):
|
||||||
|
if root_paths[i][-1] != '/':
|
||||||
|
root_paths[i] = root_paths[i] + '/'
|
||||||
|
# append trailing slash to root URL
|
||||||
|
if root_url[-1] != '/':
|
||||||
|
root_url = root_url + '/'
|
||||||
|
|
||||||
|
logging.info("Requesting all assets")
|
||||||
|
assets = fetchAssets()
|
||||||
logging.info("%d photos found", len(assets))
|
logging.info("%d photos found", len(assets))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue