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')
108 if isinstance(value, list):
110 if v.get('type') == 'Episode':
111 subfile = v.get('subfile') or v.get('new_subfile')
112 if subfile and subfile != 'http://www.dramafever.com/st/':
113 info.setdefault('subtitles', {}).setdefault('English', []).append({
122 class DramaFeverSeriesIE(DramaFeverBaseIE):
123 IE_NAME = 'dramafever:series'
124 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
126 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
129 'title': 'Cooking with Shin',
130 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
134 'url': 'http://www.dramafever.com/drama/124/IRIS/',
138 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
140 'playlist_count': 20,
143 _PAGE_SIZE = 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
145 def _real_extract(self, url):
146 series_id = self._match_id(url)
148 series = self._download_json(
149 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
150 % (self._consumer_secret, series_id),
151 series_id, 'Downloading series JSON')['series'][series_id]
153 title = clean_html(series['name'])
154 description = clean_html(series.get('description') or series.get('description_short'))
157 for page_num in itertools.count(1):
158 episodes = self._download_json(
159 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
160 % (self._consumer_secret, series_id, self._PAGE_SIZE, page_num),
161 series_id, 'Downloading episodes JSON page #%d' % page_num)
162 for episode in episodes.get('value', []):
163 episode_url = episode.get('episode_url')
166 entries.append(self.url_result(
167 compat_urlparse.urljoin(url, episode_url),
168 'DramaFever', episode.get('guid')))
169 if page_num == episodes['num_pages']:
172 return self.playlist_result(entries, series_id, title, description)