]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dramafever.py
e7abc888988e9807ee46abc4d4e44f8276b9a084
2 from __future__
import unicode_literals
20 class DramaFeverBaseIE(AMPIE
):
21 _LOGIN_URL
= 'https://www.dramafever.com/accounts/login/'
22 _NETRC_MACHINE
= 'dramafever'
23 _GEO_COUNTRIES
= ['US', 'CA']
25 _CONSUMER_SECRET
= 'DA59dtVXYLxajktV'
27 _consumer_secret
= None
29 def _get_consumer_secret(self
):
30 mainjs
= self
._download
_webpage
(
31 'http://www.dramafever.com/static/51afe95/df2014/scripts/main.js',
32 None, 'Downloading main.js', fatal
=False)
34 return self
._CONSUMER
_SECRET
35 return self
._search
_regex
(
36 r
"var\s+cs\s*=\s*'([^']+)'", mainjs
,
37 'consumer secret', default
=self
._CONSUMER
_SECRET
)
39 def _real_initialize(self
):
41 self
._consumer
_secret
= self
._get
_consumer
_secret
()
44 (username
, password
) = self
._get
_login
_info
()
53 request
= sanitized_Request(
54 self
._LOGIN
_URL
, urlencode_postdata(login_form
))
55 response
= self
._download
_webpage
(
56 request
, None, 'Logging in as %s' % username
)
58 if all(logout_pattern
not in response
59 for logout_pattern
in ['href="/accounts/logout/"', '>Log out<']):
60 error
= self
._html
_search
_regex
(
61 r
'(?s)class="hidden-xs prompt"[^>]*>(.+?)<',
62 response
, 'error message', default
=None)
64 raise ExtractorError('Unable to login: %s' % error
, expected
=True)
65 raise ExtractorError('Unable to log in')
68 class DramaFeverIE(DramaFeverBaseIE
):
69 IE_NAME
= 'dramafever'
70 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/(?:[^/]+/)?drama/(?P<id>[0-9]+/[0-9]+)(?:/|$)'
72 'url': 'http://www.dramafever.com/drama/4512/1/Cooking_with_Shin/',
76 'title': 'Cooking with Shin 4512.1',
77 'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0',
78 'episode': 'Episode 1',
80 'thumbnail': r
're:^https?://.*\.jpg',
81 'timestamp': 1404336058,
82 'upload_date': '20140702',
87 'skip_download': True,
90 'url': 'http://www.dramafever.com/drama/4826/4/Mnet_Asian_Music_Awards_2015/?ap=1',
94 'title': 'Mnet Asian Music Awards 2015 4826.4',
95 'description': 'md5:3ff2ee8fedaef86e076791c909cf2e91',
96 'episode': 'Mnet Asian Music Awards 2015 - Part 3',
98 'thumbnail': r
're:^https?://.*\.jpg',
99 'timestamp': 1450213200,
100 'upload_date': '20151215',
105 'skip_download': True,
108 'url': 'https://www.dramafever.com/zh-cn/drama/4972/15/Doctor_Romantic/',
109 'only_matching': True,
112 def _real_extract(self
, url
):
113 video_id
= self
._match
_id
(url
).replace('/', '.')
116 info
= self
._extract
_feed
_info
(
117 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id
)
118 except ExtractorError
as e
:
119 if isinstance(e
.cause
, compat_HTTPError
):
120 self
.raise_geo_restricted(
121 msg
='Currently unavailable in your country',
122 countries
=self
._GEO
_COUNTRIES
)
125 series_id
, episode_number
= video_id
.split('.')
126 episode_info
= self
._download
_json
(
127 # We only need a single episode info, so restricting page size to one episode
128 # and dealing with page number as with episode number
129 r
'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
130 % (self
._consumer
_secret
, series_id
, episode_number
),
131 video_id
, 'Downloading episode info JSON', fatal
=False)
133 value
= episode_info
.get('value')
134 if isinstance(value
, list):
136 if v
.get('type') == 'Episode':
137 subfile
= v
.get('subfile') or v
.get('new_subfile')
138 if subfile
and subfile
!= 'http://www.dramafever.com/st/':
139 info
.setdefault('subtitles', {}).setdefault('English', []).append({
143 episode_number
= int_or_none(v
.get('number'))
144 episode_fallback
= 'Episode'
146 episode_fallback
+= ' %d' % episode_number
147 info
['episode'] = v
.get('title') or episode_fallback
148 info
['episode_number'] = episode_number
154 class DramaFeverSeriesIE(DramaFeverBaseIE
):
155 IE_NAME
= 'dramafever:series'
156 _VALID_URL
= r
'https?://(?:www\.)?dramafever\.com/(?:[^/]+/)?drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$'
158 'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/',
161 'title': 'Cooking with Shin',
162 'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1',
166 'url': 'http://www.dramafever.com/drama/124/IRIS/',
170 'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862',
172 'playlist_count': 20,
175 _PAGE_SIZE
= 60 # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-)
177 def _real_extract(self
, url
):
178 series_id
= self
._match
_id
(url
)
180 series
= self
._download
_json
(
181 'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s'
182 % (self
._consumer
_secret
, series_id
),
183 series_id
, 'Downloading series JSON')['series'][series_id
]
185 title
= clean_html(series
['name'])
186 description
= clean_html(series
.get('description') or series
.get('description_short'))
189 for page_num
in itertools
.count(1):
190 episodes
= self
._download
_json
(
191 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d'
192 % (self
._consumer
_secret
, series_id
, self
._PAGE
_SIZE
, page_num
),
193 series_id
, 'Downloading episodes JSON page #%d' % page_num
)
194 for episode
in episodes
.get('value', []):
195 episode_url
= episode
.get('episode_url')
198 entries
.append(self
.url_result(
199 compat_urlparse
.urljoin(url
, episode_url
),
200 'DramaFever', episode
.get('guid')))
201 if page_num
== episodes
['num_pages']:
204 return self
.playlist_result(entries
, series_id
, title
, description
)