检索存储在Google相册中的视频的文件大小 [英] Retrieve file size for videos stored on Google Photos

查看:156
本文介绍了检索存储在Google相册中的视频的文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我想看看我如何使用Google Photos空间,我用Python编写了一个小脚本,该脚本使用Google Photos API检索了我所有的相册及其内容(使用 https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search ).文件信息不存在,而是使用mediaItem baseUrl(记录在

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.

问题:是否可以通过某种方式检索存储在Google相册中的视频的文件大小,而不必下载整个视频?该应用程序确实知道文件的大小,但是API中似乎不提供该文件的大小.有什么方法可以发送一些请求标头来获取文件大小?

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?

其他信息::我正在使用Python和httplib2.Http()来处理我的HEAD请求(很高兴使用请求模块或任何其他替代方法).

Extra info: I'm using Python and the httplib2.Http() for my HEAD requests (happy to use the requests module or any other alternative).

这是从API中检索到的信息,该视频文件略超过100MB(绝对不是30k):

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"
}

这些是从HEAD请求发送到baseUrl的标头:

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"
}

谢谢.

推荐答案

这是来自OP的错误语言,但我认为它已翻译为

This is in the wrong language from the OP, but I assume translating to a Python cURL call is a straightforward task.

我通过使用文件的 baseUrl /list"rel =" nofollow noreferrer> API :

function retrieve_remote_file_size($url){
     $ch = curl_init($url);

     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_HEADER, TRUE);
     curl_setopt($ch, CURLOPT_NOBODY, TRUE);

     $data = curl_exec($ch);
     $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);

     curl_close($ch);
     return $size;
}

( 来源 )

请注意(与上述

Note that (contrary to the "Warning" at the above baseUrl link) I did not need to specify a width/height or download parameter in order for the baseUrl to work with this function.

这篇关于检索存储在Google相册中的视频的文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆