dropout.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. from .common import InfoExtractor
  2. from .vimeo import VHXEmbedIE
  3. from ..utils import (
  4. ExtractorError,
  5. clean_html,
  6. get_element_by_class,
  7. get_element_by_id,
  8. get_elements_by_class,
  9. int_or_none,
  10. join_nonempty,
  11. unified_strdate,
  12. urlencode_postdata,
  13. )
  14. class DropoutIE(InfoExtractor):
  15. _LOGIN_URL = 'https://www.dropout.tv/login'
  16. _NETRC_MACHINE = 'dropout'
  17. _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?:[^/]+/)*videos/(?P<id>[^/]+)/?$'
  18. _TESTS = [
  19. {
  20. 'url': 'https://www.dropout.tv/game-changer/season:2/videos/yes-or-no',
  21. 'note': 'Episode in a series',
  22. 'md5': '5e000fdfd8d8fa46ff40456f1c2af04a',
  23. 'info_dict': {
  24. 'id': '738153',
  25. 'display_id': 'yes-or-no',
  26. 'ext': 'mp4',
  27. 'title': 'Yes or No',
  28. 'description': 'Ally, Brennan, and Zac are asked a simple question, but is there a correct answer?',
  29. 'release_date': '20200508',
  30. 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/351e3f24-c4a3-459a-8b79-dc80f1e5b7fd.jpg',
  31. 'series': 'Game Changer',
  32. 'season_number': 2,
  33. 'season': 'Season 2',
  34. 'episode_number': 6,
  35. 'episode': 'Yes or No',
  36. 'duration': 1180,
  37. 'uploader_id': 'user80538407',
  38. 'uploader_url': 'https://vimeo.com/user80538407',
  39. 'uploader': 'OTT Videos'
  40. },
  41. 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
  42. },
  43. {
  44. 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1/videos/episode-1',
  45. 'note': 'Episode in a series (missing release_date)',
  46. 'md5': '712caf7c191f1c47c8f1879520c2fa5c',
  47. 'info_dict': {
  48. 'id': '320562',
  49. 'display_id': 'episode-1',
  50. 'ext': 'mp4',
  51. 'title': 'The Beginning Begins',
  52. 'description': 'The cast introduces their PCs, including a neurotic elf, a goblin PI, and a corn-worshipping cleric.',
  53. 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/4421ed0d-f630-4c88-9004-5251b2b8adfa.jpg',
  54. 'series': 'Dimension 20: Fantasy High',
  55. 'season_number': 1,
  56. 'season': 'Season 1',
  57. 'episode_number': 1,
  58. 'episode': 'The Beginning Begins',
  59. 'duration': 6838,
  60. 'uploader_id': 'user80538407',
  61. 'uploader_url': 'https://vimeo.com/user80538407',
  62. 'uploader': 'OTT Videos'
  63. },
  64. 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
  65. },
  66. {
  67. 'url': 'https://www.dropout.tv/videos/misfits-magic-holiday-special',
  68. 'note': 'Episode not in a series',
  69. 'md5': 'c30fa18999c5880d156339f13c953a26',
  70. 'info_dict': {
  71. 'id': '1915774',
  72. 'display_id': 'misfits-magic-holiday-special',
  73. 'ext': 'mp4',
  74. 'title': 'Misfits & Magic Holiday Special',
  75. 'description': 'The magical misfits spend Christmas break at Gowpenny, with an unwelcome visitor.',
  76. 'release_date': '20211215',
  77. 'thumbnail': 'https://vhx.imgix.net/chuncensoredstaging/assets/d91ea8a6-b250-42ed-907e-b30fb1c65176-8e24b8e5.jpg',
  78. 'duration': 11698,
  79. 'uploader_id': 'user80538407',
  80. 'uploader_url': 'https://vimeo.com/user80538407',
  81. 'uploader': 'OTT Videos'
  82. },
  83. 'expected_warnings': ['Ignoring subtitle tracks found in the HLS manifest']
  84. }
  85. ]
  86. def _get_authenticity_token(self, display_id):
  87. signin_page = self._download_webpage(
  88. self._LOGIN_URL, display_id, note='Getting authenticity token')
  89. return self._html_search_regex(
  90. r'name=["\']authenticity_token["\'] value=["\'](.+?)["\']',
  91. signin_page, 'authenticity_token')
  92. def _login(self, display_id):
  93. username, password = self._get_login_info()
  94. if not username:
  95. return True
  96. response = self._download_webpage(
  97. self._LOGIN_URL, display_id, note='Logging in', fatal=False,
  98. data=urlencode_postdata({
  99. 'email': username,
  100. 'password': password,
  101. 'authenticity_token': self._get_authenticity_token(display_id),
  102. 'utf8': True
  103. }))
  104. user_has_subscription = self._search_regex(
  105. r'user_has_subscription:\s*["\'](.+?)["\']', response, 'subscription status', default='none')
  106. if user_has_subscription.lower() == 'true':
  107. return
  108. elif user_has_subscription.lower() == 'false':
  109. return 'Account is not subscribed'
  110. else:
  111. return 'Incorrect username/password'
  112. def _real_extract(self, url):
  113. display_id = self._match_id(url)
  114. webpage = None
  115. if self._get_cookies('https://www.dropout.tv').get('_session'):
  116. webpage = self._download_webpage(url, display_id)
  117. if not webpage or '<div id="watch-unauthorized"' in webpage:
  118. login_err = self._login(display_id)
  119. webpage = self._download_webpage(url, display_id)
  120. if login_err and '<div id="watch-unauthorized"' in webpage:
  121. if login_err is True:
  122. self.raise_login_required(method='any')
  123. raise ExtractorError(login_err, expected=True)
  124. embed_url = self._search_regex(r'embed_url:\s*["\'](.+?)["\']', webpage, 'embed url')
  125. thumbnail = self._og_search_thumbnail(webpage)
  126. watch_info = get_element_by_id('watch-info', webpage) or ''
  127. title = clean_html(get_element_by_class('video-title', watch_info))
  128. season_episode = get_element_by_class(
  129. 'site-font-secondary-color', get_element_by_class('text', watch_info))
  130. episode_number = int_or_none(self._search_regex(
  131. r'Episode (\d+)', season_episode or '', 'episode', default=None))
  132. return {
  133. '_type': 'url_transparent',
  134. 'ie_key': VHXEmbedIE.ie_key(),
  135. 'url': VHXEmbedIE._smuggle_referrer(embed_url, 'https://www.dropout.tv'),
  136. 'id': self._search_regex(r'embed\.vhx\.tv/videos/(.+?)\?', embed_url, 'id'),
  137. 'display_id': display_id,
  138. 'title': title,
  139. 'description': self._html_search_meta('description', webpage, fatal=False),
  140. 'thumbnail': thumbnail.split('?')[0] if thumbnail else None, # Ignore crop/downscale
  141. 'series': clean_html(get_element_by_class('series-title', watch_info)),
  142. 'episode_number': episode_number,
  143. 'episode': title if episode_number else None,
  144. 'season_number': int_or_none(self._search_regex(
  145. r'Season (\d+),', season_episode or '', 'season', default=None)),
  146. 'release_date': unified_strdate(self._search_regex(
  147. r'data-meta-field-name=["\']release_dates["\'] data-meta-field-value=["\'](.+?)["\']',
  148. watch_info, 'release date', default=None)),
  149. }
  150. class DropoutSeasonIE(InfoExtractor):
  151. _VALID_URL = r'https?://(?:www\.)?dropout\.tv/(?P<id>[^\/$&?#]+)(?:/?$|/season:[0-9]+/?$)'
  152. _TESTS = [
  153. {
  154. 'url': 'https://www.dropout.tv/dimension-20-fantasy-high/season:1',
  155. 'note': 'Multi-season series with the season in the url',
  156. 'playlist_count': 17,
  157. 'info_dict': {
  158. 'id': 'dimension-20-fantasy-high-season-1',
  159. 'title': 'Dimension 20 Fantasy High - Season 1'
  160. }
  161. },
  162. {
  163. 'url': 'https://www.dropout.tv/dimension-20-fantasy-high',
  164. 'note': 'Multi-season series with the season not in the url',
  165. 'playlist_count': 17,
  166. 'info_dict': {
  167. 'id': 'dimension-20-fantasy-high-season-1',
  168. 'title': 'Dimension 20 Fantasy High - Season 1'
  169. }
  170. },
  171. {
  172. 'url': 'https://www.dropout.tv/dimension-20-shriek-week',
  173. 'note': 'Single-season series',
  174. 'playlist_count': 4,
  175. 'info_dict': {
  176. 'id': 'dimension-20-shriek-week-season-1',
  177. 'title': 'Dimension 20 Shriek Week - Season 1'
  178. }
  179. }
  180. ]
  181. def _real_extract(self, url):
  182. season_id = self._match_id(url)
  183. season_title = season_id.replace('-', ' ').title()
  184. webpage = self._download_webpage(url, season_id)
  185. entries = [
  186. self.url_result(
  187. url=self._search_regex(r'<a href=["\'](.+?)["\'] class=["\']browse-item-link["\']',
  188. item, 'item_url'),
  189. ie=DropoutIE.ie_key()
  190. ) for item in get_elements_by_class('js-collection-item', webpage)
  191. ]
  192. seasons = (get_element_by_class('select-dropdown-wrapper', webpage) or '').strip().replace('\n', '')
  193. current_season = self._search_regex(r'<option[^>]+selected>([^<]+)</option>',
  194. seasons, 'current_season', default='').strip()
  195. return {
  196. '_type': 'playlist',
  197. 'id': join_nonempty(season_id, current_season.lower().replace(' ', '-')),
  198. 'title': join_nonempty(season_title, current_season, delim=' - '),
  199. 'entries': entries
  200. }