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.

148 lines
5.8 KiB

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