How to download photos (or videos) from your Google Photos account in Python | Google Photos API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey husking guys welcome to another Python 212 video my name is Jay in this tutorial we're going to create a Python program to download photos from Google photos to your PC so this feature is now available on google photos api documentation but i was able to find a workaround to explore my photos using the Google Photos API as well as some other libraries before we begin make sure that you enable the Google photos our library from your Google cloud platform if you don't know how you want to go to navigation menu api's and services library and you're from there you want to search for google photos and click on photos library api and just make sure that the photo library api is enabled and the second requirement is make sure that you installed the Google client library so you can use these pip comments to install the libraries now I'll post these comments on my website and just copy and paste to install the library and the other thing I want to talk about is how to make the photos exporting process work so if you go to developers.google.com and under the guys tab you want to click on assets media items if you scroll down to see so you scroll down to that's multiple media item ok if you scroll down to base URL you can use Google Photos API to export media metadata your part see these properties so base URL cover photo base URL profile picture base gel these are the URL address is to access the photo files if you look to the documentation on the pram 2d so which is this all right here founder you out so if you can can the ego sign fall by ladder D that converts a girl out to a photo download URL in that couple other parameters so you can also set the woods in Heights as well as the the crap I'll cram to I won't be going these two parameters I'll be purely just focusing out this download parameter so letter D no see so what else and decide a photos library API now let's go to Google Photos accounts and a couple photos so let's do these so let's say I want to back out my travel album and in general you can use these more options then click on download and Google photos will create a zip file and you can down the zip file to your PC but you have to go to the same process to back out let's say you have 20 albums you want to backup and if you have to do that 20 times then can be a little bit time-consuming and cumbersome so that's why I'm using Python we can automate the entire process to save your time and label work so you have a MT Python script and I named the script Google follows back out that high so first we need to import the libraries oh and by the way so make sure that you download googled a PI file from the link in the description below the google topic file is a script I wrote to streamline the service creation process so imported oil module even for my Google module I want to inform I'd create service function next also use the pandas library and request this library so you will need to install these two libraries so I think install request this library by using the commence pep in style requesters and for the pandas library so you can use the comments pub install pandas and that's all the libraries we need next I will need a client so I need my client secret file do I have done ok so I don't have my client secret file so let me go to my environments so I have a environment I used to do my developments based on different Google api's so here's my client super file let me just copy and paste to my folder I'm going to create a couple of constant variables so first one will be client secret file and I'll take my file path so she I can just take the file name directly oops oh and I forgot so I need to have to pay my photo environments so will be my Google API environment next is the API name so the API name is photos library version number it's gonna be p1 for the Scopes we need to use photos library and also we need photos library - in scope me Dalida and these are the four constant variables we need to create here I'm going to create my Google Photos service instance so it's kind of like the photos to assess Google Photos API methods and using my create service function so the first parameter is the client secret file API named API version and the Scopes and because I don't want to export all my photos I just want to explore photos file my travel album so which is this album right here let me go back so travel some come to Prem my album does so from the service pop shop the album's that list that seq am going to pass the output to an object called my albums in phone my albums object I want to reference the album's reference I'll pass the output to my albums from the schoolís inhale convert list to a dataframe object now let's just print uh albums the Afrin real quick so dear albums i want to print the output Smackdown so MUC sure to mark down now let me run the script in here I need to often decay my accounts so it's gonna be under my learned data analysis accounts and just ignore this page and click on go to file by your app name so my app means Google API tutorial and I'm just going to click on that and here want to grant the permissions so yes and allow and you have a let me see service is not defined oh so he have a typo and we try again [Music] and I forgot to provide my loose option so my elbow loose let me try again and here I guess yeah yeah so I forgot to we need my pandas library so is PD yeah sure beards okay so here's my mock downs table so it doesn't look very nice okay so open does just rigor data frame cyber pandas code snippet and me just put these on the top I'll change this and change the display widths to 150 let me try again so here's my ID column title party I'll cover photos based really and we just need the photo albums ID so which is first column I want to grab the Elmo's ID of my travel album so I'll grab this ID right here and if you want you can zoom into this so travel album ID so I'll create my albums there friend TF albums and based on the title column you see goes to travel now I want to return the outputs from my albums they are thing I want to return the value from my ID column and complete that to stream I don't want to include the index so I'll set index to false in case if my stream has spaces someone should I want to use the strip my fits to remove the extra space on both end now we have the album's ID now can basically retrieve all the media files from my travel album so before we do that let me create a function to download to perform the the file download process so name this function download file I'm going to have a via our parameter tsukkomi string destination folder and so ii b string file name is all sukham it's also going to be stream so here i'm going to make a request call using the request library some the output response and request that gets it will pass the AL in home consider if response the status code is equals to 200 200 means the API call is successful I own two premises loading file so far by the filename and this will be file name so from the file name arguments and to download file so we want to say we open and fall by want to concatenate the destination folder with the file name and we're going to write as binary + F and here we're going to write a file so response dot contents and once we finish want to close the file and that's her so that's the test function and to retrieve all the media files from the travel album so we want to use the service option the media items that search someone to use the search methods and from the body parameter so we need to provide the album ID album ID and it's gonna be trouble album ID that seq and because this output returns us addition so we need to reference the media idleness key and all stood output for media files Upshaw now I still need to provide my destination folder so I want to backup my photos to my photos backup folder so I'll grab this our file path of na file path for the path and he'll Crescent destination folder available so provide the photo path now we need to hear rate each media file from the media files option so you can say for media file in media files I want to grab the file name so media file you want to reference the name and the base URL so download a media file base URL remember we need to contaminate the the parameter so ego sign fall by letter D now we'll code the download file function I want to provide the URL should should be download you're out the photo path so destination folder and the file name and that's it no no supplies and see what happens so here on the Left size my Python script and on the right hand size my it's my photo backup folder now if I just run script okay so she have a so yeah oh so this should be file name nah let me try again okay now it's downloading my media files all right now that's older photos so if I counted yeah Tim photos and if I go back to my album and I should see ten albums let me go back yep ten items now let me just open one of the image so I mean go to view make the icon extra large now if I open my windows here image and here's my photo export using my Python program and you can also implement different rules or criteria sometimes I'll use my windows scheduler so issues scheduler oh task scheduler I haven't used this for a while if you need to back out photos from your google photos to your PC then can schedule different jobs to automatically backup your photos from your google photos count we all need to do any menial work so that's it I'm going to cover in this video and I'll link the link in the description below as always send you guys watching I'll see you guys on the next video
Info
Channel: Jie Jenn
Views: 6,107
Rating: undefined out of 5
Keywords: download photos google photos, download media google photos, download vidoe google photos, google photos api and Python, export photos google photos python, export media google photos and Python
Id: HYN55zgd1T4
Channel Id: undefined
Length: 16min 17sec (977 seconds)
Published: Tue Apr 07 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.