]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/animeondemand.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from ..compat 
import compat_urlparse
 
  16 class AnimeOnDemandIE(InfoExtractor
): 
  17     _VALID_URL 
= r
'https?://(?:www\.)?anime-on-demand\.de/anime/(?P<id>\d+)' 
  18     _LOGIN_URL 
= 'https://www.anime-on-demand.de/users/sign_in' 
  19     _APPLY_HTML5_URL 
= 'https://www.anime-on-demand.de/html5apply' 
  20     _NETRC_MACHINE 
= 'animeondemand' 
  22         'url': 'https://www.anime-on-demand.de/anime/161', 
  25             'title': 'Grimgar, Ashes and Illusions (OmU)', 
  26             'description': 'md5:6681ce3c07c7189d255ac6ab23812d31', 
  28         'playlist_mincount': 4, 
  32         (username
, password
) = self
._get
_login
_info
() 
  36         login_page 
= self
._download
_webpage
( 
  37             self
._LOGIN
_URL
, None, 'Downloading login page') 
  39         login_form 
= self
._form
_hidden
_inputs
('new_user', login_page
) 
  42             'user[login]': username
, 
  43             'user[password]': password
, 
  46         post_url 
= self
._search
_regex
( 
  47             r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', login_page, 
  48             'post url
', default=self._LOGIN_URL, group='url
') 
  50         if not post_url.startswith('http
'): 
  51             post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url) 
  53         request = sanitized_Request( 
  54             post_url, urlencode_postdata(encode_dict(login_form))) 
  55         request.add_header('Referer
', self._LOGIN_URL) 
  57         response = self._download_webpage( 
  58             request, None, 'Logging 
in as %s' % username) 
  60         if all(p not in response for p in ('>Logout
<', 'href
="/users/sign_out"')): 
  61             error = self._search_regex( 
  62                 r'<p 
class="alert alert-danger">(.+?
)</p
>', 
  63                 response, 'error
', default=None) 
  65                 raise ExtractorError('Unable to login
: %s' % error, expected=True) 
  66             raise ExtractorError('Unable to log 
in') 
  68     def _real_initialize(self): 
  71     def _real_extract(self, url): 
  72         anime_id = self._match_id(url) 
  74         webpage = self._download_webpage(url, anime_id) 
  76         if 'data
-playlist
=' not in webpage: 
  77             self._download_webpage( 
  78                 self._APPLY_HTML5_URL, anime_id, 
  79                 'Activating HTML5 beta
', 'Unable to 
apply HTML5 beta
') 
  80             webpage = self._download_webpage(url, anime_id) 
  82         csrf_token = self._html_search_meta( 
  83             'csrf
-token
', webpage, 'csrf token
', fatal=True) 
  85         anime_title = self._html_search_regex( 
  86             r'(?s
)<h1
[^
>]+itemprop
="name"[^
>]*>(.+?
)</h1
>', 
  87             webpage, 'anime name
') 
  88         anime_description = self._html_search_regex( 
  89             r'(?s
)<div
[^
>]+itemprop
="description"[^
>]*>(.+?
)</div
>', 
  90             webpage, 'anime description
', default=None) 
  94         for episode_html in re.findall(r'(?s
)<h3
[^
>]+class="episodebox-title".+?
>Episodeninhalt
<', webpage): 
  96                 r'class="episodebox-title"[^
>]+title
="Episode (?P<number>\d+) - (?P<title>.+?)"', episode_html) 
 100             episode_number = int(m.group('number
')) 
 101             episode_title = m.group('title
') 
 102             video_id = 'episode
-%d' % episode_number 
 106                 'series
': anime_title, 
 107                 'episode
': episode_title, 
 108                 'episode_number
': episode_number, 
 113             playlist_url = self._search_regex( 
 114                 r'data
-playlist
=(["\'])(?P<url>.+?)\1', 
 115                 episode_html, 'data playlist', default=None, group='url') 
 117                 request = sanitized_Request( 
 118                     compat_urlparse.urljoin(url, playlist_url), 
 120                         'X-Requested-With': 'XMLHttpRequest', 
 121                         'X-CSRF-Token': csrf_token, 
 123                         'Accept': 'application/json, text/javascript, */*; q=0.01', 
 126                 playlist = self._download_json( 
 127                     request, video_id, 'Downloading playlist JSON', fatal=False) 
 129                     playlist = playlist['playlist'][0] 
 130                     title = playlist['title'] 
 131                     description = playlist.get('description') 
 132                     for source in playlist.get('sources', []): 
 133                         file_ = source.get('file') 
 134                         if file_ and determine_ext(file_) == 'm3u8': 
 135                             formats = self._extract_m3u8_formats( 
 136                                 file_, video_id, 'mp4', 
 137                                 entry_protocol='m3u8_native', m3u8_id='hls') 
 140                 f = common_info.copy() 
 143                     'description': description, 
 149                 r'data-dialog-header=(["\'])(?P
<title
>.+?
)\
1[^
>]+href
=(["\'])(?P<href>.+?)\3[^>]*>Teaser<', 
 152                 f = common_info.copy() 
 154                     'id': '%s-teaser' % f['id'], 
 155                     'title': m.group('title'), 
 156                     'url': compat_urlparse.urljoin(url, m.group('href')), 
 160         return self.playlist_result(entries, anime_id, anime_title, anime_description)