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.

216 lines
7.8 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. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import itertools
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_HTTPError,
  7. compat_urllib_parse,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. ExtractorError,
  12. clean_html,
  13. determine_ext,
  14. int_or_none,
  15. parse_iso8601,
  16. sanitized_Request,
  17. )
  18. class DramaFeverBaseIE(InfoExtractor):
  19. _LOGIN_URL = 'https://www.dramafever.com/accounts/login/'
  20. _NETRC_MACHINE = 'dramafever'
  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, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
  45. response = self._download_webpage(
  46. request, None, 'Logging in as %s' % username)
  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)class="hidden-xs prompt"[^>]*>(.+?)<',
  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. _TEST = {
  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 4512.1',
  64. 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
  65. 'thumbnail': 're:^https?://.*\.jpg',
  66. 'timestamp': 1404336058,
  67. 'upload_date': '20140702',
  68. 'duration': 343,
  69. }
  70. }
  71. def _real_extract(self, url):
  72. video_id = self._match_id(url).replace('/', '.')
  73. try:
  74. feed = self._download_json(
  75. 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id,
  76. video_id, 'Downloading episode JSON')['channel']['item']
  77. except ExtractorError as e:
  78. if isinstance(e.cause, compat_HTTPError):
  79. raise ExtractorError(
  80. 'Currently unavailable in your country.', expected=True)
  81. raise
  82. media_group = feed.get('media-group', {})
  83. formats = []
  84. for media_content in media_group['media-content']:
  85. src = media_content.get('@attributes', {}).get('url')
  86. if not src:
  87. continue
  88. ext = determine_ext(src)
  89. if ext == 'f4m':
  90. formats.extend(self._extract_f4m_formats(
  91. src, video_id, f4m_id='hds'))
  92. elif ext == 'm3u8':
  93. formats.extend(self._extract_m3u8_formats(
  94. src, video_id, 'mp4', m3u8_id='hls'))
  95. else:
  96. formats.append({
  97. 'url': src,
  98. })
  99. self._sort_formats(formats)
  100. title = media_group.get('media-title')
  101. description = media_group.get('media-description')
  102. duration = int_or_none(media_group['media-content'][0].get('@attributes', {}).get('duration'))
  103. thumbnail = self._proto_relative_url(
  104. media_group.get('media-thumbnail', {}).get('@attributes', {}).get('url'))
  105. timestamp = parse_iso8601(feed.get('pubDate'), ' ')
  106. subtitles = {}
  107. for media_subtitle in media_group.get('media-subTitle', []):
  108. lang = media_subtitle.get('@attributes', {}).get('lang')
  109. href = media_subtitle.get('@attributes', {}).get('href')
  110. if not lang or not href:
  111. continue
  112. subtitles[lang] = [{
  113. 'ext': 'ttml',
  114. 'url': href,
  115. }]
  116. series_id, episode_number = video_id.split('.')
  117. episode_info = self._download_json(
  118. # We only need a single episode info, so restricting page size to one episode
  119. # and dealing with page number as with episode number
  120. r'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
  121. % (self._consumer_secret, series_id, episode_number),
  122. video_id, 'Downloading episode info JSON', fatal=False)
  123. if episode_info:
  124. value = episode_info.get('value')
  125. if value:
  126. subfile = value[0].get('subfile') or value[0].get('new_subfile')
  127. if subfile and subfile != 'http://www.dramafever.com/st/':
  128. subtitles.setdefault('English', []).append({
  129. 'ext': 'srt',
  130. 'url': subfile,
  131. })
  132. return {
  133. 'id': video_id,
  134. 'title': title,
  135. 'description': description,
  136. 'thumbnail': thumbnail,
  137. 'timestamp': timestamp,
  138. 'duration': duration,
  139. 'formats': formats,
  140. 'subtitles': subtitles,
  141. }
  142. class DramaFeverSeriesIE(DramaFeverBaseIE):
  143. IE_NAME = 'dramafever:series'
  144. _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
  145. _TESTS = [{
  146. 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
  147. 'info_dict': {
  148. 'id': '4512',
  149. 'title': 'Cooking with Shin',
  150. 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
  151. },
  152. 'playlist_count': 4,
  153. }, {
  154. 'url': 'http://www.dramafever.com/drama/124/IRIS/',
  155. 'info_dict': {
  156. 'id': '124',
  157. 'title': 'IRIS',
  158. 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
  159. },
  160. 'playlist_count': 20,
  161. }]
  162. _PAGE_SIZE = 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
  163. def _real_extract(self, url):
  164. series_id = self._match_id(url)
  165. series = self._download_json(
  166. 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
  167. % (self._consumer_secret, series_id),
  168. series_id, 'Downloading series JSON')['series'][series_id]
  169. title = clean_html(series['name'])
  170. description = clean_html(series.get('description') or series.get('description_short'))
  171. entries = []
  172. for page_num in itertools.count(1):
  173. episodes = self._download_json(
  174. 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
  175. % (self._consumer_secret, series_id, self._PAGE_SIZE, page_num),
  176. series_id, 'Downloading episodes JSON page #%d' % page_num)
  177. for episode in episodes.get('value', []):
  178. episode_url = episode.get('episode_url')
  179. if not episode_url:
  180. continue
  181. entries.append(self.url_result(
  182. compat_urlparse.urljoin(url, episode_url),
  183. 'DramaFever', episode.get('guid')))
  184. if page_num == episodes['num_pages']:
  185. break
  186. return self.playlist_result(entries, series_id, title, description)