1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
6 from ..compat
import compat_str
18 class AnimeOnDemandIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.)?anime-on-demand\.de/anime/(?P<id>\d+)'
20 _LOGIN_URL
= 'https://www.anime-on-demand.de/users/sign_in'
21 _APPLY_HTML5_URL
= 'https://www.anime-on-demand.de/html5apply'
22 _NETRC_MACHINE
= 'animeondemand'
23 # German-speaking countries of Europe
24 _GEO_COUNTRIES
= ['AT', 'CH', 'DE', 'LI', 'LU']
27 'url': 'https://www.anime-on-demand.de/anime/161',
30 'title': 'Grimgar, Ashes and Illusions (OmU)',
31 'description': 'md5:6681ce3c07c7189d255ac6ab23812d31',
33 'playlist_mincount': 4,
35 # Film wording is used instead of Episode, ger/jap, Dub/OmU
36 'url': 'https://www.anime-on-demand.de/anime/39',
37 'only_matching': True,
39 # Episodes without titles, jap, OmU
40 'url': 'https://www.anime-on-demand.de/anime/162',
41 'only_matching': True,
43 # ger/jap, Dub/OmU, account required
44 'url': 'https://www.anime-on-demand.de/anime/169',
45 'only_matching': True,
47 # Full length film, non-series, ger/jap, Dub/OmU, account required
48 'url': 'https://www.anime-on-demand.de/anime/185',
49 'only_matching': True,
52 'url': 'https://www.anime-on-demand.de/anime/12',
53 'only_matching': True,
56 def _perform_login(self
, username
, password
):
57 login_page
= self
._download
_webpage
(
58 self
._LOGIN
_URL
, None, 'Downloading login page')
60 if '>Our licensing terms allow the distribution of animes only to German-speaking countries of Europe' in login_page
:
61 self
.raise_geo_restricted(
62 '%s is only available in German-speaking countries of Europe' % self
.IE_NAME
)
64 login_form
= self
._form
_hidden
_inputs
('new_user', login_page
)
67 'user[login]': username
,
68 'user[password]': password
,
71 post_url
= self
._search
_regex
(
72 r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', login_page,
73 'post url
', default=self._LOGIN_URL, group='url
')
75 if not post_url.startswith('http
'):
76 post_url = urljoin(self._LOGIN_URL, post_url)
78 response = self._download_webpage(
79 post_url, None, 'Logging
in',
80 data=urlencode_postdata(login_form), headers={
81 'Referer
': self._LOGIN_URL,
84 if all(p not in response for p in ('>Logout
<', 'href
="/users/sign_out"')):
85 error = self._search_regex(
86 r'<p
[^
>]+\bclass
=(["\'])(?:(?!\1).)*\balert\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</p>',
87 response, 'error', default=None, group='error')
89 raise ExtractorError('Unable to login: %s' % error, expected=True)
90 raise ExtractorError('Unable to log in')
92 def _real_extract(self, url):
93 anime_id = self._match_id(url)
95 webpage = self._download_webpage(url, anime_id)
97 if 'data-playlist=' not in webpage:
98 self._download_webpage(
99 self._APPLY_HTML5_URL, anime_id,
100 'Activating HTML5 beta', 'Unable to apply HTML5 beta')
101 webpage = self._download_webpage(url, anime_id)
103 csrf_token = self._html_search_meta(
104 'csrf-token', webpage, 'csrf token', fatal=True)
106 anime_title = self._html_search_regex(
107 r'(?s)<h1[^>]+itemprop="name
"[^>]*>(.+?)</h1>',
108 webpage, 'anime name')
109 anime_description = self._html_search_regex(
110 r'(?s)<div[^>]+itemprop="description
"[^>]*>(.+?)</div>',
111 webpage, 'anime description', default=None)
113 def extract_info(html, video_id, num=None):
114 title, description = [None] * 2
117 for input_ in re.findall(
118 r'<input[^>]+class=["\'].*?streamstarter
[^
>]+>', html):
119 attributes = extract_attributes(input_)
120 title = attributes.get('data
-dialog
-header
')
122 for playlist_key in ('data
-playlist
', 'data
-otherplaylist
', 'data
-stream
'):
123 playlist_url = attributes.get(playlist_key)
124 if isinstance(playlist_url, compat_str) and re.match(
125 r'/?
[\da
-zA
-Z
]+', playlist_url):
126 playlist_urls.append(attributes[playlist_key])
127 if not playlist_urls:
130 lang = attributes.get('data
-lang
')
131 lang_note = attributes.get('value
')
133 for playlist_url in playlist_urls:
134 kind = self._search_regex(
135 r'videomaterialurl
/\d
+/([^
/]+)/',
136 playlist_url, 'media kind
', default=None)
137 format_id = join_nonempty(lang, kind) if lang or kind else str(num)
138 format_note = join_nonempty(kind, lang_note, delim=', ')
141 item_id_list.append(format_id)
142 item_id_list.append('videomaterial
')
143 playlist = self._download_json(
144 urljoin(url, playlist_url), video_id,
145 'Downloading
%s JSON
' % ' '.join(item_id_list),
147 'X
-Requested
-With
': 'XMLHttpRequest
',
148 'X
-CSRF
-Token
': csrf_token,
150 'Accept
': 'application
/json
, text
/javascript
, */*; q
=0.01',
154 stream_url = url_or_none(playlist.get('streamurl
'))
157 r'^
(?P
<url
>rtmpe?
://(?P
<host
>[^
/]+)/(?P
<app
>.+/))(?P
<playpath
>mp
[34]:.+)',
161 'url
': rtmp.group('url
'),
162 'app
': rtmp.group('app
'),
163 'play_path
': rtmp.group('playpath
'),
165 'player_url
': 'https
://www
.anime
-on
-demand
.de
/assets
/jwplayer
.flash
-55abfb34080700304d49125ce9ffb4a6
.swf
',
166 'rtmp_real_time
': True,
171 start_video = playlist.get('startvideo
', 0)
172 playlist = playlist.get('playlist
')
173 if not playlist or not isinstance(playlist, list):
175 playlist = playlist[start_video]
176 title = playlist.get('title
')
179 description = playlist.get('description
')
180 for source in playlist.get('sources
', []):
181 file_ = source.get('file')
184 ext = determine_ext(file_)
185 format_id = join_nonempty(
187 'hls
' if ext == 'm3u8
' else None,
188 'dash
' if source.get('type') == 'video
/dash
' or ext == 'mpd
' else None)
190 file_formats = self._extract_m3u8_formats(
191 file_, video_id, 'mp4
',
192 entry_protocol='m3u8_native
', m3u8_id=format_id, fatal=False)
193 elif source.get('type') == 'video
/dash
' or ext == 'mpd
':
195 file_formats = self._extract_mpd_formats(
196 file_, video_id, mpd_id=format_id, fatal=False)
199 for f in file_formats:
202 'format_note
': format_note,
204 formats.extend(file_formats)
208 'description
': description,
212 def extract_entries(html, video_id, common_info, num=None):
213 info = extract_info(html, video_id, num)
216 self._sort_formats(info['formats
'])
217 f = common_info.copy()
221 # Extract teaser/trailer only when full episode is not available
222 if not info['formats
']:
224 r'data
-dialog
-header
=(["\'])(?P<title>.+?)\1[^>]+href=(["\'])(?P
<href
>.+?
)\
3[^
>]*>(?P
<kind
>Teaser|Trailer
)<',
227 f = common_info.copy()
229 'id': '%s-%s' % (f['id'], m.group('kind
').lower()),
230 'title
': m.group('title
'),
231 'url
': urljoin(url, m.group('href
')),
235 def extract_episodes(html):
236 for num, episode_html in enumerate(re.findall(
237 r'(?s
)<h3
[^
>]+class="episodebox-title".+?
>Episodeninhalt
<', html), 1):
238 episodebox_title = self._search_regex(
239 (r'class="episodebox-title"[^
>]+title
=(["\'])(?P<title>.+?)\1',
240 r'class="episodebox
-title
"[^>]+>(?P<title>.+?)<'),
241 episode_html, 'episodebox title', default=None, group='title')
242 if not episodebox_title:
245 episode_number = int(self._search_regex(
246 r'(?:Episode|Film)\s*(\d+)',
247 episodebox_title, 'episode number', default=num))
248 episode_title = self._search_regex(
249 r'(?:Episode|Film)\s*\d+\s*-\s*(.+)',
250 episodebox_title, 'episode title', default=None)
252 video_id = 'episode-%d' % episode_number
256 'series': anime_title,
257 'episode': episode_title,
258 'episode_number': episode_number,
261 for e in extract_entries(episode_html, video_id, common_info):
264 def extract_film(html, video_id):
267 'title': anime_title,
268 'description': anime_description,
270 for e in extract_entries(html, video_id, common_info):
275 for e in extract_episodes(webpage):
280 for e in extract_film(webpage, anime_id):
283 return self.playlist_result(
284 entries(), anime_id, anime_title, anime_description)