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.

209 lines
7.7 KiB

Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
Switch codebase to use sanitized_Request instead of compat_urllib_request.Request [downloader/dash] Use sanitized_Request [downloader/http] Use sanitized_Request [atresplayer] Use sanitized_Request [bambuser] Use sanitized_Request [bliptv] Use sanitized_Request [brightcove] Use sanitized_Request [cbs] Use sanitized_Request [ceskatelevize] Use sanitized_Request [collegerama] Use sanitized_Request [extractor/common] Use sanitized_Request [crunchyroll] Use sanitized_Request [dailymotion] Use sanitized_Request [dcn] Use sanitized_Request [dramafever] Use sanitized_Request [dumpert] Use sanitized_Request [eitb] Use sanitized_Request [escapist] Use sanitized_Request [everyonesmixtape] Use sanitized_Request [extremetube] Use sanitized_Request [facebook] Use sanitized_Request [fc2] Use sanitized_Request [flickr] Use sanitized_Request [4tube] Use sanitized_Request [gdcvault] Use sanitized_Request [extractor/generic] Use sanitized_Request [hearthisat] Use sanitized_Request [hotnewhiphop] Use sanitized_Request [hypem] Use sanitized_Request [iprima] Use sanitized_Request [ivi] Use sanitized_Request [keezmovies] Use sanitized_Request [letv] Use sanitized_Request [lynda] Use sanitized_Request [metacafe] Use sanitized_Request [minhateca] Use sanitized_Request [miomio] Use sanitized_Request [meovideo] Use sanitized_Request [mofosex] Use sanitized_Request [moniker] Use sanitized_Request [mooshare] Use sanitized_Request [movieclips] Use sanitized_Request [mtv] Use sanitized_Request [myvideo] Use sanitized_Request [neteasemusic] Use sanitized_Request [nfb] Use sanitized_Request [niconico] Use sanitized_Request [noco] Use sanitized_Request [nosvideo] Use sanitized_Request [novamov] Use sanitized_Request [nowness] Use sanitized_Request [nuvid] Use sanitized_Request [played] Use sanitized_Request [pluralsight] Use sanitized_Request [pornhub] Use sanitized_Request [pornotube] Use sanitized_Request [primesharetv] Use sanitized_Request [promptfile] Use sanitized_Request [qqmusic] Use sanitized_Request [rtve] Use sanitized_Request [safari] Use sanitized_Request [sandia] Use sanitized_Request [shared] Use sanitized_Request [sharesix] Use sanitized_Request [sina] Use sanitized_Request [smotri] Use sanitized_Request [sohu] Use sanitized_Request [spankwire] Use sanitized_Request [sportdeutschland] Use sanitized_Request [streamcloud] Use sanitized_Request [streamcz] Use sanitized_Request [tapely] Use sanitized_Request [tube8] Use sanitized_Request [tubitv] Use sanitized_Request [twitch] Use sanitized_Request [twitter] Use sanitized_Request [udemy] Use sanitized_Request [vbox7] Use sanitized_Request [veoh] Use sanitized_Request [vessel] Use sanitized_Request [vevo] Use sanitized_Request [viddler] Use sanitized_Request [videomega] Use sanitized_Request [viewvster] Use sanitized_Request [viki] Use sanitized_Request [vk] Use sanitized_Request [vodlocker] Use sanitized_Request [voicerepublic] Use sanitized_Request [wistia] Use sanitized_Request [xfileshare] Use sanitized_Request [xtube] Use sanitized_Request [xvideos] Use sanitized_Request [yandexmusic] Use sanitized_Request [youku] Use sanitized_Request [youporn] Use sanitized_Request [youtube] Use sanitized_Request [patreon] Use sanitized_Request [extractor/common] Remove unused import [nfb] PEP 8
9 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. from .amp import AMPIE
  5. from ..compat import (
  6. compat_HTTPError,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. clean_html,
  12. int_or_none,
  13. remove_end,
  14. sanitized_Request,
  15. urlencode_postdata
  16. )
  17. class DramaFeverBaseIE(AMPIE):
  18. _LOGIN_URL = 'https://www.dramafever.com/accounts/login/'
  19. _NETRC_MACHINE = 'dramafever'
  20. _GEO_COUNTRIES = ['US', 'CA']
  21. _CONSUMER_SECRET = 'DA59dtVXYLxajktV'
  22. _consumer_secret = None
  23. def _get_consumer_secret(self):
  24. mainjs = self._download_webpage(
  25. 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
  26. None, 'Downloading main.js', fatal=False)
  27. if not mainjs:
  28. return self._CONSUMER_SECRET
  29. return self._search_regex(
  30. r"var\s+cs\s*=\s*'([^']+)'", mainjs,
  31. 'consumer secret', default=self._CONSUMER_SECRET)
  32. def _real_initialize(self):
  33. self._login()
  34. self._consumer_secret = self._get_consumer_secret()
  35. def _login(self):
  36. (username, password) = self._get_login_info()
  37. if username is None:
  38. return
  39. login_form = {
  40. 'username': username,
  41. 'password': password,
  42. }
  43. request = sanitized_Request(
  44. self._LOGIN_URL, urlencode_postdata(login_form))
  45. response = self._download_webpage(
  46. request, None, 'Logging in')
  47. if all(logout_pattern not in response
  48. for logout_pattern in ['href="/accounts/logout/"', '>Log out<']):
  49. error = self._html_search_regex(
  50. r'(?s)<h\d[^>]+\bclass="hidden-xs prompt"[^>]*>(.+?)</h\d',
  51. response, 'error message', default=None)
  52. if error:
  53. raise ExtractorError('Unable to login: %s' % error, expected=True)
  54. raise ExtractorError('Unable to log in')
  55. class DramaFeverIE(DramaFeverBaseIE):
  56. IE_NAME = 'dramafever'
  57. _VALID_URL = r'https?://(?:www\.)?dramafever\.com/(?:[^/]+/)?drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
  58. _TESTS = [{
  59. 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
  60. 'info_dict': {
  61. 'id': '4512.1',
  62. 'ext': 'flv',
  63. 'title': 'Cooking with Shin',
  64. 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
  65. 'episode': 'Episode 1',
  66. 'episode_number': 1,
  67. 'thumbnail': r're:^https?://.*\.jpg',
  68. 'timestamp': 1404336058,
  69. 'upload_date': '20140702',
  70. 'duration': 344,
  71. },
  72. 'params': {
  73. # m3u8 download
  74. 'skip_download': True,
  75. },
  76. }, {
  77. 'url': 'http://www.dramafever.com/drama/4826/4/Mnet_Asian_Music_Awards_2015/?ap=1',
  78. 'info_dict': {
  79. 'id': '4826.4',
  80. 'ext': 'flv',
  81. 'title': 'Mnet Asian Music Awards 2015',
  82. 'description': 'md5:3ff2ee8fedaef86e076791c909cf2e91',
  83. 'episode': 'Mnet Asian Music Awards 2015 - Part 3',
  84. 'episode_number': 4,
  85. 'thumbnail': r're:^https?://.*\.jpg',
  86. 'timestamp': 1450213200,
  87. 'upload_date': '20151215',
  88. 'duration': 5359,
  89. },
  90. 'params': {
  91. # m3u8 download
  92. 'skip_download': True,
  93. },
  94. }, {
  95. 'url': 'https://www.dramafever.com/zh-cn/drama/4972/15/Doctor_Romantic/',
  96. 'only_matching': True,
  97. }]
  98. def _real_extract(self, url):
  99. video_id = self._match_id(url).replace('/', '.')
  100. try:
  101. info = self._extract_feed_info(
  102. 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id)
  103. except ExtractorError as e:
  104. if isinstance(e.cause, compat_HTTPError):
  105. self.raise_geo_restricted(
  106. msg='Currently unavailable in your country',
  107. countries=self._GEO_COUNTRIES)
  108. raise
  109. # title is postfixed with video id for some reason, removing
  110. if info.get('title'):
  111. info['title'] = remove_end(info['title'], video_id).strip()
  112. series_id, episode_number = video_id.split('.')
  113. episode_info = self._download_json(
  114. # We only need a single episode info, so restricting page size to one episode
  115. # and dealing with page number as with episode number
  116. r'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
  117. % (self._consumer_secret, series_id, episode_number),
  118. video_id, 'Downloading episode info JSON', fatal=False)
  119. if episode_info:
  120. value = episode_info.get('value')
  121. if isinstance(value, list):
  122. for v in value:
  123. if v.get('type') == 'Episode':
  124. subfile = v.get('subfile') or v.get('new_subfile')
  125. if subfile and subfile != 'http://www.dramafever.com/st/':
  126. info.setdefault('subtitles', {}).setdefault('English', []).append({
  127. 'ext': 'srt',
  128. 'url': subfile,
  129. })
  130. episode_number = int_or_none(v.get('number'))
  131. episode_fallback = 'Episode'
  132. if episode_number:
  133. episode_fallback += ' %d' % episode_number
  134. info['episode'] = v.get('title') or episode_fallback
  135. info['episode_number'] = episode_number
  136. break
  137. return info
  138. class DramaFeverSeriesIE(DramaFeverBaseIE):
  139. IE_NAME = 'dramafever:series'
  140. _VALID_URL = r'https?://(?:www\.)?dramafever\.com/(?:[^/]+/)?drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
  141. _TESTS = [{
  142. 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
  143. 'info_dict': {
  144. 'id': '4512',
  145. 'title': 'Cooking with Shin',
  146. 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
  147. },
  148. 'playlist_count': 4,
  149. }, {
  150. 'url': 'http://www.dramafever.com/drama/124/IRIS/',
  151. 'info_dict': {
  152. 'id': '124',
  153. 'title': 'IRIS',
  154. 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
  155. },
  156. 'playlist_count': 20,
  157. }]
  158. _PAGE_SIZE = 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
  159. def _real_extract(self, url):
  160. series_id = self._match_id(url)
  161. series = self._download_json(
  162. 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
  163. % (self._consumer_secret, series_id),
  164. series_id, 'Downloading series JSON')['series'][series_id]
  165. title = clean_html(series['name'])
  166. description = clean_html(series.get('description') or series.get('description_short'))
  167. entries = []
  168. for page_num in itertools.count(1):
  169. episodes = self._download_json(
  170. 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
  171. % (self._consumer_secret, series_id, self._PAGE_SIZE, page_num),
  172. series_id, 'Downloading episodes JSON page #%d' % page_num)
  173. for episode in episodes.get('value', []):
  174. episode_url = episode.get('episode_url')
  175. if not episode_url:
  176. continue
  177. entries.append(self.url_result(
  178. compat_urlparse.urljoin(url, episode_url),
  179. 'DramaFever', episode.get('guid')))
  180. if page_num == episodes['num_pages']:
  181. break
  182. return self.playlist_result(entries, series_id, title, description)