如何获取用户的整个YouTube观看记录? [英] How to get a user's entire YouTube watch history?

查看:1486
本文介绍了如何获取用户的整个YouTube观看记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的YouTube API应用程序中获取给定用户的观看视频的完整列表。我想加上所有视频的总持续时间。

I'm trying to get a full list of watched videos for a given user in my YouTube API application. I want to add up total duration of all videos.

当我从历史播放列表中获取视频列表时,API将其限制为50个项目。有分页但项目总数为50(不仅仅是每页);我无法使用它出现的API访问更多数据。

When I get the list of videos from history playlist, the API caps it at 50 items. There's pagination but total amount of items is 50 (not just per page); I can't access more data with the API it appears.

有没有办法在没有数据上限的情况下获得此播放列表?我希望有另一种方法(使用API​​)或没有API的方法。我知道YouTube会存储这些数据,因为我可以查看我的整个历史记录(远远超过50个视频)。

Is there any way I can get this playlist without the data cap? I'm hoping for another method (of using the API) or a way to do it without the API. I know YouTube stores this data because I can view my entire history (far more that 50 videos).

我正在使用此代码:

var requestOptions = {
    playlistId: playlistId,
    part: 'snippet',
    maxResults: 50
};
gapi.client.youtube.playlistItems.list(requestOptions);

其中 playlistId 是历史记录的ID播放列表我来自 gapi.client.youtube.channels.list 请求。

where playlistId is the id of the history playlist I got from a gapi.client.youtube.channels.list request.

编辑(2017年) ):我想澄清一下,我总是打算下载自己的历史记录,只是出于兴趣,看看我花了多少时间观看视频。我仍然无法做到这一点。

Edit (2017): I want to clarify that it was always my intention to download my own history, just out of interest to see how much time I have spent watching videos. I still have not been able to do this.

推荐答案

我写了一个刮刀(用Python 2.7(更新为3.5)和Scrapy )这个任务不久前。
无官方API,它使用登录的会话cookie和html解析。默认情况下转储到SQLite。
https://github.com/zvodd/Youtube-Watch-History-Scraper

I wrote a scraper(in Python 2.7(updated for 3.5) and Scrapy) for this task a while ago. Sans official API, it uses a logged in session cookie and html parsing. Dumps to SQLite by default. https://github.com/zvodd/Youtube-Watch-History-Scraper

如何完成:基本上它会打开网址

How it's done: essentially it opens the url

https://www.youtube.com/feed/history'

有效(已记录) in)取自Chrome的会话cookie。为名称,视频(网址),频道/用户,描述,长度绘制所有视频条目。然后,它会在页面底部找到带有 data-uix-load-more-href 属性的按钮,其中包含指向下一页的链接,如:

with a valid(logged in) session cookie taken from Chrome. Scrapes all video entries for name, vid(url), channel/user, description, length. Then it finds the button at the bottom of the page with the attribute data-uix-load-more-href which contains the link to the next page, something like:

"/browse_ajax?action_continuation=1&continuation=98h32hfoasau0fu928hf2hf908h98hr%253D%253D&target_id=item-section-552363&direct_render=1"

...从那里重新擦除视频条目并将它们全部转储到sqlite数据库中;您可以通过任何字段(姓名,长度,用户,描述等)搜索条目。

... re-scrapes the video entries from there and dumps them all into an sqlite database; which you can search entries by any of the fields (name, length, user, description, etc).

因此,在他们更改其Feed /历史记录页面之前,它是可行的,完成。
我甚至可以更新它。

So until they change their feed/history page, it's doable and done. I might even update it.

这篇关于如何获取用户的整个YouTube观看记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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