]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/amcnetworks.py
dd3b18d72d05f3deaab902b75cb6064e4b9d16ac
[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|wetv)\.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
56 def _real_extract(self, url):
57 display_id = self._match_id(url)
58 webpage = self._download_webpage(url, display_id)
59 query = {
60 'mbr': 'true',
61 'manifest': 'm3u',
62 }
63 media_url = self._search_regex(
64 r'window\.platformLinkURL\s*=\s*[\'"]([^\'"]+)',
65 webpage, 'media url')
66 theplatform_metadata = self._download_theplatform_metadata(self._search_regex(
67 r'link\.theplatform\.com/s/([^?]+)',
68 media_url, 'theplatform_path'), display_id)
69 info = self._parse_theplatform_metadata(theplatform_metadata)
70 video_id = theplatform_metadata['pid']
71 title = theplatform_metadata['title']
72 rating = try_get(
73 theplatform_metadata, lambda x: x['ratings'][0]['rating'])
74 auth_required = self._search_regex(
75 r'window\.authRequired\s*=\s*(true|false);',
76 webpage, 'auth required')
77 if auth_required == 'true':
78 requestor_id = self._search_regex(
79 r'window\.requestor_id\s*=\s*[\'"]([^\'"]+)',
80 webpage, 'requestor id')
81 resource = self._get_mvpd_resource(
82 requestor_id, title, video_id, rating)
83 query['auth'] = self._extract_mvpd_auth(
84 url, video_id, requestor_id, resource)
85 media_url = update_url_query(media_url, query)
86 formats, subtitles = self._extract_theplatform_smil(
87 media_url, video_id)
88 self._sort_formats(formats)
89 info.update({
90 'id': video_id,
91 'subtitles': subtitles,
92 'formats': formats,
93 'age_limit': parse_age_limit(parse_age_limit(rating)),
94 })
95 ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
96 if ns_keys:
97 ns = list(ns_keys)[0]
98 series = theplatform_metadata.get(ns + '$show')
99 season_number = int_or_none(
100 theplatform_metadata.get(ns + '$season'))
101 episode = theplatform_metadata.get(ns + '$episodeTitle')
102 episode_number = int_or_none(
103 theplatform_metadata.get(ns + '$episode'))
104 if season_number:
105 title = 'Season %d - %s' % (season_number, title)
106 if series:
107 title = '%s - %s' % (series, title)
108 info.update({
109 'title': title,
110 'series': series,
111 'season_number': season_number,
112 'episode': episode,
113 'episode_number': episode_number,
114 })
115 return info