|
|
@ -40,6 +40,7 @@ class Connection: |
|
|
|
self.nextcloud_pass = data['pass'] |
|
|
|
self.nextcloud_url = data['url'] |
|
|
|
self.nextcloud_destination_folder = data['destination_folder'] |
|
|
|
self.google_connect() |
|
|
|
|
|
|
|
def google_connect(self): |
|
|
|
# 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) |
|
|
|
# If there are no (valid) credentials available, let the user log in. |
|
|
|
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()) |
|
|
|
else: |
|
|
|
flow = InstalledAppFlow.from_client_secrets_file( |
|
|
@ -65,15 +66,15 @@ def download(connection, next_page=None): |
|
|
|
try: |
|
|
|
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', []) |
|
|
|
next_page = results.get('nextPageToken') |
|
|
|
images = [] |
|
|
|
|
|
|
|
for item in items: |
|
|
|
print(f"{item['filename']} {item['mimeType']}") |
|
|
|
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']: |
|
|
|
requests.put(url, auth=HTTPBasicAuth(connection.nextcloud_user, connection.nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content) |
|
|
|
else: |
|
|
@ -89,7 +90,7 @@ def download(connection, next_page=None): |
|
|
|
if __name__ == '__main__': |
|
|
|
connection = Connection() |
|
|
|
next_page = download(connection) |
|
|
|
while next_page != 'null': |
|
|
|
while next_page != None: |
|
|
|
next_page = download(connection, next_page) |
|
|
|
print('done') |
|
|
|
# [END docs_quickstart] |