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