Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve file size for videos stored on Google Photos

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.

like image 810
Josep Valls Avatar asked May 08 '19 17:05

Josep Valls


People also ask

How do I see file size in Google Photos?

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.

Do videos use space on Google Photos?

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.

How can I sort my files in Google Photos by size?

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.


1 Answers

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']
like image 185
kaytwo Avatar answered Nov 14 '22 23:11

kaytwo