3 from .common
import InfoExtractor
4 from ..compat
import compat_str
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'
21 # German-speaking countries of Europe
22 _GEO_COUNTRIES
= ['AT', 'CH', 'DE', 'LI', 'LU']
25 'url': 'https://www.anime-on-demand.de/anime/161',
28 'title': 'Grimgar, Ashes and Illusions (OmU)',
29 'description': 'md5:6681ce3c07c7189d255ac6ab23812d31',
31 'playlist_mincount': 4,
33 # Film wording is used instead of Episode, ger/jap, Dub/OmU
34 'url': 'https://www.anime-on-demand.de/anime/39',
35 'only_matching': True,
37 # Episodes without titles, jap, OmU
38 'url': 'https://www.anime-on-demand.de/anime/162',
39 'only_matching': True,
41 # ger/jap, Dub/OmU, account required
42 'url': 'https://www.anime-on-demand.de/anime/169',
43 'only_matching': True,
45 # Full length film, non-series, ger/jap, Dub/OmU, account required
46 'url': 'https://www.anime-on-demand.de/anime/185',
47 'only_matching': True,
50 'url': 'https://www.anime-on-demand.de/anime/12',
51 'only_matching': True,
54 def _perform_login(self
, username
, password
):
55 login_page
= self
._download
_webpage
(
56 self
._LOGIN
_URL
, None, 'Downloading login page')
58 if '>Our licensing terms allow the distribution of animes only to German-speaking countries of Europe' in login_page
:
59 self
.raise_geo_restricted(
60 '%s is only available in German-speaking countries of Europe' % self
.IE_NAME
)
62 login_form
= self
._form
_hidden
_inputs
('new_user', login_page
)
65 'user[login]': username
,
66 'user[password]': password
,
69 post_url
= self
._search
_regex
(
70 r
'<form[^>]+action=(["\'])(?P
<url
>.+?
)\
1', login_page,
71 'post url
', default=self._LOGIN_URL, group='url
')
73 if not post_url.startswith('http
'):
74 post_url = urljoin(self._LOGIN_URL, post_url)
76 response = self._download_webpage(
77 post_url, None, 'Logging
in',
78 data=urlencode_postdata(login_form), headers={
79 'Referer
': self._LOGIN_URL,
82 if all(p not in response for p in ('>Logout
<', 'href
="/users/sign_out"')):
83 error = self._search_regex(
84 r'<p
[^
>]+\bclass
=(["\'])(?:(?!\1).)*\balert\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</p>',
85 response, 'error', default=None, group='error')
87 raise ExtractorError('Unable to login: %s' % error, expected=True)
88 raise ExtractorError('Unable to log in')
90 def _real_extract(self, url):
91 anime_id = self._match_id(url)
93 webpage = self._download_webpage(url, anime_id)
95 if 'data-playlist=' not in webpage:
96 self._download_webpage(
97 self._APPLY_HTML5_URL, anime_id,
98 'Activating HTML5 beta', 'Unable to apply HTML5 beta')
99 webpage = self._download_webpage(url, anime_id)
101 csrf_token = self._html_search_meta(
102 'csrf-token', webpage, 'csrf token', fatal=True)
104 anime_title = self._html_search_regex(
105 r'(?s)<h1[^>]+itemprop="name
"[^>]*>(.+?)</h1>',
106 webpage, 'anime name')
107 anime_description = self._html_search_regex(
108 r'(?s)<div[^>]+itemprop="description
"[^>]*>(.+?)</div>',
109 webpage, 'anime description', default=None)
111 def extract_info(html, video_id, num=None):
112 title, description = [None] * 2
115 for input_ in re.findall(
116 r'<input[^>]+class=["\'].*?streamstarter
[^
>]+>', html):
117 attributes = extract_attributes(input_)
118 title = attributes.get('data
-dialog
-header
')
120 for playlist_key in ('data
-playlist
', 'data
-otherplaylist
', 'data
-stream
'):
121 playlist_url = attributes.get(playlist_key)
122 if isinstance(playlist_url, compat_str) and re.match(
123 r'/?
[\da
-zA
-Z
]+', playlist_url):
124 playlist_urls.append(attributes[playlist_key])
125 if not playlist_urls:
128 lang = attributes.get('data
-lang
')
129 lang_note = attributes.get('value
')
131 for playlist_url in playlist_urls:
132 kind = self._search_regex(
133 r'videomaterialurl
/\d
+/([^
/]+)/',
134 playlist_url, 'media kind
', default=None)
135 format_id = join_nonempty(lang, kind) if lang or kind else str(num)
136 format_note = join_nonempty(kind, lang_note, delim=', ')
139 item_id_list.append(format_id)
140 item_id_list.append('videomaterial
')
141 playlist = self._download_json(
142 urljoin(url, playlist_url), video_id,
143 'Downloading
%s JSON
' % ' '.join(item_id_list),
145 'X
-Requested
-With
': 'XMLHttpRequest
',
146 'X
-CSRF
-Token
': csrf_token,
148 'Accept
': 'application
/json
, text
/javascript
, */*; q
=0.01',
152 stream_url = url_or_none(playlist.get('streamurl
'))
155 r'^
(?P
<url
>rtmpe?
://(?P
<host
>[^
/]+)/(?P
<app
>.+/))(?P
<playpath
>mp
[34]:.+)',
159 'url
': rtmp.group('url
'),
160 'app
': rtmp.group('app
'),
161 'play_path
': rtmp.group('playpath
'),
163 'player_url
': 'https
://www
.anime
-on
-demand
.de
/assets
/jwplayer
.flash
-55abfb34080700304d49125ce9ffb4a6
.swf
',
164 'rtmp_real_time
': True,
169 start_video = playlist.get('startvideo
', 0)
170 playlist = playlist.get('playlist
')
171 if not playlist or not isinstance(playlist, list):
173 playlist = playlist[start_video]
174 title = playlist.get('title
')
177 description = playlist.get('description
')
178 for source in playlist.get('sources
', []):
179 file_ = source.get('file')
182 ext = determine_ext(file_)
183 format_id = join_nonempty(
185 'hls
' if ext == 'm3u8
' else None,
186 'dash
' if source.get('type') == 'video
/dash
' or ext == 'mpd
' else None)
188 file_formats = self._extract_m3u8_formats(
189 file_, video_id, 'mp4
',
190 entry_protocol='m3u8_native
', m3u8_id=format_id, fatal=False)
191 elif source.get('type') == 'video
/dash
' or ext == 'mpd
':
193 file_formats = self._extract_mpd_formats(
194 file_, video_id, mpd_id=format_id, fatal=False)
197 for f in file_formats:
200 'format_note
': format_note,
202 formats.extend(file_formats)
206 'description
': description,
210 def extract_entries(html, video_id, common_info, num=None):
211 info = extract_info(html, video_id, num)
214 self._sort_formats(info['formats
'])
215 f = common_info.copy()
219 # Extract teaser/trailer only when full episode is not available
220 if not info['formats
']:
222 r'data
-dialog
-header
=(["\'])(?P<title>.+?)\1[^>]+href=(["\'])(?P
<href
>.+?
)\
3[^
>]*>(?P
<kind
>Teaser|Trailer
)<',
225 f = common_info.copy()
227 'id': '%s-%s' % (f['id'], m.group('kind
').lower()),
228 'title
': m.group('title
'),
229 'url
': urljoin(url, m.group('href
')),
233 def extract_episodes(html):
234 for num, episode_html in enumerate(re.findall(
235 r'(?s
)<h3
[^
>]+class="episodebox-title".+?
>Episodeninhalt
<', html), 1):
236 episodebox_title = self._search_regex(
237 (r'class="episodebox-title"[^
>]+title
=(["\'])(?P<title>.+?)\1',
238 r'class="episodebox
-title
"[^>]+>(?P<title>.+?)<'),
239 episode_html, 'episodebox title', default=None, group='title')
240 if not episodebox_title:
243 episode_number = int(self._search_regex(
244 r'(?:Episode|Film)\s*(\d+)',
245 episodebox_title, 'episode number', default=num))
246 episode_title = self._search_regex(
247 r'(?:Episode|Film)\s*\d+\s*-\s*(.+)',
248 episodebox_title, 'episode title', default=None)
250 video_id = 'episode-%d' % episode_number
254 'series': anime_title,
255 'episode': episode_title,
256 'episode_number': episode_number,
259 for e in extract_entries(episode_html, video_id, common_info):
262 def extract_film(html, video_id):
265 'title': anime_title,
266 'description': anime_description,
268 for e in extract_entries(html, video_id, common_info):
273 for e in extract_episodes(webpage):
278 for e in extract_film(webpage, anime_id):
281 return self.playlist_result(
282 entries(), anime_id, anime_title, anime_description)