]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[mitele] Modernize and extract more metadata
authorSergey M․ <dstftw@gmail.com>
Thu, 24 Nov 2016 15:43:02 +0000 (22:43 +0700)
committerSergey M․ <dstftw@gmail.com>
Thu, 24 Nov 2016 15:43:02 +0000 (22:43 +0700)
youtube_dl/extractor/mitele.py

index 48d94992c8104b6aa2d52740c5889c03f24057a3..f577836be6dd01c7dc4b315c0295a973fe308a2d 100644 (file)
@@ -86,7 +86,10 @@ class MiTeleIE(InfoExtractor):
             'description': 'md5:3b6fce7eaa41b2d97358726378d9369f',
             'series': 'Diario de',
             'season': 'La redacción',
+            'season_number': 14,
+            'season_id': 'diario_de_t14_11981',
             'episode': 'Programa 144',
+            'episode_number': 3,
             'thumbnail': 're:(?i)^https?://.*\.jpg$',
             'duration': 2913,
         },
@@ -101,7 +104,10 @@ class MiTeleIE(InfoExtractor):
             'description': 'md5:5ff132013f0cd968ffbf1f5f3538a65f',
             'series': 'Cuarto Milenio',
             'season': 'Temporada 6',
+            'season_number': 6,
+            'season_id': 'cuarto_milenio_t06_12715',
             'episode': 'Programa 226',
+            'episode_number': 24,
             'thumbnail': 're:(?i)^https?://.*\.jpg$',
             'duration': 7313,
         },
@@ -118,35 +124,68 @@ class MiTeleIE(InfoExtractor):
         video_id = self._match_id(url)
         webpage = self._download_webpage(url, video_id)
 
-        gigya_url = self._search_regex(r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s*src="([^"]*)">[^>]*</script>', webpage, 'gigya', default=None)
-        gigya_sc = self._download_webpage(compat_urlparse.urljoin(r'http://www.mitele.es/', gigya_url), video_id, 'Downloading gigya script')
+        gigya_url = self._search_regex(
+            r'<gigya-api>[^>]*</gigya-api>[^>]*<script\s+src="([^"]*)">[^>]*</script>',
+            webpage, 'gigya', default=None)
+        gigya_sc = self._download_webpage(
+            compat_urlparse.urljoin('http://www.mitele.es/', gigya_url),
+            video_id, 'Downloading gigya script')
+
         # Get a appKey/uuid for getting the session key
-        appKey_var = self._search_regex(r'value\("appGridApplicationKey",([0-9a-f]+)\)', gigya_sc, 'appKey variable')
-        appKey = self._search_regex(r'var %s="([0-9a-f]+)"' % appKey_var, gigya_sc, 'appKey')
-        uid = compat_str(uuid.uuid4())
-        session_url = 'https://appgrid-api.cloud.accedo.tv/session?appKey=%s&uuid=%s' % (appKey, uid)
-        session_json = self._download_json(session_url, video_id, 'Downloading session keys')
-        sessionKey = compat_str(session_json['sessionKey'])
-
-        paths_url = 'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration?sessionKey=' + sessionKey
-        paths = self._download_json(paths_url, video_id, 'Downloading paths JSON')
+        appKey_var = self._search_regex(
+            r'value\s*\(\s*["\']appGridApplicationKey["\']\s*,\s*([0-9a-f]+)',
+            gigya_sc, 'appKey variable')
+        appKey = self._search_regex(
+            r'var\s+%s\s*=\s*["\']([0-9a-f]+)' % appKey_var, gigya_sc, 'appKey')
+
+        session_json = self._download_json(
+            'https://appgrid-api.cloud.accedo.tv/session',
+            video_id, 'Downloading session keys', query={
+                'appKey': appKey,
+                'uuid': compat_str(uuid.uuid4()),
+            })
+
+        paths = self._download_json(
+            'https://appgrid-api.cloud.accedo.tv/metadata/general_configuration,%20web_configuration',
+            video_id, 'Downloading paths JSON',
+            query={'sessionKey': compat_str(session_json['sessionKey'])})
+
         ooyala_s = paths['general_configuration']['api_configuration']['ooyala_search']
-        data_p = (
-            'http://' + ooyala_s['base_url'] + ooyala_s['full_path'] + ooyala_s['provider_id'] +
-            '/docs/' + video_id + '?include_titles=Series,Season&product_name=test&format=full')
-        data = self._download_json(data_p, video_id, 'Downloading data JSON')
-        source = data['hits']['hits'][0]['_source']
-        embedCode = source['offers'][0]['embed_codes'][0]
+        source = self._download_json(
+            'http://%s%s%s/docs/%s' % (
+                ooyala_s['base_url'], ooyala_s['full_path'],
+                ooyala_s['provider_id'], video_id),
+            video_id, 'Downloading data JSON', query={
+                'include_titles': 'Series,Season',
+                'product_name': 'test',
+                'format': 'full',
+            })['hits']['hits'][0]['_source']
 
+        embedCode = source['offers'][0]['embed_codes'][0]
         titles = source['localizable_titles'][0]
+
         title = titles.get('title_medium') or titles['title_long']
-        episode = titles['title_sort_name']
-        description = titles['summary_long']
-        titles_series = source['localizable_titles_series'][0]
-        series = titles_series['title_long']
-        titles_season = source['localizable_titles_season'][0]
-        season = titles_season['title_medium']
-        duration = parse_duration(source['videos'][0]['duration'])
+
+        description = titles.get('summary_long') or titles.get('summary_medium')
+
+        def get(key1, key2):
+            value1 = source.get(key1)
+            if not value1 or not isinstance(value1, list):
+                return
+            if not isinstance(value1[0], dict):
+                return
+            return value1[0].get(key2)
+
+        series = get('localizable_titles_series', 'title_medium')
+
+        season = get('localizable_titles_season', 'title_medium')
+        season_number = int_or_none(source.get('season_number'))
+        season_id = source.get('season_id')
+
+        episode = titles.get('title_sort_name')
+        episode_number = int_or_none(source.get('episode_number'))
+
+        duration = parse_duration(get('videos', 'duration'))
 
         return {
             '_type': 'url_transparent',
@@ -157,7 +196,10 @@ class MiTeleIE(InfoExtractor):
             'description': description,
             'series': series,
             'season': season,
+            'season_number': season_number,
+            'season_id': season_id,
             'episode': episode,
+            'episode_number': episode_number,
             'duration': duration,
-            'thumbnail': source['images'][0]['url'],
+            'thumbnail': get('images', 'url'),
         }