diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fbd0668 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +nextcloud_auth.json \ No newline at end of file diff --git a/app.py b/app.py index 1fb7040..2c370c3 100644 --- a/app.py +++ b/app.py @@ -16,18 +16,21 @@ from __future__ import print_function import os.path +import requests, json +from requests.auth import HTTPBasicAuth +from httplib2 import Http from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build from googleapiclient.errors import HttpError +from googleapiclient.http import MediaIoBaseDownload + # If modifying these scopes, delete the file token.json. -SCOPES = ['https://www.googleapis.com/auth/documents.readonly'] +SCOPES = ['https://www.googleapis.com/auth/photoslibrary'] -# The ID of a sample document. -DOCUMENT_ID = '195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE' def main(): @@ -52,13 +55,31 @@ def main(): with open('token.json', 'w') as token: token.write(creds.to_json()) + with open('nextcloud_auth.json') as next_auth: + data = json.load(next_auth) + nextcloud_user = data['user'] + nextcloud_pass = data['pass'] + try: - service = build('drive', 'v3', credentials=creds) + service = build('photoslibrary', 'v1', credentials=creds, static_discovery=False) + + results = service.mediaItems().list().execute() + + items = results.get('mediaItems', []) + images = [] + + for item in items: + print(f"{item['filename']} {item['mimeType']}") + url = "https://homelinuxserver.ddns.net/remote.php/dav/files/arthur/data/Backup/photos/"+item['filename'] + print(url) + if "video" in item['mimeType']: + requests.put(url, auth=HTTPBasicAuth(nextcloud_user, nextcloud_pass), data=requests.get(item['baseUrl']+'=dv').content) + else: + requests.put(url, auth=HTTPBasicAuth(nextcloud_user, nextcloud_pass), data=requests.get(item['baseUrl']+'=d').content) + + print('done !') - # Retrieve the documents contents from the Docs service. - document = service.documents().get(documentId=DOCUMENT_ID).execute() - print('The title of the document is: {}'.format(document.get('title'))) except HttpError as err: print(err) diff --git a/requirement.txt b/requirement.txt index 1305ee6..1d0d769 100644 --- a/requirement.txt +++ b/requirement.txt @@ -1,19 +1,19 @@ -cachetools==5.2.0 -certifi==2022.12.7 -charset-normalizer==2.1.1 -google-api-core==2.11.0 -google-api-python-client==2.71.0 -google-auth==2.15.0 -google-auth-httplib2==0.1.0 -googleapis-common-protos==1.57.1 -httplib2==0.21.0 -idna==3.4 -protobuf==4.21.12 -pyasn1==0.4.8 -pyasn1-modules==0.2.8 -pyparsing==3.0.9 -requests==2.28.1 -rsa==4.9 -six==1.16.0 -uritemplate==4.1.1 -urllib3==1.26.13 +cachetools==5.2.0 +certifi==2022.12.7 +charset-normalizer==2.1.1 +google-api-core==2.11.0 +google-api-python-client==2.71.0 +google-auth==2.15.0 +google-auth-httplib2==0.1.0 +googleapis-common-protos==1.57.1 +httplib2==0.21.0 +idna==3.4 +protobuf==4.21.12 +pyasn1==0.4.8 +pyasn1-modules==0.2.8 +pyparsing==3.0.9 +requests==2.28.1 +rsa==4.9 +six==1.16.0 +uritemplate==4.1.1 +urllib3==1.26.13 diff --git a/token.json b/token.json index b55a5b3..70bc83a 100644 --- a/token.json +++ b/token.json @@ -1 +1 @@ -{"token": "ya29.a0AX9GBdULPvaziEUVBLWIIOsklGJfK5NQMK-i4_w75KcevtfVJAPi3VE_Lmal8Dd2A0by2uSlGfeE1GTuCzN573KJWwUtN_B8pwNMms7ICX7DORRWomCH01shCsN7UoC1PZJGtVuTDSsZRLeMboAfZIsjlGNEaCgYKAXUSARMSFQHUCsbCf0kSDh1XJROzQs-xbgNqdA0163", "refresh_token": "1//03yth_jXiKf1MCgYIARAAGAMSNwF-L9IraU74M3oUMX3z-m4tc7HjPWfPCcjfrTzIwocPp0a18ru_PQQ-JdSN9_5upP0eYGkElyk", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "114734902818-12qkdhcljn2cjtlffmmag6ahq85ig6bb.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/documents.readonly"], "expiry": "2023-01-09T17:16:14.720449Z"} \ No newline at end of file +{"token": "ya29.a0AX9GBdUHoUjUGSu4S7_VdbS0kmoHO3rvcJlC2hAOO5gHc8Ha3FDBx6G0zdjtV2SeIaJXPVVHvvMuxDZn37lMTXWQObhVIb3cseSkTE2Lh-HcSd6FhQXuLTApl77mI-2MjIYD49Ld5e6dTCDig9PIHxyaag4HzSIaCgYKAWUSAQASFQHUCsbC6VZE2PWen5SOAsH-58bOrA0166", "refresh_token": "1//0306exYla7apXCgYIARAAGAMSNwF-L9IrDTP2kdneYUP7CBpJ_oqtdWfvtIuuaCDaxySRfADycVywQjJ8C1jjrRCCo_1N16vlxdA", "token_uri": "https://oauth2.googleapis.com/token", "client_id": "114734902818-12qkdhcljn2cjtlffmmag6ahq85ig6bb.apps.googleusercontent.com", "client_secret": "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", "scopes": ["https://www.googleapis.com/auth/photoslibrary"], "expiry": "2023-01-10T22:18:47.449544Z"} \ No newline at end of file