Coder Social home page Coder Social logo

eshmu / gphotos-upload Goto Github PK

View Code? Open in Web Editor NEW
139.0 9.0 53.0 17 KB

Simple but flexible script to upload photos to Google Photos and add to a particular album. Useful if you have photos in a directory structure that you want to reflect as Google Photos albums.

Python 100.00%
google-photos google-photos-albums google-photos-api

gphotos-upload's Introduction

gphotos-upload

Simple but flexible script to upload photos to Google Photos. Useful if you have photos in a directory structure that you want to reflect as Google Photos albums.

Usage

usage: upload.py [-h] [--auth  auth_file] [--album album_name]
                 [--log log_file]
                 [photo [photo ...]]

Upload photos to Google Photos.

positional arguments:
  photo               filename of a photo to upload

optional arguments:
  -h, --help          show this help message and exit
  --auth  auth_file   file for reading/storing user authentication tokens
  --album album_name  name of photo album to create (if it doesn't exist). Any
                      uploaded photos will be added to this album.
  --log log_file      name of output file for log messages

Setup

Obtaining a Google Photos API key

  1. Obtain a Google Photos API key (Client ID and Client Secret) by following the instructions on Getting started with Google Photos REST APIs

NOTE When selecting your application type in Step 4 of "Request an OAuth 2.0 client ID", please select "Other". There's also no need to carry out step 5 in that section.

  1. Replace YOUR_CLIENT_ID in the client_id.json file with the provided Client ID.
  2. Replace YOUR_CLIENT_SECRET in the client_id.json file wiht the provided Client Secret.

Installing dependencies and running the script

  1. Make sure you have Python 3.7 installed on your system
  2. If needed, install pipenv via pip install pipenv
  3. Change to the directory where you installed this script
  4. Run pipenv install to download and install all the dependencies
  5. Run pipenv shell to open a shell with all the dependencies available (you'll need to do this every time you want to run the script)
  6. Now run the script via python upload.py as desired. Use python upload.py -h to get help.

gphotos-upload's People

Contributors

eshmu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gphotos-upload's Issues

Error while uploading video files >2GB

Uploading video files >2GB doesn't work

Error log

Traceback (most recent call last):
File "upload.py", line 206, in
main()
File "upload.py", line 196, in main
upload_photos(session, args.photos, args.album_name)
File "upload.py", line 156, in upload_photos
upload_token = session.post('https://photoslibrary.googleapis.com/v1/uploads', photo_bytes)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/requests/sessions.py", line 572, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/google/auth/transport/requests.py", line 201, in request
method, url, data=data, headers=request_headers, **kwargs)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/requests/sessions.py", line 524, in request
resp = self.send(prep, **send_kwargs)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/requests/sessions.py", line 637, in send
r = adapter.send(request, **kwargs)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/Users/yusuf/.local/share/virtualenvs/gphotos-upload-master-Q2NAzFMA/lib/python3.7/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 1055, in _send_output
self.send(chunk)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/http/client.py", line 977, in send
self.sock.sendall(data)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ssl.py", line 1015, in sendall
v = self.send(byte_view[count:])
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ssl.py", line 984, in send
return self._sslobj.write(data)
OverflowError: string longer than 2147483647 bytes

Automatic auth flow not working

When I specify --auth option with file, refresh token is None and because of that auth flow without browser doesn't work. How can I fix this to work in cron job?

Can you add some examples of the command please?

I am running it and it shows me all my albums, and opens a new one (even if this name already exists),

  1. if I don't use album_name, will it take the folder's name?
  2. can I make it go through a folder of a few folders somehow?
    or should I use an external script to do that loop?

thanks!

thanks!

Upload does not include photo Description/Caption

Regarding eshmu's upload.py, line 160:
create_body = json.dumps({"albumId":album_id, "newMediaItems":[{"description":"","simpleMediaItem":{"uploadToken":upload_token.content.decode()}}]}, indent=4)

I am trying to upload JPGs to Google Photos with a description. However, when I set the description, this field is entirely ignored by Google Photos:
create_body = json.dumps({"albumId":album_id, "newMediaItems":[{"description":"THIS TEXT IS IGNORED","simpleMediaItem":{"uploadToken":upload_token.content.decode()}}]}, indent=4)

How can this very helpful python script be modified to include the photo captions?
This is the issue to be addressed (but in python):
https://stackoverflow.com/questions/72639040/programmatically-set-a-google-photos-caption

Thank you!

upload.py does nothing when run

$ python -m venv venv
$ source venv/bin/activate
$ pip install google-auth-oauthlib

I followed directions to get the client_id and client_secret and inserted that into my client_id.json file.
I then try to upload a photo to an existing album:

$ python ./upload.py --album "EXISTING_ALBUM" pic.jpg

and the script just sits there and doesn't do anything. I have to hit Ctrl-CI t to exit. I try adding the --log with a log file and the file is empty after I run the same command. Any suggestions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.