dropout.py 9.7 KB

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