2 from __future__ import unicode_literals
10 compat_urllib_request,
22 class DramaFeverBaseIE(AMPIE):
23 _LOGIN_URL = 'https://www.dramafever.com/accounts/login/'
24 _NETRC_MACHINE = 'dramafever'
26 _CONSUMER_SECRET = 'DA59dtVXYLxajktV'
28 _consumer_secret = None
30 def _get_consumer_secret(self):
31 mainjs = self._download_webpage(
32 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
33 None, 'Downloading main.js', fatal=False)
35 return self._CONSUMER_SECRET
36 return self._search_regex(
37 r"var\s+cs\s*=\s*'([^']+)'", mainjs,
38 'consumer secret', default=self._CONSUMER_SECRET)
40 def _real_initialize(self):
42 self._consumer_secret = self._get_consumer_secret()
45 (username, password) = self._get_login_info()
54 request = compat_urllib_request.Request(
55 self._LOGIN_URL, compat_urllib_parse.urlencode(login_form).encode('utf-8'))
56 response = self._download_webpage(
57 request, None, 'Logging in as %s' % username)
59 if all(logout_pattern not in response
60 for logout_pattern in ['href="/accounts/logout/"', '>Log out<']):
61 error = self._html_search_regex(
62 r'(?s)class="hidden-xs prompt"[^>]*>(.+?)<',
63 response, 'error message', default=None)
65 raise ExtractorError('Unable to login: %s' % error, expected=True)
66 raise ExtractorError('Unable to log in')
69 class DramaFeverIE(DramaFeverBaseIE):
70 IE_NAME = 'dramafever'
71 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
73 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
77 'title': 'Cooking with Shin 4512.1',
78 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
79 'thumbnail': 're:^https?://.*\.jpg',
80 'timestamp': 1404336058,
81 'upload_date': '20140702',
86 'skip_download': True,
90 def _real_extract(self, url):
91 video_id = self._match_id(url).replace('/', '.')
94 info = self._extract_feed_info('http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id)
95 except ExtractorError as e:
96 if isinstance(e.cause, compat_HTTPError):
98 'Currently unavailable in your country.', expected=True)
101 series_id, episode_number = video_id.split('.')
102 episode_info = self._download_json(
103 # We only need a single episode info, so restricting page size to one episode
104 # and dealing with page number as with episode number
105 r'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
106 % (self._consumer_secret, series_id, episode_number),
107 video_id, 'Downloading episode info JSON', fatal=False)
109 value = episode_info.get('value')
111 subfile = value[0].get('subfile') or value[0].get('new_subfile')
112 if subfile and subfile != 'http://www.dramafever.com/st/':
113 info['subtitiles'].setdefault('English', []).append({
121 class DramaFeverSeriesIE(DramaFeverBaseIE):
122 IE_NAME = 'dramafever:series'
123 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
125 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
128 'title': 'Cooking with Shin',
129 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
133 'url': 'http://www.dramafever.com/drama/124/IRIS/',
137 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
139 'playlist_count': 20,
142 _PAGE_SIZE = 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
144 def _real_extract(self, url):
145 series_id = self._match_id(url)
147 series = self._download_json(
148 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
149 % (self._consumer_secret, series_id),
150 series_id, 'Downloading series JSON')['series'][series_id]
152 title = clean_html(series['name'])
153 description = clean_html(series.get('description') or series.get('description_short'))
156 for page_num in itertools.count(1):
157 episodes = self._download_json(
158 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
159 % (self._consumer_secret, series_id, self._PAGE_SIZE, page_num),
160 series_id, 'Downloading episodes JSON page #%d' % page_num)
161 for episode in episodes.get('value', []):
162 episode_url = episode.get('episode_url')
165 entries.append(self.url_result(
166 compat_urlparse.urljoin(url, episode_url),
167 'DramaFever', episode.get('guid')))
168 if page_num == episodes['num_pages']:
171 return self.playlist_result(entries, series_id, title, description)