Context: I wanted to see how I'm using my Google Photos space and I wrote a little script in Python that uses the Google Photos API to retrieve all my albums and it's contents (using https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search). The file information is not there but using the mediaItem
baseUrl
(documented https://developers.google.com/photos/library/reference/rest/v1/mediaItems#MediaItem) I can then perform a HEAD
request and get the content-length
from the headers. This seems to work fine for the photos but the size for videos is grossly underestimated. My guess is that Google Photos is getting ready to stream the videos and it's not sending the whole video information.
Question: Is there any way to retrieve file size for videos stored on Google Photos, hopefully, without having to download the whole video? The app does know about the file size, but that doesn't seem to be available in the API. Is there any way to send some request headers to get the file size?
Extra info: I'm using Python and the httplib2.Http()
for my HEAD
requests (happy to use the requests module or any other alternative).
This is the information retrieved from the API, this video file is a little over 100MB (definitely not 30k):
{
"id": "XYZ",
"productUrl": "https://photos.google.com/lr/photo/XYZ",
"baseUrl": "https://lh3.googleusercontent.com/lr/ABC",
"mimeType": "video/mp4",
"mediaMetadata": {
"creationTime": "2018-11-27T03:43:27Z",
"width": "1920",
"height": "1080",
"video": {
"fps": 120,
"status": "READY"
}
},
"filename": "VID_20181126_174327.mp4"
}
These are the headers received from the HEAD
request to baseUrl
:
{
"access-control-expose-headers": "Content-Length",
"etag": "\"v15ceb\"",
"expires": "Fri, 01 Jan 1990 00:00:00 GMT",
"cache-control": "private, max-age=86400, no-transform",
"content-disposition": "inline;filename=\"VID_20181126_174327.jpg\"",
"content-type": "image/jpeg",
"vary": "Origin",
"x-content-type-options": "nosniff",
"date": "Wed, 08 May 2019 17:39:42 GMT",
"server": "fife",
"content-length": "31652",
"x-xss-protection": "0",
"alt-svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\"",
"status": "200",
"content-location": "https://lh3.googleusercontent.com/lr/ABC"
}
Thanks.
So, if you backed up a file before the privilege was withdrawn, it won't eat into your account storage, but if it does, you'll see the file size under the 'Backed up' section on Photos. Interestingly, you can also see a condensed version of the 'Backed up' section on the Photos app for iPhone and iPad.
As of June 1, 2021, any new photos or videos you back up in High quality (now named Storage saver) or Express quality will count toward your 15 GB of Google Account storage or any additional storage you may have purchased as a Google One member.
If you have a @gmail Google account, go to one.google.com and click the “review” link under Large Files. You'll get a sorted list view of all files in your Google Drive, sort by size. Select the ones you no longer need and hit the delete button to instantly recover space.
The Photos API docs mention that for videos, the baseUrl
that the API returns refers to a thumbnail for the video rather than the video itself, and you've got to append =dv
to the baseUrl
to actually receive the video. It also looks from my experimentation that the content-length
that comes back from that endpoint is accurate:
import requests
baseUrl = "https://lh3.googleusercontent.com/lr/AF..."
# just the thumbnail's size
requests.head(baseUrl,allow_redirects=True).headers['content-length']
# the entire video's size
requests.head(baseUrl + "=dv",allow_redirects=True).headers['content-length']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With