2 from __future__ import unicode_literals
6 from .common import InfoExtractor
20 class DramaFeverIE(InfoExtractor):
21 IE_NAME = 'dramafever'
22 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+/[0-9]+)'
24 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
28 'title': 'Cooking with Shin 4512.1',
29 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
30 'thumbnail': 're:^https?://.*\.jpg',
31 'timestamp': 1404336058,
32 'upload_date': '20140702',
37 def _real_extract(self, url):
38 video_id = self._match_id(url).replace('/', '.')
41 feed = self._download_json(
42 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id,
43 video_id, 'Downloading episode JSON')['channel']['item']
44 except ExtractorError as e:
45 if isinstance(e.cause, compat_HTTPError):
47 'Currently unavailable in your country.', expected=True)
50 media_group = feed.get('media-group', {})
53 for media_content in media_group['media-content']:
54 src = media_content.get('@attributes', {}).get('url')
57 ext = determine_ext(src)
59 formats.extend(self._extract_f4m_formats(
60 src, video_id, f4m_id='hds'))
62 formats.extend(self._extract_m3u8_formats(
63 src, video_id, 'mp4', m3u8_id='hls'))
68 self._sort_formats(formats)
70 title = media_group.get('media-title')
71 description = media_group.get('media-description')
72 duration = int_or_none(media_group['media-content'][0].get('@attributes', {}).get('duration'))
73 thumbnail = self._proto_relative_url(
74 media_group.get('media-thumbnail', {}).get('@attributes', {}).get('url'))
75 timestamp = parse_iso8601(feed.get('pubDate'), ' ')
78 for media_subtitle in media_group.get('media-subTitle', []):
79 lang = media_subtitle.get('@attributes', {}).get('lang')
80 href = media_subtitle.get('@attributes', {}).get('href')
81 if not lang or not href:
91 'description': description,
92 'thumbnail': thumbnail,
93 'timestamp': timestamp,
96 'subtitles': subtitles,
100 class DramaFeverSeriesIE(InfoExtractor):
101 IE_NAME = 'dramafever:series'
102 _VALID_URL = r'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
104 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
107 'title': 'Cooking with Shin',
108 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
112 'url': 'http://www.dramafever.com/drama/124/IRIS/',
116 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
118 'playlist_count': 20,
121 _CONSUMER_SECRET = 'DA59dtVXYLxajktV'
122 _PAGE_SIZE = 5 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
124 def _get_consumer_secret(self, video_id):
125 mainjs = self._download_webpage(
126 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
127 video_id, 'Downloading main.js', fatal=False)
129 return self._CONSUMER_SECRET
130 return self._search_regex(
131 r"var\s+cs\s*=\s*'([^']+)'", mainjs,
132 'consumer secret', default=self._CONSUMER_SECRET)
134 def _real_extract(self, url):
135 series_id = self._match_id(url)
137 consumer_secret = self._get_consumer_secret(series_id)
139 series = self._download_json(
140 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
141 % (consumer_secret, series_id),
142 series_id, 'Downloading series JSON')['series'][series_id]
144 title = clean_html(series['name'])
145 description = clean_html(series.get('description') or series.get('description_short'))
148 for page_num in itertools.count(1):
149 episodes = self._download_json(
150 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
151 % (consumer_secret, series_id, self._PAGE_SIZE, page_num),
152 series_id, 'Downloading episodes JSON page #%d' % page_num)
153 for episode in episodes.get('value', []):
154 entries.append(self.url_result(
155 compat_urlparse.urljoin(url, episode['episode_url']),
156 'DramaFever', episode.get('guid')))
157 if page_num == episodes['num_pages']:
160 return self.playlist_result(entries, series_id, title, description)