You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_HTTPError,
  6. compat_str,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. int_or_none,
  11. str_or_none,
  12. urlencode_postdata,
  13. )
  14. class RoosterTeethIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:.+?\.)?roosterteeth\.com/(?:episode|watch)/(?P<id>[^/?#&]+)'
  16. _NETRC_MACHINE = 'roosterteeth'
  17. _TESTS = [{
  18. 'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
  19. 'md5': 'e2bd7764732d785ef797700a2489f212',
  20. 'info_dict': {
  21. 'id': '9156',
  22. 'display_id': 'million-dollars-but-season-2-million-dollars-but-the-game-announcement',
  23. 'ext': 'mp4',
  24. 'title': 'Million Dollars, But... The Game Announcement',
  25. 'description': 'md5:168a54b40e228e79f4ddb141e89fe4f5',
  26. 'thumbnail': r're:^https?://.*\.png$',
  27. 'series': 'Million Dollars, But...',
  28. 'episode': 'Million Dollars, But... The Game Announcement',
  29. },
  30. }, {
  31. 'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
  32. 'only_matching': True,
  33. }, {
  34. 'url': 'http://funhaus.roosterteeth.com/episode/funhaus-shorts-2016-austin-sucks-funhaus-shorts',
  35. 'only_matching': True,
  36. }, {
  37. 'url': 'http://screwattack.roosterteeth.com/episode/death-battle-season-3-mewtwo-vs-shadow',
  38. 'only_matching': True,
  39. }, {
  40. 'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
  41. 'only_matching': True,
  42. }, {
  43. # only available for FIRST members
  44. 'url': 'http://roosterteeth.com/episode/rt-docs-the-world-s-greatest-head-massage-the-world-s-greatest-head-massage-an-asmr-journey-part-one',
  45. 'only_matching': True,
  46. }, {
  47. 'url': 'https://roosterteeth.com/watch/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
  48. 'only_matching': True,
  49. }]
  50. _EPISODE_BASE_URL = 'https://svod-be.roosterteeth.com/api/v1/episodes/'
  51. def _login(self):
  52. username, password = self._get_login_info()
  53. if username is None:
  54. return
  55. try:
  56. self._download_json(
  57. 'https://auth.roosterteeth.com/oauth/token',
  58. None, 'Logging in', data=urlencode_postdata({
  59. 'client_id': '4338d2b4bdc8db1239360f28e72f0d9ddb1fd01e7a38fbb07b4b1f4ba4564cc5',
  60. 'grant_type': 'password',
  61. 'username': username,
  62. 'password': password,
  63. }))
  64. except ExtractorError as e:
  65. msg = 'Unable to login'
  66. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 401:
  67. resp = self._parse_json(e.cause.read().decode(), None, fatal=False)
  68. if resp:
  69. error = resp.get('extra_info') or resp.get('error_description') or resp.get('error')
  70. if error:
  71. msg += ': ' + error
  72. self.report_warning(msg)
  73. def _real_initialize(self):
  74. if self._get_cookies(self._EPISODE_BASE_URL).get('rt_access_token'):
  75. return
  76. self._login()
  77. def _real_extract(self, url):
  78. display_id = self._match_id(url)
  79. api_episode_url = self._EPISODE_BASE_URL + display_id
  80. try:
  81. m3u8_url = self._download_json(
  82. api_episode_url + '/videos', display_id,
  83. 'Downloading video JSON metadata')['data'][0]['attributes']['url']
  84. except ExtractorError as e:
  85. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  86. if self._parse_json(e.cause.read().decode(), display_id).get('access') is False:
  87. self.raise_login_required(
  88. '%s is only available for FIRST members' % display_id)
  89. raise
  90. formats = self._extract_m3u8_formats(
  91. m3u8_url, display_id, 'mp4', 'm3u8_native', m3u8_id='hls')
  92. self._sort_formats(formats)
  93. episode = self._download_json(
  94. api_episode_url, display_id,
  95. 'Downloading episode JSON metadata')['data'][0]
  96. attributes = episode['attributes']
  97. title = attributes.get('title') or attributes['display_title']
  98. video_id = compat_str(episode['id'])
  99. thumbnails = []
  100. for image in episode.get('included', {}).get('images', []):
  101. if image.get('type') == 'episode_image':
  102. img_attributes = image.get('attributes') or {}
  103. for k in ('thumb', 'small', 'medium', 'large'):
  104. img_url = img_attributes.get(k)
  105. if img_url:
  106. thumbnails.append({
  107. 'id': k,
  108. 'url': img_url,
  109. })
  110. return {
  111. 'id': video_id,
  112. 'display_id': display_id,
  113. 'title': title,
  114. 'description': attributes.get('description') or attributes.get('caption'),
  115. 'thumbnails': thumbnails,
  116. 'series': attributes.get('show_title'),
  117. 'season_number': int_or_none(attributes.get('season_number')),
  118. 'season_id': attributes.get('season_id'),
  119. 'episode': title,
  120. 'episode_number': int_or_none(attributes.get('number')),
  121. 'episode_id': str_or_none(episode.get('uuid')),
  122. 'formats': formats,
  123. 'channel_id': attributes.get('channel_id'),
  124. 'duration': int_or_none(attributes.get('length')),
  125. }