[youtube] Add an extractor for downloading the watch history (closes #1821)
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sun, 24 Nov 2013 13:33:50 +0000 (14:33 +0100)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Sun, 24 Nov 2013 13:33:50 +0000 (14:33 +0100)
test/test_all_urls.py
youtube_dl/extractor/__init__.py
youtube_dl/extractor/youtube.py

index 56e5f80e1f6ddb17fef3ee5c499c238996c12051..42813da1a4059f2049772e1f2767558f9bc2498d 100644 (file)
@@ -100,6 +100,7 @@ class TestAllURLsMatching(unittest.TestCase):
     def test_keywords(self):
         self.assertMatch(':ytsubs', ['youtube:subscriptions'])
         self.assertMatch(':ytsubscriptions', ['youtube:subscriptions'])
+        self.assertMatch(':ythistory', ['youtube:history'])
         self.assertMatch(':thedailyshow', ['ComedyCentral'])
         self.assertMatch(':tds', ['ComedyCentral'])
         self.assertMatch(':colbertreport', ['ComedyCentral'])
index 4c280fa5e674b092c222876dda4c57b3d5db34a0..1fbd10bc5c410efb82ca9568872042fe951a68fd 100644 (file)
@@ -186,6 +186,7 @@ from .youtube import (
     YoutubeTruncatedURLIE,
     YoutubeWatchLaterIE,
     YoutubeFavouritesIE,
+    YoutubeHistoryIE,
 )
 from .zdf import ZDFIE
 
index 07a457f4d7d56355fe677e07a7d27171ea73f2ec..64d4c2445892baad5decb53620f605368ff335d5 100644 (file)
@@ -1826,6 +1826,20 @@ class YoutubeWatchLaterIE(YoutubeFeedsInfoExtractor):
     _PAGING_STEP = 100
     _PERSONAL_FEED = True
 
+class YoutubeHistoryIE(YoutubeFeedsInfoExtractor):
+    IE_DESC = u'Youtube watch history, "ythistory" keyword (requires authentication)'
+    _VALID_URL = u'https?://www\.youtube\.com/feed/history|:ythistory'
+    _FEED_NAME = 'history'
+    _PERSONAL_FEED = True
+    _PLAYLIST_TITLE = u'Youtube Watch History'
+
+    def _real_extract(self, url):
+        webpage = self._download_webpage('https://www.youtube.com/feed/history', u'History')
+        data_paging = self._search_regex(r'data-paging="(\d+)"', webpage, u'data-paging')
+        # The step is actually a ridiculously big number (like 1374343569725646)
+        self._PAGING_STEP = int(data_paging)
+        return super(YoutubeHistoryIE, self)._real_extract(url)
+
 class YoutubeFavouritesIE(YoutubeBaseInfoExtractor):
     IE_NAME = u'youtube:favorites'
     IE_DESC = u'YouTube.com favourite videos, "ytfav" keyword (requires authentication)'