]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/usanetwork.py
debian/control: Mark my GitHub trees as the preferred repos.
[youtubedl] / youtube_dl / extractor / usanetwork.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .adobepass import AdobePassIE
5 from ..utils import (
6 NO_DEFAULT,
7 smuggle_url,
8 update_url_query,
9 )
10
11
12 class USANetworkIE(AdobePassIE):
13 _VALID_URL = r'https?://(?:www\.)?usanetwork\.com/(?:[^/]+/videos|movies)/(?P<id>[^/?#]+)'
14 _TEST = {
15 'url': 'http://www.usanetwork.com/mrrobot/videos/hpe-cybersecurity',
16 'md5': '33c0d2ba381571b414024440d08d57fd',
17 'info_dict': {
18 'id': '3086229',
19 'ext': 'mp4',
20 'title': 'HPE Cybersecurity',
21 'description': 'The more we digitize our world, the more vulnerable we are.',
22 'upload_date': '20160818',
23 'timestamp': 1471535460,
24 'uploader': 'NBCU-USA',
25 },
26 }
27
28 def _real_extract(self, url):
29 display_id = self._match_id(url)
30 webpage = self._download_webpage(url, display_id)
31
32 def _x(name, default=NO_DEFAULT):
33 return self._search_regex(
34 r'data-%s\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1' % name,
35 webpage, name, default=default, group='value')
36
37 video_id = _x('mpx-guid')
38 title = _x('episode-title')
39 mpx_account_id = _x('mpx-account-id', '2304992029')
40
41 query = {
42 'mbr': 'true',
43 }
44 if _x('is-full-episode', None) == '1':
45 query['manifest'] = 'm3u'
46
47 if _x('is-entitlement', None) == '1':
48 adobe_pass = {}
49 drupal_settings = self._search_regex(
50 r'jQuery\.extend\(Drupal\.settings\s*,\s*({.+?})\);',
51 webpage, 'drupal settings', fatal=False)
52 if drupal_settings:
53 drupal_settings = self._parse_json(drupal_settings, video_id, fatal=False)
54 if drupal_settings:
55 adobe_pass = drupal_settings.get('adobePass', {})
56 resource = self._get_mvpd_resource(
57 adobe_pass.get('adobePassResourceId', 'usa'),
58 title, video_id, _x('episode-rating', 'TV-14'))
59 query['auth'] = self._extract_mvpd_auth(
60 url, video_id, adobe_pass.get('adobePassRequestorId', 'usa'), resource)
61
62 info = self._search_json_ld(webpage, video_id, default={})
63 info.update({
64 '_type': 'url_transparent',
65 'url': smuggle_url(update_url_query(
66 'http://link.theplatform.com/s/HNK2IC/media/guid/%s/%s' % (mpx_account_id, video_id),
67 query), {'force_smil_url': True}),
68 'id': video_id,
69 'title': title,
70 'series': _x('show-title', None),
71 'episode': title,
72 'ie_key': 'ThePlatform',
73 })
74 return info