2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
10 compat_urllib_request
,
22 class DramaFeverBaseIE(InfoExtractor
):
23 _LOGIN_URL
= 'https://www.dramafever.com/accounts/login/'
24 _NETRC_MACHINE
= 'dramafever'
26 def _real_initialize(self
):
30 (username
, password
) = self
._get
_login
_info
()
39 request
= compat_urllib_request
.Request(
40 self
._LOGIN
_URL
, compat_urllib_parse
.urlencode(login_form
).encode('utf-8'))
41 response
= self
._download
_webpage
(
42 request
, None, 'Logging in as %s' % username
)
44 if all(logout_pattern
not in response
45 for logout_pattern
in ['href="/accounts/logout/"', '>Log out<']):
46 error
= self
._html
_search
_regex
(
47 r
'(?s)class="hidden-xs prompt"[^>]*>(.+?)<',
48 response
, 'error message', default
=None)
50 raise ExtractorError('Unable to login: %s' % error
, expected
=True)
51 raise ExtractorError('Unable to log in')
54 class DramaFeverIE(DramaFeverBaseIE
):
55 IE_NAME
= 'dramafever'
56 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
58 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
62 'title': 'Cooking with Shin 4512.1',
63 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
64 'thumbnail': 're:^https?://.*\.jpg',
65 'timestamp': 1404336058,
66 'upload_date': '20140702',
71 def _real_extract(self
, url
):
72 video_id
= self
._match
_id
(url
).replace('/', '.')
75 feed
= self
._download
_json
(
76 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id
,
77 video_id
, 'Downloading episode JSON')['channel']['item']
78 except ExtractorError
as e
:
79 if isinstance(e
.cause
, compat_HTTPError
):
81 'Currently unavailable in your country.', expected
=True)
84 media_group
= feed
.get('media-group', {})
87 for media_content
in media_group
['media-content']:
88 src
= media_content
.get('@attributes', {}).get('url')
91 ext
= determine_ext(src
)
93 formats
.extend(self
._extract
_f
4m
_formats
(
94 src
, video_id
, f4m_id
='hds'))
96 formats
.extend(self
._extract
_m
3u8_formats
(
97 src
, video_id
, 'mp4', m3u8_id
='hls'))
102 self
._sort
_formats
(formats
)
104 title
= media_group
.get('media-title')
105 description
= media_group
.get('media-description')
106 duration
= int_or_none(media_group
['media-content'][0].get('@attributes', {}).get('duration'))
107 thumbnail
= self
._proto
_relative
_url
(
108 media_group
.get('media-thumbnail', {}).get('@attributes', {}
).get('url'))
109 timestamp
= parse_iso8601(feed
.get('pubDate'), ' ')
112 for media_subtitle
in media_group
.get('media-subTitle', []):
113 lang
= media_subtitle
.get('@attributes', {}).get('lang')
114 href
= media_subtitle
.get('@attributes', {}).get('href')
115 if not lang
or not href
:
125 'description': description
,
126 'thumbnail': thumbnail
,
127 'timestamp': timestamp
,
128 'duration': duration
,
130 'subtitles': subtitles
,
134 class DramaFeverSeriesIE(DramaFeverBaseIE
):
135 IE_NAME
= 'dramafever:series'
136 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
138 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
141 'title': 'Cooking with Shin',
142 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
146 'url': 'http://www.dramafever.com/drama/124/IRIS/',
150 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
152 'playlist_count': 20,
155 _CONSUMER_SECRET
= 'DA59dtVXYLxajktV'
156 _PAGE_SIZE
= 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
158 def _get_consumer_secret(self
, video_id
):
159 mainjs
= self
._download
_webpage
(
160 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
161 video_id
, 'Downloading main.js', fatal
=False)
163 return self
._CONSUMER
_SECRET
164 return self
._search
_regex
(
165 r
"var\s+cs\s*=\s*'([^']+)'", mainjs
,
166 'consumer secret', default
=self
._CONSUMER
_SECRET
)
168 def _real_extract(self
, url
):
169 series_id
= self
._match
_id
(url
)
171 consumer_secret
= self
._get
_consumer
_secret
(series_id
)
173 series
= self
._download
_json
(
174 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
175 % (consumer_secret
, series_id
),
176 series_id
, 'Downloading series JSON')['series'][series_id
]
178 title
= clean_html(series
['name'])
179 description
= clean_html(series
.get('description') or series
.get('description_short'))
182 for page_num
in itertools
.count(1):
183 episodes
= self
._download
_json
(
184 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
185 % (consumer_secret
, series_id
, self
._PAGE
_SIZE
, page_num
),
186 series_id
, 'Downloading episodes JSON page #%d' % page_num
)
187 for episode
in episodes
.get('value', []):
188 episode_url
= episode
.get('episode_url')
191 entries
.append(self
.url_result(
192 compat_urlparse
.urljoin(url
, episode_url
),
193 'DramaFever', episode
.get('guid')))
194 if page_num
== episodes
['num_pages']:
197 return self
.playlist_result(entries
, series_id
, title
, description
)