]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/roosterteeth.py
1 from .common
import InfoExtractor
2 from ..compat
import compat_HTTPError
18 class RoosterTeethBaseIE(InfoExtractor
):
19 _NETRC_MACHINE
= 'roosterteeth'
20 _API_BASE
= 'https://svod-be.roosterteeth.com'
21 _API_BASE_URL
= f
'{_API_BASE}/api/v1'
23 def _perform_login(self
, username
, password
):
24 if self
._get
_cookies
(self
._API
_BASE
_URL
).get('rt_access_token'):
29 'https://auth.roosterteeth.com/oauth/token',
30 None, 'Logging in', data
=urlencode_postdata({
31 'client_id': '4338d2b4bdc8db1239360f28e72f0d9ddb1fd01e7a38fbb07b4b1f4ba4564cc5',
32 'grant_type': 'password',
36 except ExtractorError
as e
:
37 msg
= 'Unable to login'
38 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 401:
39 resp
= self
._parse
_json
(e
.cause
.read().decode(), None, fatal
=False)
41 error
= resp
.get('extra_info') or resp
.get('error_description') or resp
.get('error')
44 self
.report_warning(msg
)
46 def _extract_video_info(self
, data
):
48 for image
in traverse_obj(data
, ('included', 'images')):
49 if image
.get('type') not in ('episode_image', 'bonus_feature_image'):
54 } for name
, url
in (image
.get('attributes') or {}).items() if url_or_none(url
)])
56 attributes
= data
.get('attributes') or {}
57 title
= traverse_obj(attributes
, 'title', 'display_title')
58 sub_only
= attributes
.get('is_sponsors_only')
61 'id': str(data
.get('id')),
62 'display_id': attributes
.get('slug'),
64 'description': traverse_obj(attributes
, 'description', 'caption'),
65 'series': attributes
.get('show_title'),
66 'season_number': int_or_none(attributes
.get('season_number')),
67 'season_id': attributes
.get('season_id'),
69 'episode_number': int_or_none(attributes
.get('number')),
70 'episode_id': str_or_none(data
.get('uuid')),
71 'channel_id': attributes
.get('channel_id'),
72 'duration': int_or_none(attributes
.get('length')),
73 'thumbnails': thumbnails
,
74 'availability': self
._availability
(
75 needs_premium
=sub_only
, needs_subscription
=sub_only
, needs_auth
=sub_only
,
76 is_private
=False, is_unlisted
=False),
77 'tags': attributes
.get('genres')
81 class RoosterTeethIE(RoosterTeethBaseIE
):
82 _VALID_URL
= r
'https?://(?:.+?\.)?roosterteeth\.com/(?:episode|watch)/(?P<id>[^/?#&]+)'
84 'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
87 'display_id': 'million-dollars-but-season-2-million-dollars-but-the-game-announcement',
89 'title': 'Million Dollars, But... The Game Announcement',
90 'description': 'md5:168a54b40e228e79f4ddb141e89fe4f5',
91 'thumbnail': r
're:^https?://.*\.png$',
92 'series': 'Million Dollars, But...',
93 'episode': 'Million Dollars, But... The Game Announcement',
95 'params': {'skip_download': True}
,
97 'url': 'https://roosterteeth.com/watch/rwby-bonus-25',
100 'display_id': 'rwby-bonus-25',
102 'description': 'md5:f30ff570741213418a8d2c19868b93ab',
104 'channel_id': '92f780eb-ebfe-4bf5-a3b5-c6ad5460a5f1',
105 'thumbnail': r
're:^https?://.*\.(png|jpe?g)$',
108 'params': {'skip_download': True}
,
110 'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
111 'only_matching': True,
113 'url': 'http://funhaus.roosterteeth.com/episode/funhaus-shorts-2016-austin-sucks-funhaus-shorts',
114 'only_matching': True,
116 'url': 'http://screwattack.roosterteeth.com/episode/death-battle-season-3-mewtwo-vs-shadow',
117 'only_matching': True,
119 'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
120 'only_matching': True,
122 # only available for FIRST members
123 'url': 'http://roosterteeth.com/episode/rt-docs-the-world-s-greatest-head-massage-the-world-s-greatest-head-massage-an-asmr-journey-part-one',
124 'only_matching': True,
126 'url': 'https://roosterteeth.com/watch/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
127 'only_matching': True,
130 def _real_extract(self
, url
):
131 display_id
= self
._match
_id
(url
)
132 api_episode_url
= f
'{self._API_BASE_URL}/watch/{display_id}'
135 video_data
= self
._download
_json
(
136 api_episode_url
+ '/videos', display_id
,
137 'Downloading video JSON metadata')['data'][0]
138 m3u8_url
= video_data
['attributes']['url']
139 # XXX: additional URL at video_data['links']['download']
140 except ExtractorError
as e
:
141 if isinstance(e
.cause
, compat_HTTPError
) and e
.cause
.code
== 403:
142 if self
._parse
_json
(e
.cause
.read().decode(), display_id
).get('access') is False:
143 self
.raise_login_required(
144 '%s is only available for FIRST members' % display_id
)
147 formats
, subtitles
= self
._extract
_m
3u8_formats
_and
_subtitles
(
148 m3u8_url
, display_id
, 'mp4', 'm3u8_native', m3u8_id
='hls')
149 self
._sort
_formats
(formats
)
151 episode
= self
._download
_json
(
152 api_episode_url
, display_id
,
153 'Downloading episode JSON metadata')['data'][0]
156 'display_id': display_id
,
158 'subtitles': subtitles
,
159 **self
._extract
_video
_info
(episode
)
163 class RoosterTeethSeriesIE(RoosterTeethBaseIE
):
164 _VALID_URL
= r
'https?://(?:.+?\.)?roosterteeth\.com/series/(?P<id>[^/?#&]+)'
166 'url': 'https://roosterteeth.com/series/rwby?season=7',
167 'playlist_count': 13,
170 'title': 'RWBY - Season 7',
173 'url': 'https://roosterteeth.com/series/role-initiative',
174 'playlist_mincount': 16,
176 'id': 'role-initiative',
177 'title': 'Role Initiative',
180 'url': 'https://roosterteeth.com/series/let-s-play-minecraft?season=9',
181 'playlist_mincount': 50,
183 'id': 'let-s-play-minecraft-9',
184 'title': 'Let\'s Play Minecraft - Season 9',
188 def _entries(self
, series_id
, season_number
):
189 display_id
= join_nonempty(series_id
, season_number
)
190 # TODO: extract bonus material
191 for data
in self
._download
_json
(
192 f
'{self._API_BASE_URL}/shows/{series_id}/seasons?order=asc&order_by', display_id
)['data']:
193 idx
= traverse_obj(data
, ('attributes', 'number'))
194 if season_number
and idx
!= season_number
:
196 season_url
= update_url_query(urljoin(self
._API
_BASE
, data
['links']['episodes']), {'per_page': 1000}
)
197 season
= self
._download
_json
(season_url
, display_id
, f
'Downloading season {idx} JSON metadata')['data']
198 for episode
in season
:
199 yield self
.url_result(
200 f
'https://www.roosterteeth.com{episode["canonical_links"]["self"]}',
201 RoosterTeethIE
.ie_key(),
202 **self
._extract
_video
_info
(episode
))
204 def _real_extract(self
, url
):
205 series_id
= self
._match
_id
(url
)
206 season_number
= traverse_obj(parse_qs(url
), ('season', 0), expected_type
=int_or_none
)
208 entries
= LazyList(self
._entries
(series_id
, season_number
))
209 return self
.playlist_result(
211 join_nonempty(series_id
, season_number
),
212 join_nonempty(entries
[0].get('series'), season_number
, delim
=' - Season '))