]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dramafever.py
   2 from __future__ 
import unicode_literals
 
  21 class DramaFeverBaseIE(AMPIE
): 
  22     _LOGIN_URL 
= 'https://www.dramafever.com/accounts/login/' 
  23     _NETRC_MACHINE 
= 'dramafever' 
  24     _GEO_COUNTRIES 
= ['US', 'CA'] 
  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
, urlencode_postdata(login_form
)) 
  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', 
  78             'description': 'md5:a8eec7942e1664a6896fcd5e1287bfd0', 
  79             'episode': 'Episode 1', 
  81             'thumbnail': r
're:^https?://.*\.jpg', 
  82             'timestamp': 1404336058, 
  83             'upload_date': '20140702', 
  88             'skip_download': True, 
  91         'url': 'http://www.dramafever.com/drama/4826/4/Mnet_Asian_Music_Awards_2015/?ap=1', 
  95             'title': 'Mnet Asian Music Awards 2015', 
  96             'description': 'md5:3ff2ee8fedaef86e076791c909cf2e91', 
  97             'episode': 'Mnet Asian Music Awards 2015 - Part 3', 
  99             'thumbnail': r
're:^https?://.*\.jpg', 
 100             'timestamp': 1450213200, 
 101             'upload_date': '20151215', 
 106             'skip_download': True, 
 109         'url': 'https://www.dramafever.com/zh-cn/drama/4972/15/Doctor_Romantic/', 
 110         'only_matching': True, 
 113     def _real_extract(self
, url
): 
 114         video_id 
= self
._match
_id
(url
).replace('/', '.') 
 117             info 
= self
._extract
_feed
_info
( 
 118                 'http://www.dramafever.com/amp/episode/feed.json?guid=%s' % video_id
) 
 119         except ExtractorError 
as e
: 
 120             if isinstance(e
.cause
, compat_HTTPError
): 
 121                 self
.raise_geo_restricted( 
 122                     msg
='Currently unavailable in your country', 
 123                     countries
=self
._GEO
_COUNTRIES
) 
 126         # title is postfixed with video id for some reason, removing 
 127         if info
.get('title'): 
 128             info
['title'] = remove_end(info
['title'], video_id
).strip() 
 130         series_id
, episode_number 
= video_id
.split('.') 
 131         episode_info 
= self
._download
_json
( 
 132             # We only need a single episode info, so restricting page size to one episode 
 133             # and dealing with page number as with episode number 
 134             r
'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1' 
 135             % (self
._consumer
_secret
, series_id
, episode_number
), 
 136             video_id
, 'Downloading episode info JSON', fatal
=False) 
 138             value 
= episode_info
.get('value') 
 139             if isinstance(value
, list): 
 141                     if v
.get('type') == 'Episode': 
 142                         subfile 
= v
.get('subfile') or v
.get('new_subfile') 
 143                         if subfile 
and subfile 
!= 'http://www.dramafever.com/st/': 
 144                             info
.setdefault('subtitles', {}).setdefault('English', []).append({ 
 148                         episode_number 
= int_or_none(v
.get('number')) 
 149                         episode_fallback 
= 'Episode' 
 151                             episode_fallback 
+= ' %d' % episode_number
 
 152                         info
['episode'] = v
.get('title') or episode_fallback
 
 153                         info
['episode_number'] = episode_number
 
 159 class DramaFeverSeriesIE(DramaFeverBaseIE
): 
 160     IE_NAME 
= 'dramafever:series' 
 161     _VALID_URL 
= r
'https?://(?:www\.)?dramafever\.com/(?:[^/]+/)?drama/(?P<id>[0-9]+)(?:/(?:(?!\d+(?:/|$)).+)?)?$' 
 163         'url': 'http://www.dramafever.com/drama/4512/Cooking_with_Shin/', 
 166             'title': 'Cooking with Shin', 
 167             'description': 'md5:84a3f26e3cdc3fb7f500211b3593b5c1', 
 171         'url': 'http://www.dramafever.com/drama/124/IRIS/', 
 175             'description': 'md5:b3a30e587cf20c59bd1c01ec0ee1b862', 
 177         'playlist_count': 20, 
 180     _PAGE_SIZE 
= 60  # max is 60 (see http://api.drama9.com/#get--api-4-episode-series-) 
 182     def _real_extract(self
, url
): 
 183         series_id 
= self
._match
_id
(url
) 
 185         series 
= self
._download
_json
( 
 186             'http://www.dramafever.com/api/4/series/query/?cs=%s&series_id=%s' 
 187             % (self
._consumer
_secret
, series_id
), 
 188             series_id
, 'Downloading series JSON')['series'][series_id
] 
 190         title 
= clean_html(series
['name']) 
 191         description 
= clean_html(series
.get('description') or series
.get('description_short')) 
 194         for page_num 
in itertools
.count(1): 
 195             episodes 
= self
._download
_json
( 
 196                 'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_size=%d&page_number=%d' 
 197                 % (self
._consumer
_secret
, series_id
, self
._PAGE
_SIZE
, page_num
), 
 198                 series_id
, 'Downloading episodes JSON page #%d' % page_num
) 
 199             for episode 
in episodes
.get('value', []): 
 200                 episode_url 
= episode
.get('episode_url') 
 203                 entries
.append(self
.url_result( 
 204                     compat_urlparse
.urljoin(url
, episode_url
), 
 205                     'DramaFever', episode
.get('guid'))) 
 206             if page_num 
== episodes
['num_pages']: 
 209         return self
.playlist_result(entries
, series_id
, title
, description
)