]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/amcnetworks.py
debian/control: Mark compliance with Debian policy 4.2.1.
[youtubedl] / youtube_dl / extractor / amcnetworks.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .theplatform import ThePlatformIE
5 from ..utils import (
6 int_or_none,
7 parse_age_limit,
8 try_get,
9 update_url_query,
10 )
11
12
13 class AMCNetworksIE(ThePlatformIE):
14 _VALID_URL = r'https?://(?:www\.)?(?:amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?:movies|shows(?:/[^/]+)+)/(?P<id>[^/?#]+)'
15 _TESTS = [{
16 'url': 'http://www.ifc.com/shows/maron/season-04/episode-01/step-1',
17 'md5': '',
18 'info_dict': {
19 'id': 's3MX01Nl4vPH',
20 'ext': 'mp4',
21 'title': 'Maron - Season 4 - Step 1',
22 'description': 'In denial about his current situation, Marc is reluctantly convinced by his friends to enter rehab. Starring Marc Maron and Constance Zimmer.',
23 'age_limit': 17,
24 'upload_date': '20160505',
25 'timestamp': 1462468831,
26 'uploader': 'AMCN',
27 },
28 'params': {
29 # m3u8 download
30 'skip_download': True,
31 },
32 'skip': 'Requires TV provider accounts',
33 }, {
34 'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
35 'only_matching': True,
36 }, {
37 'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
38 'only_matching': True,
39 }, {
40 'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
41 'only_matching': True,
42 }, {
43 'url': 'http://www.ifc.com/movies/chaos',
44 'only_matching': True,
45 }, {
46 'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version',
47 'only_matching': True,
48 }, {
49 'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention',
50 'only_matching': True,
51 }, {
52 'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3',
53 'only_matching': True,
54 }, {
55 'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1',
56 'only_matching': True,
57 }]
58
59 def _real_extract(self, url):
60 display_id = self._match_id(url)
61 webpage = self._download_webpage(url, display_id)
62 query = {
63 'mbr': 'true',
64 'manifest': 'm3u',
65 }
66 media_url = self._search_regex(
67 r'window\.platformLinkURL\s*=\s*[\'"]([^\'"]+)',
68 webpage, 'media url')
69 theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
70 r'link\.theplatform\.com/s/([^?]+)',
71 media_url, 'theplatform_path'), display_id)
72 info = self._parse_theplatform_metadata(theplatform_metadata)
73 video_id = theplatform_metadata['pid']
74 title = theplatform_metadata['title']
75 rating = try_get(
76 theplatform_metadata, lambda x: x['ratings'][0]['rating'])
77 auth_required = self._search_regex(
78 r'window\.authRequired\s*=\s*(true|false);',
79 webpage, 'auth required')
80 if auth_required == 'true':
81 requestor_id = self._search_regex(
82 r'window\.requestor_id\s*=\s*[\'"]([^\'"]+)',
83 webpage, 'requestor id')
84 resource = self._get_mvpd_resource(
85 requestor_id, title, video_id, rating)
86 query['auth'] = self._extract_mvpd_auth(
87 url, video_id, requestor_id, resource)
88 media_url = update_url_query(media_url, query)
89 formats, subtitles = self._extract_theplatform_smil(
90 media_url, video_id)
91 self._sort_formats(formats)
92 info.update({
93 'id': video_id,
94 'subtitles': subtitles,
95 'formats': formats,
96 'age_limit': parse_age_limit(parse_age_limit(rating)),
97 })
98 ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
99 if ns_keys:
100 ns = list(ns_keys)[0]
101 series = theplatform_metadata.get(ns + '$show')
102 season_number = int_or_none(
103 theplatform_metadata.get(ns + '$season'))
104 episode = theplatform_metadata.get(ns + '$episodeTitle')
105 episode_number = int_or_none(
106 theplatform_metadata.get(ns + '$episode'))
107 if season_number:
108 title = 'Season %d - %s' % (season_number, title)
109 if series:
110 title = '%s - %s' % (series, title)
111 info.update({
112 'title': title,
113 'series': series,
114 'season_number': season_number,
115 'episode': episode,
116 'episode_number': episode_number,
117 })
118 return info