[fox] Add metadata extraction
[youtube-dl] / youtube_dl / extractor / fox.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .adobepass import AdobePassIE
5 from ..utils import (
6     int_or_none,
7     smuggle_url,
8     update_url_query,
9 )
10
11
12 class FOXIE(AdobePassIE):
13     _VALID_URL = r'https?://(?:www\.)?fox\.com/watch/(?P<id>[0-9]+)'
14     _TEST = {
15         'url': 'http://www.fox.com/watch/255180355939/7684182528',
16         'md5': 'ebd296fcc41dd4b19f8115d8461a3165',
17         'info_dict': {
18             'id': '255180355939',
19             'ext': 'mp4',
20             'title': 'Official Trailer: Gotham',
21             'description': 'Tracing the rise of the great DC Comics Super-Villains and vigilantes, Gotham reveals an entirely new chapter that has never been told.',
22             'duration': 129,
23             'timestamp': 1400020798,
24             'upload_date': '20140513',
25             'uploader': 'NEWA-FNG-FOXCOM',
26         },
27         'add_ie': ['ThePlatform'],
28     }
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32         webpage = self._download_webpage(url, video_id)
33
34         settings = self._parse_json(self._search_regex(
35             r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
36             webpage, 'drupal settings'), video_id)
37         fox_pdk_player = settings['fox_pdk_player']
38         release_url = fox_pdk_player['release_url']
39         query = {
40             'mbr': 'true',
41             'switch': 'http'
42         }
43         if fox_pdk_player.get('access') == 'locked':
44             ap_p = settings['foxAdobePassProvider']
45             rating = ap_p.get('videoRating')
46             if rating == 'n/a':
47                 rating = None
48             resource = self._get_mvpd_resource('fbc-fox', None, ap_p['videoGUID'], rating)
49             query['auth'] = self._extract_mvpd_auth(url, video_id, 'fbc-fox', resource)
50
51         info = self._search_json_ld(webpage, video_id, fatal=False)
52         info.update({
53             '_type': 'url_transparent',
54             'ie_key': 'ThePlatform',
55             'url': smuggle_url(update_url_query(release_url, query), {'force_smil_url': True}),
56             'id': video_id,
57         })
58
59         return info