]>
Commit | Line | Data |
---|---|---|
48fbb100 AMW |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
29825140 | 6 | from .turner import TurnerBaseIE |
3fb2a230 | 7 | from ..utils import ( |
3fb2a230 | 8 | int_or_none, |
3b859145 | 9 | strip_or_none, |
3fb2a230 | 10 | ) |
48fbb100 | 11 | |
5f6a1245 | 12 | |
29825140 | 13 | class AdultSwimIE(TurnerBaseIE): |
3b859145 | 14 | _VALID_URL = r'https?://(?:www\.)?adultswim\.com/videos/(?P<show_path>[^/?#]+)(?:/(?P<episode_path>[^/?#]+))?' |
71155991 | 15 | |
16 | _TESTS = [{ | |
17 | 'url': 'http://adultswim.com/videos/rick-and-morty/pilot', | |
71155991 | 18 | 'info_dict': { |
11e611a7 | 19 | 'id': 'rQxZvXQ4ROaSOqq-or2Mow', |
3b859145 | 20 | 'ext': 'mp4', |
71155991 | 21 | 'title': 'Rick and Morty - Pilot', |
3b859145 RA |
22 | 'description': 'Rick moves in with his daughter\'s family and establishes himself as a bad influence on his grandson, Morty.', |
23 | 'timestamp': 1493267400, | |
24 | 'upload_date': '20170427', | |
58cd7e17 | 25 | }, |
3b859145 RA |
26 | 'params': { |
27 | # m3u8 download | |
28 | 'skip_download': True, | |
71155991 | 29 | }, |
3b859145 | 30 | 'expected_warnings': ['Unable to download f4m manifest'], |
cc08b11d NJ |
31 | }, { |
32 | 'url': 'http://www.adultswim.com/videos/tim-and-eric-awesome-show-great-job/dr-steve-brule-for-your-wine/', | |
cc08b11d NJ |
33 | 'info_dict': { |
34 | 'id': 'sY3cMUR_TbuE4YmdjzbIcQ', | |
3b859145 | 35 | 'ext': 'mp4', |
cc08b11d | 36 | 'title': 'Tim and Eric Awesome Show Great Job! - Dr. Steve Brule, For Your Wine', |
3b859145 RA |
37 | 'description': 'Dr. Brule reports live from Wine Country with a special report on wines. \nWatch Tim and Eric Awesome Show Great Job! episode #20, "Embarrassed" on Adult Swim.', |
38 | 'upload_date': '20080124', | |
39 | 'timestamp': 1201150800, | |
cc08b11d | 40 | }, |
0f15ad7b | 41 | 'params': { |
42 | # m3u8 download | |
43 | 'skip_download': True, | |
3b859145 | 44 | }, |
038a5e1a | 45 | }, { |
038a5e1a | 46 | 'url': 'http://www.adultswim.com/videos/decker/inside-decker-a-new-hero/', |
038a5e1a S |
47 | 'info_dict': { |
48 | 'id': 'I0LQFQkaSUaFp8PnAWHhoQ', | |
49 | 'ext': 'mp4', | |
50 | 'title': 'Decker - Inside Decker: A New Hero', | |
3b859145 RA |
51 | 'description': 'The guys recap the conclusion of the season. They announce a new hero, take a peek into the Victorville Film Archive and welcome back the talented James Dean.', |
52 | 'timestamp': 1469480460, | |
53 | 'upload_date': '20160725', | |
038a5e1a S |
54 | }, |
55 | 'params': { | |
56 | # m3u8 download | |
57 | 'skip_download': True, | |
29825140 RA |
58 | }, |
59 | 'expected_warnings': ['Unable to download f4m manifest'], | |
a5a8877f | 60 | }, { |
3b859145 RA |
61 | 'url': 'http://www.adultswim.com/videos/attack-on-titan', |
62 | 'info_dict': { | |
63 | 'id': 'b7A69dzfRzuaXIECdxW8XQ', | |
64 | 'title': 'Attack on Titan', | |
65 | 'description': 'md5:6c8e003ea0777b47013e894767f5e114', | |
66 | }, | |
67 | 'playlist_mincount': 12, | |
68 | }, { | |
69 | 'url': 'http://www.adultswim.com/videos/streams/williams-stream', | |
a5a8877f | 70 | 'info_dict': { |
3b859145 RA |
71 | 'id': 'd8DEBj7QRfetLsRgFnGEyg', |
72 | 'ext': 'mp4', | |
73 | 'title': r're:^Williams Stream \d{4}-\d{2}-\d{2} \d{2}:\d{2}$', | |
74 | 'description': 'original programming', | |
a5a8877f | 75 | }, |
a5a8877f YCH |
76 | 'params': { |
77 | # m3u8 download | |
78 | 'skip_download': True, | |
79 | }, | |
71155991 | 80 | }] |
81 | ||
48fbb100 | 82 | def _real_extract(self, url): |
3b859145 RA |
83 | show_path, episode_path = re.match(self._VALID_URL, url).groups() |
84 | display_id = episode_path or show_path | |
85 | webpage = self._download_webpage(url, display_id) | |
86 | initial_data = self._parse_json(self._search_regex( | |
87 | r'AS_INITIAL_DATA(?:__)?\s*=\s*({.+?});', | |
88 | webpage, 'initial data'), display_id) | |
89 | ||
90 | is_stream = show_path == 'streams' | |
91 | if is_stream: | |
92 | if not episode_path: | |
93 | episode_path = 'live-stream' | |
94 | ||
95 | video_data = next(stream for stream_path, stream in initial_data['streams'].items() if stream_path == episode_path) | |
96 | video_id = video_data.get('stream') | |
97 | ||
98 | if not video_id: | |
99 | entries = [] | |
100 | for episode in video_data.get('archiveEpisodes', []): | |
101 | episode_url = episode.get('url') | |
102 | if not episode_url: | |
103 | continue | |
104 | entries.append(self.url_result( | |
105 | episode_url, 'AdultSwim', episode.get('id'))) | |
106 | return self.playlist_result( | |
107 | entries, video_data.get('id'), video_data.get('title'), | |
108 | strip_or_none(video_data.get('description'))) | |
71155991 | 109 | else: |
3b859145 RA |
110 | show_data = initial_data['show'] |
111 | ||
112 | if not episode_path: | |
113 | entries = [] | |
114 | for video in show_data.get('videos', []): | |
115 | slug = video.get('slug') | |
116 | if not slug: | |
117 | continue | |
118 | entries.append(self.url_result( | |
119 | 'http://adultswim.com/videos/%s/%s' % (show_path, slug), | |
120 | 'AdultSwim', video.get('id'))) | |
121 | return self.playlist_result( | |
122 | entries, show_data.get('id'), show_data.get('title'), | |
123 | strip_or_none(show_data.get('metadata', {}).get('description'))) | |
124 | ||
125 | video_data = show_data['sluggedVideo'] | |
126 | video_id = video_data['id'] | |
127 | ||
128 | info = self._extract_cvp_info( | |
39ee2638 | 129 | 'http://www.adultswim.com/videos/api/v0/assets?platform=desktop&id=' + video_id, |
3b859145 RA |
130 | video_id, { |
131 | 'secure': { | |
132 | 'media_src': 'http://androidhls-secure.cdn.turner.com/adultswim/big', | |
133 | 'tokenizer_src': 'http://www.adultswim.com/astv/mvpd/processors/services/token_ipadAdobe.do', | |
134 | }, | |
135 | }, { | |
136 | 'url': url, | |
137 | 'site_name': 'AdultSwim', | |
138 | 'auth_required': video_data.get('auth'), | |
139 | }) | |
48fbb100 | 140 | |
3b859145 RA |
141 | info.update({ |
142 | 'id': video_id, | |
143 | 'display_id': display_id, | |
144 | 'description': info.get('description') or strip_or_none(video_data.get('description')), | |
145 | }) | |
146 | if not is_stream: | |
147 | info.update({ | |
148 | 'duration': info.get('duration') or int_or_none(video_data.get('duration')), | |
149 | 'timestamp': info.get('timestamp') or int_or_none(video_data.get('launch_date')), | |
150 | 'season_number': info.get('season_number') or int_or_none(video_data.get('season_number')), | |
151 | 'episode': info['title'], | |
152 | 'episode_number': info.get('episode_number') or int_or_none(video_data.get('episode_number')), | |
48fbb100 AMW |
153 | }) |
154 | ||
3b859145 RA |
155 | info['series'] = video_data.get('collection_title') or info.get('series') |
156 | if info['series'] and info['series'] != info['title']: | |
157 | info['title'] = '%s - %s' % (info['series'], info['title']) | |
158 | ||
159 | return info |