-
Notifications
You must be signed in to change notification settings - Fork 169
google colab request #388
Comments
Hi, thanks for the suggestion. I'm not that keen on this because gphotos-sync was born out of Google deprecating its own photos-drive sync, so we moved on from this a long time ago. What is your use case? If you already have photos in Google why have them in two places in Google (and use up your Google disk quota) ? If I were to look at this I'd prefer to do it is a desktop app that talks to the photos and drive APIs. That is because Notebooks don't make a great development environment due to lack of version control (at least last time I looked - this is my only effort in colab notebooks https://colab.research.google.com/drive/1zBHuFfGpqkv8I96epPfo45xxyKg2_FTh?usp=sharing) |
Thanks @gilesknap for your quick reply. The reason is that: I have a shared drive with great unusual space, meanwhile my own account has 15gb limit. I want to copy my photos and videos from my google photos to that shared drive so that I can make use of my shared drive to store medias. I want to do this on google colab because the download and upload speed is high. Hope you could help me with this. |
I would not recommend this for 2 reasons:
If you still want this and are interested in doing it yourself, I'm happy to help with ideas and some code pointers. |
Oh, and by the way, one of the API limitations is you can't delete any photos unless they were uploaded by the same App. Therefore you would need to delete them manually to get your space back after the tool did a copy to drive. This is obviously error prone and a risk to your photos. The delete issue is one of many that have been outstanding for years and Google is simply not going to fix. See: |
Thanks @gilesknap for your reply, well I think I might need an api to get the list of filenames on google photos and make sure that every filename in that list is present in my shared drive. If a single filename is not present, I might copy that single file to my shared drive, can I do that? And after that I can safely delete everything in my google photo? |
This is one of the big issues I faced with gphotos-sync. The mapping between allowed names in the library and allowed filenames is a little fiddly, for example the same filename may appear multiple times in the same album. Since Drive is your target it would also allow the same filename multiple times. HOWEVER you are left to work out how to know which is which, if you have two PHOTO1 in photos but only one in Drive then which one do you copy over? To solve this gphotos-sync uses a database and keeps additional meta-data on each photo, including what it got called on the local filesystem. To simply see how you list photos in the library you could look at gphotos-sync/src/gphotos_sync/GooglePhotosIndex.py Lines 137 to 227 in 2f6bcbb
The truth is this is non-trivial and it is why I made the project read-only. |
I should be fair and say that modern cameras are pretty good at creating unique file names for their images. My collection goes back to 1996 and in those days cameras reset the image name counter on each memory card clean. I have hundreds of Image001.jpg in my collection! So you could try ignoring this issue and assume that filenames are unique. But you would loose photos if this turned out not to be true. |
Yeah I think so, I probably don't have 2 files with the same name but with different metadata. Google photos automatically backups my photos and videos on my phone so that's why I'm using it. And I'd say the photos and videos on my phone are numbered distinctly so there's no issue unless I reset my phone and it numbers from 0. I guess I might need a feature where when it sees a file with the same filename, it would check 2 metadatas and if they're the same, it skips, otherwise rename any of the two files to like xxx(2).png or sth then proceeds to copy. |
Exactly. But you need a consistent way to get from metadata to files named (2) or (3) etc. You can't just do it in date order because you are going to be deleting files from the photos source. This is why I keep a DB of what I named a file. I also try to be consistent if someone wants to flush the DB and start again - but I have not been successful in coping with all corner cases. Rebuilding the DB after some files have been deleted from the source may not result in the same filenames the second time a cause the sync to overwrite already copied files. |
I think this would be a better starting point for you instead of reading my code. And once you have that working the rest of the REST API is documented here: Drive has a similar REST API. I've had a google around and it looks like there are a few out of date python libraries wrapping it - not sure what to advise on this without more research |
Seems fairly complicated with filenames and duplicate checking haha. Well I guess as long as I use the same device and I don't reset, I think I won't encounter any problem with filenames and duplicates. So my plan to copy to drive should work right? |
I think the principal of what you want to do is viable.
You just need to be sure you can verify that you have a copies of files
before you delete them from photos.
In my view it is quite difficult to guarantee that especially since you
will need to do the deletes manually.
…On Sat, 1 Oct 2022, 19:11 mikebilly, ***@***.***> wrote:
Seems fairly complicated with filenames and duplicate checking haha. Well
I guess as long as I use the same device and I don't reset, I think I won't
encounter any problem with filenames and duplicates. So my plan to copy to
drive should work right?
—
Reply to this email directly, view it on GitHub
<#388 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHLRW42MGQZBBNP5HJ3I6LWBB5E3ANCNFSM6AAAAAAQ2PTBCM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thank you for your helpful information, I'll begin to try to make this work on colab tomorrow |
Good luck. Closing this as its not a gphotos-sync issue. I'll still respond here if you continue to post. |
This is the first error that I got.
|
This is just saying that the default auth flow port 8080 is already in use. You can choose a different port on the command line with --port (see gphotos-sync --help). |
I think you are using a function from the oauth2client library. That is deprecated and you need to use https://github.com/googleapis/google-auth-library-python-oauthlib. Now you might be able to do clever stuff because you are already logged in to Collab Notebooks, but I don't have any knowledge of that. Instead, I would hope that the authentication code from gphotos-sync here should still work for you - you would need to make the token locally on your workstation first as the authetication flow only works on a local browser. See setting up for headless browsers here. https://gilesknap.github.io/gphotos-sync/main/tutorials/installation.html#headless-gphotos-sync-servers |
Yeah that's what I'm facing, I want to do the authorization phase that gives me the token and credentials and everything by using my |
As I've mentioned above, this authorization function works for my other project
So I've modified your authorization function from:
to
(from
|
For that error, I've added this code:
and changed
to
But now I get this error:
|
So I added these commands:
and it works.
I get this message:
However, the copied photos and videos are not in original quality. |
Yep. Remember I said the API was crippled. Again this is one Google has been sitting on for years. I don't mind the images too much because I cant see any visual difference with my image resolutions. But the videos are awful. ALSO: note that you loose GPS info from your images. |
Good work getting the auth going though!! |
Thanks @gilesknap, I got your api working, but the only issue is that it doesn't download original quality videos and it strips gps info, for that reason I can't use google photo api. I'm looking for some sort of google takeout api. |
Yeah, sorry about that - I should have thought to mention those specific limitations for your use case. (it's not my API its Google's!! :-) |
Hi!, Thanks for your amazing repo. I'd like to suggest creating a colab notebook so that I can easily copy photos and videos from google photos and save it in a folder in my google drive
The text was updated successfully, but these errors were encountered: