]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
[tvp] Add extractor
authorTithen-Firion <Tithen-Firion@users.noreply.github.com>
Thu, 4 Dec 2014 04:14:09 +0000 (05:14 +0100)
committerTithen-Firion <Tithen-Firion@users.noreply.github.com>
Thu, 4 Dec 2014 04:14:09 +0000 (05:14 +0100)
youtube_dl/extractor/__init__.py
youtube_dl/extractor/tvp.py

index 8b513ffd1d903bd7a3fc1c4d8b63c461ca0a81cc..b09ee303d43344de728b7c6b7c3a5772f5a18b1b 100644 (file)
@@ -415,7 +415,7 @@ from .tunein import TuneInIE
 from .turbo import TurboIE
 from .tutv import TutvIE
 from .tvigle import TvigleIE
-from .tvp import TvpIE
+from .tvp import TvpIE, TvpSeriesIE
 from .tvplay import TVPlayIE
 from .twentyfourvideo import TwentyFourVideoIE
 from .twitch import TwitchIE
index 6b95e2ed11fe3e8ef24b463ea3177f4940968461..2248a9fdff9bee514ac4cb9d5272567e388d8ea1 100644 (file)
@@ -110,3 +110,59 @@ class TvpIE(InfoExtractor):
                 'formats': formats,
             })
         return info_dict
+
+
+class TvpSeriesIE(InfoExtractor):
+    IE_NAME = 'tvp.pl:Series'
+    _VALID_URL = r'https?://vod\.tvp\.pl/(?:[^/]+/){2}(?P<id>[^/]+)/?$'
+
+    _TESTS = [
+        {
+            'url': 'http://vod.tvp.pl/filmy-fabularne/filmy-za-darmo/ogniem-i-mieczem',
+            'info_dict': {
+                'title': 'Ogniem i mieczem',
+                'id': '4278026',
+            },
+            'playlist_count': 4,
+        }, {
+            'url': 'http://vod.tvp.pl/audycje/podroze/boso-przez-swiat',
+            'info_dict': {
+                'title': 'Boso przez Ĺ›wiat',
+                'id': '9329207',
+            },
+            'playlist_count': 86,
+        }
+    ]
+
+    def _force_download_webpage(self, url, v_id, tries=0):
+        if tries >= 5:
+            raise ExtractorError(
+                '%s: Cannot download webpage, try again later' % v_id)
+        # Sometimes happen, but in my tests second try always succeeded
+        try:
+            return self._download_webpage(url, v_id)
+        except IncompleteRead as e:
+            return self._force_download_webpage(url, v_id, tries+1)
+    
+    def _real_extract(self, url):
+        display_id = self._match_id(url)
+        webpage = self._force_download_webpage(url, display_id)
+        title = self._html_search_regex(
+            r'(?s) id=[\'"]path[\'"]>(.*?)</span>', webpage, 'series')
+        title = title.split(' / ', 2)[-1]
+        playlist_id = self._search_regex(r'nodeId:\s*(\d+)', webpage, 'playlist id')
+        playlist = self._force_download_webpage(
+            'http://vod.tvp.pl/vod/seriesAjax?type=series&nodeId=%s&recommend'
+            'edId=0&sort=&page=0&pageSize=1000000' % playlist_id, display_id)
+        videos_paths = re.findall(
+            '(?s)class="shortTitle">.*?href="(/[^"]+)', playlist)
+        entries = [
+            self.url_result('http://vod.tvp.pl%s' % v_path, ie=TvpIE.ie_key())
+            for v_path in videos_paths]
+        return {
+            '_type': 'playlist',
+            'id': playlist_id,
+            'display_id': display_id,
+            'title': title,
+            'entries': entries,
+        }