2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
22 class DramaFeverBaseIE(InfoExtractor
):
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
= sanitized_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 def _real_extract(self
, url
):
87 video_id
= self
._match
_id
(url
).replace('/', '.')
90 feed
= self
._download
_json
(
91 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id
,
92 video_id
, 'Downloading episode JSON')['channel']['item']
93 except ExtractorError
as e
:
94 if isinstance(e
.cause
, compat_HTTPError
):
96 'Currently unavailable in your country.', expected
=True)
99 media_group
= feed
.get('media-group', {})
102 for media_content
in media_group
['media-content']:
103 src
= media_content
.get('@attributes', {}).get('url')
106 ext
= determine_ext(src
)
108 formats
.extend(self
._extract
_f
4m
_formats
(
109 src
, video_id
, f4m_id
='hds'))
111 formats
.extend(self
._extract
_m
3u8_formats
(
112 src
, video_id
, 'mp4', m3u8_id
='hls'))
117 self
._sort
_formats
(formats
)
119 title
= media_group
.get('media-title')
120 description
= media_group
.get('media-description')
121 duration
= int_or_none(media_group
['media-content'][0].get('@attributes', {}).get('duration'))
122 thumbnail
= self
._proto
_relative
_url
(
123 media_group
.get('media-thumbnail', {}).get('@attributes', {}
).get('url'))
124 timestamp
= parse_iso8601(feed
.get('pubDate'), ' ')
127 for media_subtitle
in media_group
.get('media-subTitle', []):
128 lang
= media_subtitle
.get('@attributes', {}).get('lang')
129 href
= media_subtitle
.get('@attributes', {}).get('href')
130 if not lang
or not href
:
137 series_id
, episode_number
= video_id
.split('.')
138 episode_info
= self
._download
_json
(
139 # We only need a single episode info, so restricting page size to one episode
140 # and dealing with page number as with episode number
141 r
'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
142 % (self
._consumer
_secret
, series_id
, episode_number
),
143 video_id
, 'Downloading episode info JSON', fatal
=False)
145 value
= episode_info
.get('value')
147 subfile
= value
[0].get('subfile') or value
[0].get('new_subfile')
148 if subfile
and subfile
!= 'http://www.dramafever.com/st/':
149 subtitles
.setdefault('English', []).append({
157 'description': description
,
158 'thumbnail': thumbnail
,
159 'timestamp': timestamp
,
160 'duration': duration
,
162 'subtitles': subtitles
,
166 class DramaFeverSeriesIE(DramaFeverBaseIE
):
167 IE_NAME
= 'dramafever:series'
168 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
170 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
173 'title': 'Cooking with Shin',
174 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
178 'url': 'http://www.dramafever.com/drama/124/IRIS/',
182 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
184 'playlist_count': 20,
187 _PAGE_SIZE
= 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
189 def _real_extract(self
, url
):
190 series_id
= self
._match
_id
(url
)
192 series
= self
._download
_json
(
193 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
194 % (self
._consumer
_secret
, series_id
),
195 series_id
, 'Downloading series JSON')['series'][series_id
]
197 title
= clean_html(series
['name'])
198 description
= clean_html(series
.get('description') or series
.get('description_short'))
201 for page_num
in itertools
.count(1):
202 episodes
= self
._download
_json
(
203 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
204 % (self
._consumer
_secret
, series_id
, self
._PAGE
_SIZE
, page_num
),
205 series_id
, 'Downloading episodes JSON page #%d' % page_num
)
206 for episode
in episodes
.get('value', []):
207 episode_url
= episode
.get('episode_url')
210 entries
.append(self
.url_result(
211 compat_urlparse
.urljoin(url
, episode_url
),
212 'DramaFever', episode
.get('guid')))
213 if page_num
== episodes
['num_pages']:
216 return self
.playlist_result(entries
, series_id
, title
, description
)