]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[NRKTV] Added NRKTVSeriesIE
authorOdd Stråbø <oddstr13@openshell.no>
Sat, 14 Jan 2017 01:36:04 +0000 (02:36 +0100)
committerSergey M․ <dstftw@gmail.com>
Tue, 31 Jan 2017 16:10:40 +0000 (23:10 +0700)
[NRKTV] Added season and episode number to metadata.

[NRKTV] Added category to metadata.

[NRKTV] Added tests to NRKTVSeries.

[NRKTV] Fixed whitespace issues (flake8).

youtube_dl/extractor/extractors.py
youtube_dl/extractor/nrk.py

index 2590b5e1b2ac3c1c5594844e8cb9d86d2bbfc530..06e6d46201fb28114f297bf70fe00d8260006ec5 100644 (file)
@@ -668,6 +668,7 @@ from .nrk import (
     NRKTVIE,
     NRKTVDirekteIE,
     NRKTVEpisodesIE,
+    NRKTVSeriesIE,
 )
 from .ntvde import NTVDeIE
 from .ntvru import NTVRuIE
index ea7be005a9640b631c03381778792251fca574a5..26604f84face8eafabc550ca6fc4fd840e2b8517 100644 (file)
@@ -128,6 +128,18 @@ class NRKBaseIE(InfoExtractor):
         series = conviva.get('seriesName') or data.get('seriesTitle')
         episode = conviva.get('episodeName') or data.get('episodeNumberOrDate')
 
+        season_number = None
+        episode_number = None
+        if data.get('mediaElementType') == 'Episode':
+            _season_episode = data.get('scoresStatistics', {}).get('springStreamStream') or \
+                data.get('relativeOriginUrl', '')
+            EPISODENUM_RE = [
+                r'/s(?P<season>\d+)e(?P<episode>\d+)\.',
+                r'/sesong-(?P<season>\d+)/episode-(?P<episode>\d+)',
+            ]
+            season_number = int_or_none(self._search_regex(EPISODENUM_RE, _season_episode, "S##E##", fatal=False, group='season'))
+            episode_number = int_or_none(self._search_regex(EPISODENUM_RE, _season_episode, "S##E##", fatal=False, group='episode'))
+
         thumbnails = None
         images = data.get('images')
         if images and isinstance(images, dict):
@@ -140,11 +152,15 @@ class NRKBaseIE(InfoExtractor):
                 } for image in web_images if image.get('imageUrl')]
 
         description = data.get('description')
+        category = data.get('mediaAnalytics', {}).get('category')
 
         common_info = {
             'description': description,
             'series': series,
             'episode': episode,
+            'season_number': season_number,
+            'episode_number': episode_number,
+            'categories': [category] if category else None,
             'age_limit': parse_age_limit(data.get('legalAge')),
             'thumbnails': thumbnails,
         }
@@ -360,6 +376,39 @@ class NRKTVEpisodesIE(NRKPlaylistBaseIE):
             r'<h1>([^<]+)</h1>', webpage, 'title', fatal=False)
 
 
+class NRKTVSeriesIE(InfoExtractor):
+    _VALID_URL = r'https?://tv\.nrk\.no/serie/(?P<id>[^/]+)/?'
+    _ITEM_RE = r'data-season=["\'](?P<id>\d+)["\']'
+    _TESTS = [{
+        'url': 'https://tv.nrk.no/serie/broedrene-dal-og-spektralsteinene',
+        'playlist_count': 1,
+    }, {
+        'url': 'https://tv.nrk.no/serie/saving-the-human-race',
+        'playlist_count': 1,
+    }, {
+        'url': 'https://tv.nrk.no/serie/postmann-pat',
+        'playlist_count': 3,
+    }, {
+        'url': 'https://tv.nrk.no/serie/groenn-glede',
+        'playlist_count': 9,
+    }]
+
+    def _real_extract(self, url):
+        series_id = self._match_id(url)
+
+        webpage = self._download_webpage(url, series_id)
+
+        entries = [
+            self.url_result('https://tv.nrk.no/program/Episodes/{series}/{season}'.format(
+                series=series_id,
+                season=season_id
+            ))
+            for season_id in re.findall(self._ITEM_RE, webpage)
+        ]
+
+        return self.playlist_result(entries)
+
+
 class NRKSkoleIE(InfoExtractor):
     IE_DESC = 'NRK Skole'
     _VALID_URL = r'https?://(?:www\.)?nrk\.no/skole/?\?.*\bmediaId=(?P<id>\d+)'