2 from __future__ import unicode_literals
19 class DramaFeverBaseIE(AMPIE):
20 _LOGIN_URL = 'https://www.dramafever.com/accounts/login/'
21 _NETRC_MACHINE = 'dramafever'
23 _CONSUMER_SECRET = 'DA59dtVXYLxajktV'
25 _consumer_secret = None
27 def _get_consumer_secret(self):
28 mainjs = self._download_webpage(
29 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
30 None, 'Downloading main.js', fatal=False)
32 return self._CONSUMER_SECRET
33 return self._search_regex(
34 r"var\s+cs\s*=\s*'([^']+)'", mainjs,
35 'consumer secret', default=self._CONSUMER_SECRET)
37 def _real_initialize(self):
39 self._consumer_secret = self._get_consumer_secret()
42 (username, password) = self._get_login_info()
51 request = sanitized_Request(
52 self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
53 response = self._download_webpage(
54 request, None, 'Logging in as %s' % username)
56 if all(logout_pattern not in response
57 for logout_pattern in ['href="/accounts/logout/"', '>Log out<']):
58 error = self._html_search_regex(
59 r'(?s)class="hidden-xs prompt"[^>]*>(.+?)<',
60 response, 'error message', default=None)
62 raise ExtractorError('Unable to login: %s' % error, expected=True)
63 raise ExtractorError('Unable to log in')
66 class DramaFeverIE(DramaFeverBaseIE):
67 IE_NAME = 'dramafever'
68 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
70 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
74 'title': 'Cooking with Shin 4512.1',
75 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
76 'thumbnail': 're:^https?://.*\.jpg',
77 'timestamp': 1404336058,
78 'upload_date': '20140702',
83 'skip_download': True,
87 def _real_extract(self, url):
88 video_id = self._match_id(url).replace('/', '.')
91 info = self._extract_feed_info(
92 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id)
93 except ExtractorError as e:
94 if isinstance(e.cause, compat_HTTPError):
96 'Currently unavailable in your country.', expected=True)
99 series_id, episode_number = video_id.split('.')
100 episode_info = self._download_json(
101 # We only need a single episode info, so restricting page size to one episode
102 # and dealing with page number as with episode number
103 r'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
104 % (self._consumer_secret, series_id, episode_number),
105 video_id, 'Downloading episode info JSON', fatal=False)
107 value = episode_info.get('value')
109 subfile = value[0].get('subfile') or value[0].get('new_subfile')
110 if subfile and subfile != 'http://www.dramafever.com/st/':
111 info.setdefault('subtitles', {}).setdefault('English', []).append({
119 class DramaFeverSeriesIE(DramaFeverBaseIE):
120 IE_NAME = 'dramafever:series'
121 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
123 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
126 'title': 'Cooking with Shin',
127 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
131 'url': 'http://www.dramafever.com/drama/124/IRIS/',
135 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
137 'playlist_count': 20,
140 _PAGE_SIZE = 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
142 def _real_extract(self, url):
143 series_id = self._match_id(url)
145 series = self._download_json(
146 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
147 % (self._consumer_secret, series_id),
148 series_id, 'Downloading series JSON')['series'][series_id]
150 title = clean_html(series['name'])
151 description = clean_html(series.get('description') or series.get('description_short'))
154 for page_num in itertools.count(1):
155 episodes = self._download_json(
156 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
157 % (self._consumer_secret, series_id, self._PAGE_SIZE, page_num),
158 series_id, 'Downloading episodes JSON page #%d' % page_num)
159 for episode in episodes.get('value', []):
160 episode_url = episode.get('episode_url')
163 entries.append(self.url_result(
164 compat_urlparse.urljoin(url, episode_url),
165 'DramaFever', episode.get('guid')))
166 if page_num == episodes['num_pages']:
169 return self.playlist_result(entries, series_id, title, description)