]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dramafever.py
3b6529f4b108052e3019c8e400bbc2cd0eb5a9a1
2 from __future__
import unicode_literals
20 class DramaFeverBaseIE(AMPIE
):
21 _LOGIN_URL
= 'https://www.dramafever.com/accounts/login/'
22 _NETRC_MACHINE
= 'dramafever'
24 _CONSUMER_SECRET
= 'DA59dtVXYLxajktV'
26 _consumer_secret
= None
28 def _get_consumer_secret(self
):
29 mainjs
= self
._download
_webpage
(
30 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
31 None, 'Downloading main.js', fatal
=False)
33 return self
._CONSUMER
_SECRET
34 return self
._search
_regex
(
35 r
"var\s+cs\s*=\s*'([^']+)'", mainjs
,
36 'consumer secret', default
=self
._CONSUMER
_SECRET
)
38 def _real_initialize(self
):
40 self
._consumer
_secret
= self
._get
_consumer
_secret
()
43 (username
, password
) = self
._get
_login
_info
()
52 request
= sanitized_Request(
53 self
._LOGIN
_URL
, urlencode_postdata(login_form
))
54 response
= self
._download
_webpage
(
55 request
, None, 'Logging in as %s' % username
)
57 if all(logout_pattern
not in response
58 for logout_pattern
in ['href="/accounts/logout/"', '>Log out<']):
59 error
= self
._html
_search
_regex
(
60 r
'(?s)class="hidden-xs prompt"[^>]*>(.+?)<',
61 response
, 'error message', default
=None)
63 raise ExtractorError('Unable to login: %s' % error
, expected
=True)
64 raise ExtractorError('Unable to log in')
67 class DramaFeverIE(DramaFeverBaseIE
):
68 IE_NAME
= 'dramafever'
69 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
71 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
75 'title': 'Cooking with Shin 4512.1',
76 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
77 'episode': 'Episode 1',
79 'thumbnail': 're:^https?://.*\.jpg',
80 'timestamp': 1404336058,
81 'upload_date': '20140702',
86 'skip_download': True,
89 'url': 'http://www.dramafever.com/drama/4826/4/Mnet_Asian_Music_Awards_2015/?ap=1',
93 'title': 'Mnet Asian Music Awards 2015 4826.4',
94 'description': 'md5:3ff2ee8fedaef86e076791c909cf2e91',
95 'episode': 'Mnet Asian Music Awards 2015 - Part 3',
97 'thumbnail': 're:^https?://.*\.jpg',
98 'timestamp': 1450213200,
99 'upload_date': '20151215',
104 'skip_download': True,
108 def _real_extract(self
, url
):
109 video_id
= self
._match
_id
(url
).replace('/', '.')
112 info
= self
._extract
_feed
_info
(
113 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id
)
114 except ExtractorError
as e
:
115 if isinstance(e
.cause
, compat_HTTPError
):
116 raise ExtractorError(
117 'Currently unavailable in your country.', expected
=True)
120 series_id
, episode_number
= video_id
.split('.')
121 episode_info
= self
._download
_json
(
122 # We only need a single episode info, so restricting page size to one episode
123 # and dealing with page number as with episode number
124 r
'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
125 % (self
._consumer
_secret
, series_id
, episode_number
),
126 video_id
, 'Downloading episode info JSON', fatal
=False)
128 value
= episode_info
.get('value')
129 if isinstance(value
, list):
131 if v
.get('type') == 'Episode':
132 subfile
= v
.get('subfile') or v
.get('new_subfile')
133 if subfile
and subfile
!= 'http://www.dramafever.com/st/':
134 info
.setdefault('subtitles', {}).setdefault('English', []).append({
138 episode_number
= int_or_none(v
.get('number'))
139 episode_fallback
= 'Episode'
141 episode_fallback
+= ' %d' % episode_number
142 info
['episode'] = v
.get('title') or episode_fallback
143 info
['episode_number'] = episode_number
149 class DramaFeverSeriesIE(DramaFeverBaseIE
):
150 IE_NAME
= 'dramafever:series'
151 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
153 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
156 'title': 'Cooking with Shin',
157 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
161 'url': 'http://www.dramafever.com/drama/124/IRIS/',
165 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
167 'playlist_count': 20,
170 _PAGE_SIZE
= 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
172 def _real_extract(self
, url
):
173 series_id
= self
._match
_id
(url
)
175 series
= self
._download
_json
(
176 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
177 % (self
._consumer
_secret
, series_id
),
178 series_id
, 'Downloading series JSON')['series'][series_id
]
180 title
= clean_html(series
['name'])
181 description
= clean_html(series
.get('description') or series
.get('description_short'))
184 for page_num
in itertools
.count(1):
185 episodes
= self
._download
_json
(
186 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
187 % (self
._consumer
_secret
, series_id
, self
._PAGE
_SIZE
, page_num
),
188 series_id
, 'Downloading episodes JSON page #%d' % page_num
)
189 for episode
in episodes
.get('value', []):
190 episode_url
= episode
.get('episode_url')
193 entries
.append(self
.url_result(
194 compat_urlparse
.urljoin(url
, episode_url
),
195 'DramaFever', episode
.get('guid')))
196 if page_num
== episodes
['num_pages']:
199 return self
.playlist_result(entries
, series_id
, title
, description
)