|
@ -40,6 +40,7 @@ class Connection: |
|
|
self.nextcloud_pass = data['pass'] |
|
|
self.nextcloud_pass = data['pass'] |
|
|
self.nextcloud_url = data['url'] |
|
|
self.nextcloud_url = data['url'] |
|
|
self.nextcloud_destination_folder = data['destination_folder'] |
|
|
self.nextcloud_destination_folder = data['destination_folder'] |
|
|
|
|
|
self.google_connect() |
|
|
|
|
|
|
|
|
def google_connect(self): |
|
|
def google_connect(self): |
|
|
# The file token.json stores the user's access and refresh tokens, and is |
|
|
# The file token.json stores the user's access and refresh tokens, and is |
|
@ -49,7 +50,7 @@ class Connection: |
|
|
self.creds = Credentials.from_authorized_user_file('token.json', self.SCOPES) |
|
|
self.creds = Credentials.from_authorized_user_file('token.json', self.SCOPES) |
|
|
# If there are no (valid) credentials available, let the user log in. |
|
|
# If there are no (valid) credentials available, let the user log in. |
|
|
if not self.creds or not self.creds.valid: |
|
|
if not self.creds or not self.creds.valid: |
|
|
if self.creds and self.creds.expired and self.reds.refresh_token: |
|
|
if self.creds and self.creds.expired and self.creds.refresh_token: |
|
|
self.creds.refresh(Request()) |
|
|
self.creds.refresh(Request()) |
|
|
else: |
|
|
else: |
|
|
flow = InstalledAppFlow.from_client_secrets_file( |
|
|
flow = InstalledAppFlow.from_client_secrets_file( |
|
@ -65,15 +66,15 @@ def download(connection, next_page=None): |
|
|
try: |
|
|
try: |
|
|
service = build('photoslibrary', 'v1', credentials=connection.creds, static_discovery=False) |
|
|
service = build('photoslibrary', 'v1', credentials=connection.creds, static_discovery=False) |
|
|
|
|
|
|
|
|
results = service.mediaItems().list(pageSize=100, pageToken=next_page).execute() |
|
|
results = service.mediaItems().list(pageSize=20, pageToken=next_page).execute() |
|
|
|
|
|
|
|
|
items = results.get('mediaItems', []) |
|
|
items = results.get('mediaItems', []) |
|
|
next_page = results.get('nextPageToken') |
|
|
next_page = results.get('nextPageToken') |
|
|
images = [] |
|
|
|
|
|
|
|
|
|
|
|
for item in items: |
|
|
for item in items: |
|
|
print(f"{item['filename']} {item['mimeType']}") |
|
|
print(f"{item['filename']} {item['mimeType']}") |
|
|
url = connection.nextcloud_url + '/remote.php/dav/files/' + connection.nextcloud_user + '/' + connection.nextcloud_destination_folder + '/' + item['filename'] |
|
|
url = connection.nextcloud_url + '/remote.php/dav/files/' + connection.nextcloud_user + '/' + connection.nextcloud_destination_folder + '/' + item['filename'] |
|
|
|
|
|
if requests.get(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass)).status_code != 200: |
|
|
if "video" in item['mimeType']: |
|
|
if "video" in item['mimeType']: |
|
|
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content) |
|
|
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content) |
|
|
else: |
|
|
else: |
|
@ -89,7 +90,7 @@ def download(connection, next_page=None): |
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
connection = Connection() |
|
|
connection = Connection() |
|
|
next_page = download(connection) |
|
|
next_page = download(connection) |
|
|
while next_page != 'null': |
|
|
while next_page != None: |
|
|
next_page = download(connection, next_page) |
|
|
next_page = download(connection, next_page) |
|
|
print('done') |
|
|
print('done') |
|
|
# [END docs_quickstart] |
|
|
# [END docs_quickstart] |