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.

112 lines
4.4 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. ExtractorError,
  6. urlencode_postdata,
  7. )
  8. class RoosterTeethIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:.+?\.)?roosterteeth\.com/episode/(?P<id>[^/?#&]+)'
  10. _LOGIN_URL = 'https://roosterteeth.com/login'
  11. _NETRC_MACHINE = 'roosterteeth'
  12. _TESTS = [{
  13. 'url': 'http://roosterteeth.com/episode/million-dollars-but-season-2-million-dollars-but-the-game-announcement',
  14. 'info_dict': {
  15. 'id': '26576',
  16. 'ext': 'mp4',
  17. 'title': 'Million Dollars, But... The Game Announcement',
  18. 'thumbnail': 're:^https?://.*\.png$',
  19. 'description': 'Introducing Million Dollars, But... The Game! Available for pre-order now at www.MDBGame.com ',
  20. 'creator': 'Rooster Teeth',
  21. 'series': 'Million Dollars, But...',
  22. 'episode': 'Million Dollars, But... The Game Announcement',
  23. 'episode_id': '26576',
  24. },
  25. 'params': {
  26. 'skip_download': True, # m3u8 downloads
  27. },
  28. }, {
  29. 'url': 'http://achievementhunter.roosterteeth.com/episode/off-topic-the-achievement-hunter-podcast-2016-i-didn-t-think-it-would-pass-31',
  30. 'only_matching': True,
  31. }, {
  32. 'url': 'http://funhaus.roosterteeth.com/episode/funhaus-shorts-2016-austin-sucks-funhaus-shorts',
  33. 'only_matching': True,
  34. }, {
  35. 'url': 'http://screwattack.roosterteeth.com/episode/death-battle-season-3-mewtwo-vs-shadow',
  36. 'only_matching': True,
  37. }, {
  38. 'url': 'http://theknow.roosterteeth.com/episode/the-know-game-news-season-1-boring-steam-sales-are-better',
  39. 'only_matching': True,
  40. }]
  41. def _login(self):
  42. (username, password) = self._get_login_info()
  43. if username is None or password is None:
  44. return False
  45. # token is required to authenticate request
  46. login_page = self._download_webpage(self._LOGIN_URL, None, 'Getting login token', 'Unable to get login token')
  47. login_form = self._hidden_inputs(login_page)
  48. login_form.update({
  49. 'username': username,
  50. 'password': password,
  51. })
  52. login_payload = urlencode_postdata(login_form)
  53. # required for proper responses
  54. login_headers = {
  55. 'Referer': self._LOGIN_URL,
  56. }
  57. login_request = self._download_webpage(
  58. self._LOGIN_URL, None,
  59. note='Logging in as %s' % username,
  60. data=login_payload,
  61. headers=login_headers)
  62. if 'Authentication failed' in login_request:
  63. raise ExtractorError(
  64. 'Login failed (invalid username/password)', expected=True)
  65. def _real_initialize(self):
  66. self._login()
  67. def _real_extract(self, url):
  68. match_id = self._match_id(url)
  69. webpage = self._download_webpage(url, match_id)
  70. episode_id = self._html_search_regex(r"commentControls\('#comment-([0-9]+)'\)", webpage, 'episode id', match_id, False)
  71. self.report_extraction(episode_id)
  72. title = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'episode title', self._og_search_title(webpage), False)
  73. thumbnail = self._og_search_thumbnail(webpage)
  74. description = self._og_search_description(webpage)
  75. creator = self._html_search_regex(r'<h3>Latest (.+) Gear</h3>', webpage, 'site', 'Rooster Teeth', False)
  76. series = self._html_search_regex(r'<h2>More ([^<]+)</h2>', webpage, 'series', fatal=False)
  77. episode = self._html_search_regex(r'<title>([^<]+)</title>', webpage, 'episode title', fatal=False)
  78. if '<div class="non-sponsor">' in webpage:
  79. self.raise_login_required('%s is only available for FIRST members' % title)
  80. if '<div class="golive-gate">' in webpage:
  81. self.raise_login_required('%s is not available yet' % title)
  82. formats = self._extract_m3u8_formats(self._html_search_regex(r"file: '(.+?)m3u8'", webpage, 'm3u8 url') + 'm3u8', episode_id, ext='mp4')
  83. self._sort_formats(formats)
  84. return {
  85. 'id': episode_id,
  86. 'title': title,
  87. 'formats': formats,
  88. 'thumbnail': thumbnail,
  89. 'description': description,
  90. 'creator': creator,
  91. 'series': series,
  92. 'episode': episode,
  93. 'episode_id': episode_id,
  94. }