2016-06-22 02:58:42 -05:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2018-04-06 01:29:51 -04:00
|
|
|
import time
|
2016-07-10 01:28:28 +07:00
|
|
|
|
2016-06-22 02:58:42 -05:00
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2018-06-12 19:39:31 -04:00
|
|
|
compat_str,
|
2018-04-06 01:29:51 -04:00
|
|
|
str_or_none,
|
2018-06-12 19:39:31 -04:00
|
|
|
try_get,
|
2018-04-06 01:29:51 -04:00
|
|
|
unified_timestamp,
|
2016-06-22 02:58:42 -05:00
|
|
|
urlencode_postdata,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class RoosterTeethIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:.+?\.)?roosterteeth\.com/episode/(?P<id>[^/?#&]+)'
|
2018-04-07 00:23:37 -04:00
|
|
|
_LOGIN_URL = 'https://auth.roosterteeth.com/oauth/token'
|
2018-04-08 17:48:10 -04:00
|
|
|
_API_URL = 'https://svod-be.roosterteeth.com/api/v1/episodes/'
|
2018-04-07 00:23:37 -04:00
|
|
|
_ACCESS_TOKEN = None
|
2016-06-22 02:58:42 -05:00
|
|
|
_NETRC_MACHINE = 'roosterteeth'
|
|
|
|
_TESTS = [{
|
|
|
|
'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
|
2016-07-10 01:28:28 +07:00
|
|
|
'md5': 'e2bd7764732d785ef797700a2489f212',
|
2016-06-22 02:58:42 -05:00
|
|
|
'info_dict': {
|
2018-04-06 01:29:51 -04:00
|
|
|
'id': '9156',
|
2016-07-10 01:28:28 +07:00
|
|
|
'display_id': 'million-dollars-but-season-2-million-dollars-but-the-game-announcement',
|
2016-06-22 02:58:42 -05:00
|
|
|
'ext': 'mp4',
|
2018-04-06 01:29:51 -04:00
|
|
|
'title': 'Million Dollars, But... The Game Announcement',
|
2016-07-10 01:28:28 +07:00
|
|
|
'description': 'md5:0cc3b21986d54ed815f5faeccd9a9ca5',
|
2017-01-02 20:08:07 +08:00
|
|
|
'thumbnail': r're:^https?://.*\.png$',
|
2016-06-22 02:58:42 -05:00
|
|
|
'series': 'Million Dollars, But...',
|
2018-04-06 01:29:51 -04:00
|
|
|
'episode': 'S2:E10 - Million Dollars, But... The Game Announcement',
|
2016-06-22 02:58:42 -05:00
|
|
|
},
|
|
|
|
}, {
|
|
|
|
'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://funhaus.roosterteeth.com/episode/funhaus-shorts-2016-austin-sucks-funhaus-shorts',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://screwattack.roosterteeth.com/episode/death-battle-season-3-mewtwo-vs-shadow',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
|
|
|
|
'only_matching': True,
|
2016-07-10 01:28:28 +07:00
|
|
|
}, {
|
|
|
|
# only available for FIRST members
|
|
|
|
'url': 'http://roosterteeth.com/episode/rt-docs-the-world-s-greatest-head-massage-the-world-s-greatest-head-massage-an-asmr-journey-part-one',
|
|
|
|
'only_matching': True,
|
2016-06-22 02:58:42 -05:00
|
|
|
}]
|
|
|
|
|
|
|
|
def _login(self):
|
|
|
|
(username, password) = self._get_login_info()
|
2016-07-10 01:28:28 +07:00
|
|
|
if username is None:
|
|
|
|
return
|
2016-06-22 02:58:42 -05:00
|
|
|
|
2018-04-08 17:49:02 -04:00
|
|
|
cookie = self._get_cookie('rt_access_token')
|
|
|
|
if cookie and not cookie.is_expired():
|
|
|
|
self._ACCESS_TOKEN = cookie.value
|
|
|
|
return
|
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
response = self._download_json(
|
2016-06-22 02:58:42 -05:00
|
|
|
self._LOGIN_URL, None,
|
2017-11-11 20:49:03 +07:00
|
|
|
note='Logging in',
|
2018-04-07 00:23:37 -04:00
|
|
|
errnote='Unable to log in',
|
|
|
|
data=urlencode_postdata({
|
|
|
|
'username': username,
|
|
|
|
'password': password,
|
|
|
|
'client_id': '4338d2b4bdc8db1239360f28e72f0d9ddb1fd01e7a38fbb07b4b1f4ba4564cc5',
|
|
|
|
'grant_type': 'password',
|
2016-07-10 01:28:28 +07:00
|
|
|
})
|
2018-04-07 00:23:37 -04:00
|
|
|
)
|
2016-07-10 01:28:28 +07:00
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
self._ACCESS_TOKEN = response.get('access_token')
|
|
|
|
if not self._ACCESS_TOKEN:
|
2016-07-10 01:28:28 +07:00
|
|
|
raise ExtractorError('Unable to log in')
|
2016-06-22 02:58:42 -05:00
|
|
|
|
2018-04-08 17:49:02 -04:00
|
|
|
created_at = response.get('created_at', 0)
|
|
|
|
expires_in = response.get('expires_in', 0)
|
|
|
|
|
2018-06-12 19:09:21 -04:00
|
|
|
self._set_cookie('.roosterteeth.com', 'rt_access_token', self._ACCESS_TOKEN, created_at + expires_in)
|
2018-04-08 17:49:02 -04:00
|
|
|
|
2016-06-22 02:58:42 -05:00
|
|
|
def _real_initialize(self):
|
|
|
|
self._login()
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2016-07-10 01:28:28 +07:00
|
|
|
display_id = self._match_id(url)
|
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
headers = {}
|
|
|
|
if self._ACCESS_TOKEN:
|
2018-06-12 19:09:21 -04:00
|
|
|
headers['Authorization'] = 'Bearer ' + self._ACCESS_TOKEN
|
2018-04-06 01:29:51 -04:00
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
api_response = self._call_api(
|
|
|
|
display_id,
|
|
|
|
note='Downloading video information (1/2)',
|
|
|
|
errnote='Unable to download video information (1/2)',
|
|
|
|
headers=headers,
|
2018-04-06 01:29:51 -04:00
|
|
|
)
|
|
|
|
|
2018-06-12 19:35:42 -04:00
|
|
|
data = api_response['data'][0]
|
2018-04-06 01:29:51 -04:00
|
|
|
|
2018-06-12 19:35:42 -04:00
|
|
|
attributes = data['attributes']
|
2018-04-06 21:24:04 -04:00
|
|
|
episode = attributes.get('display_title')
|
2018-06-12 19:35:42 -04:00
|
|
|
title = attributes['title']
|
2018-04-06 21:24:04 -04:00
|
|
|
description = attributes.get('caption')
|
|
|
|
series = attributes.get('show_title')
|
2018-04-07 03:28:16 -04:00
|
|
|
|
2018-07-13 17:19:30 -04:00
|
|
|
thumbnails = []
|
|
|
|
for size in ['thumb', 'small', 'medium', 'large']:
|
|
|
|
thumbnail = try_get(data, lambda x: x['included']['images'][0]['attributes'][size], compat_str)
|
|
|
|
if thumbnail:
|
|
|
|
thumbnails.append({'url': thumbnail})
|
2018-04-07 00:23:37 -04:00
|
|
|
|
|
|
|
video_response = self._call_api(
|
|
|
|
display_id,
|
|
|
|
path='/videos',
|
|
|
|
note='Downloading video information (2/2)',
|
|
|
|
errnote='Unable to download video information (2/2)',
|
|
|
|
headers=headers,
|
2018-04-06 01:29:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
if video_response.get('access') is not None:
|
|
|
|
now = time.time()
|
|
|
|
sponsor_golive = unified_timestamp(attributes.get('sponsor_golive_at'))
|
|
|
|
member_golive = unified_timestamp(attributes.get('member_golive_at'))
|
|
|
|
public_golive = unified_timestamp(attributes.get('public_golive_at'))
|
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
if attributes.get('is_sponsors_only', False):
|
2018-04-06 01:29:51 -04:00
|
|
|
if now < sponsor_golive:
|
2018-04-07 00:23:37 -04:00
|
|
|
self._golive_error(display_id, 'FIRST members')
|
2018-04-06 01:29:51 -04:00
|
|
|
else:
|
|
|
|
self.raise_login_required('{0} is only available for FIRST members'.format(display_id))
|
|
|
|
else:
|
|
|
|
if now < member_golive:
|
2018-04-07 00:23:37 -04:00
|
|
|
self._golive_error(display_id, 'site members')
|
2018-04-06 01:29:51 -04:00
|
|
|
elif now < public_golive:
|
2018-04-07 00:23:37 -04:00
|
|
|
self._golive_error(display_id, 'the public')
|
2018-04-06 01:29:51 -04:00
|
|
|
else:
|
|
|
|
raise ExtractorError('Video is not available')
|
2018-04-07 00:23:37 -04:00
|
|
|
|
2018-06-12 19:39:31 -04:00
|
|
|
video_attributes = try_get(video_response, lambda x: x['data'][0]['attributes'])
|
2018-04-06 01:29:51 -04:00
|
|
|
|
|
|
|
m3u8_url = video_attributes.get('url')
|
2016-07-10 01:28:28 +07:00
|
|
|
if not m3u8_url:
|
|
|
|
raise ExtractorError('Unable to extract m3u8 URL')
|
|
|
|
|
|
|
|
formats = self._extract_m3u8_formats(
|
|
|
|
m3u8_url, display_id, ext='mp4',
|
|
|
|
entry_protocol='m3u8_native', m3u8_id='hls')
|
2016-06-22 02:58:42 -05:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
2018-04-06 01:29:51 -04:00
|
|
|
video_id = str_or_none(video_attributes.get('content_id'))
|
2016-07-10 01:28:28 +07:00
|
|
|
|
2016-06-22 02:58:42 -05:00
|
|
|
return {
|
2016-07-10 01:28:28 +07:00
|
|
|
'id': video_id,
|
|
|
|
'display_id': display_id,
|
2016-06-22 02:58:42 -05:00
|
|
|
'title': title,
|
|
|
|
'description': description,
|
2018-07-13 17:19:30 -04:00
|
|
|
'thumbnails': thumbnails,
|
2016-06-22 02:58:42 -05:00
|
|
|
'series': series,
|
|
|
|
'episode': episode,
|
2016-07-10 01:28:28 +07:00
|
|
|
'formats': formats,
|
2016-06-22 02:58:42 -05:00
|
|
|
}
|
2018-04-06 01:29:51 -04:00
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
def _golive_error(self, video_id, member_level):
|
2018-04-06 01:29:51 -04:00
|
|
|
raise ExtractorError('{0} is not yet live for {1}'.format(video_id, member_level))
|
|
|
|
|
2018-04-07 00:23:37 -04:00
|
|
|
def _call_api(self, video_id, path=None, **kwargs):
|
|
|
|
url = self._API_URL + video_id
|
|
|
|
if path:
|
|
|
|
url = url + path
|
|
|
|
|
2018-06-12 19:09:21 -04:00
|
|
|
return self._download_json(url, video_id, **kwargs)
|
2018-04-08 17:49:02 -04:00
|
|
|
|
|
|
|
def _get_cookie(self, name):
|
|
|
|
for cookie in self._downloader.cookiejar:
|
|
|
|
if cookie.name == name:
|
|
|
|
return cookie
|
|
|
|
return None
|