2016-02-13 16:30:31 +09:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
2017-09-11 06:32:35 +09:00
|
|
|
from ..compat import compat_str
|
2016-02-13 16:30:31 +09:00
|
|
|
from ..utils import (
|
|
|
|
determine_ext,
|
2016-03-21 00:51:22 +09:00
|
|
|
extract_attributes,
|
2016-02-13 16:30:31 +09:00
|
|
|
ExtractorError,
|
2018-07-21 21:08:28 +09:00
|
|
|
url_or_none,
|
2016-02-13 16:30:31 +09:00
|
|
|
urlencode_postdata,
|
2017-09-11 06:32:35 +09:00
|
|
|
urljoin,
|
2016-02-13 16:30:31 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class AnimeOnDemandIE(InfoExtractor):
|
|
|
|
_VALID_URL = r'https?://(?:www\.)?anime-on-demand\.de/anime/(?P<id>\d+)'
|
|
|
|
_LOGIN_URL = 'https://www.anime-on-demand.de/users/sign_in'
|
|
|
|
_APPLY_HTML5_URL = 'https://www.anime-on-demand.de/html5apply'
|
2016-02-14 01:41:58 +09:00
|
|
|
_NETRC_MACHINE = 'animeondemand'
|
2017-09-11 06:22:55 +09:00
|
|
|
# German-speaking countries of Europe
|
|
|
|
_GEO_COUNTRIES = ['AT', 'CH', 'DE', 'LI', 'LU']
|
2016-03-18 02:50:10 +09:00
|
|
|
_TESTS = [{
|
2016-07-09 08:57:04 +09:00
|
|
|
# jap, OmU
|
2016-02-13 16:30:31 +09:00
|
|
|
'url': 'https://www.anime-on-demand.de/anime/161',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '161',
|
|
|
|
'title': 'Grimgar, Ashes and Illusions (OmU)',
|
|
|
|
'description': 'md5:6681ce3c07c7189d255ac6ab23812d31',
|
|
|
|
},
|
|
|
|
'playlist_mincount': 4,
|
2016-03-18 02:50:10 +09:00
|
|
|
}, {
|
2016-07-09 08:57:04 +09:00
|
|
|
# Film wording is used instead of Episode, ger/jap, Dub/OmU
|
2016-03-18 02:50:10 +09:00
|
|
|
'url': 'https://www.anime-on-demand.de/anime/39',
|
|
|
|
'only_matching': True,
|
2016-03-18 03:02:34 +09:00
|
|
|
}, {
|
2016-07-09 08:57:04 +09:00
|
|
|
# Episodes without titles, jap, OmU
|
2016-03-18 03:02:34 +09:00
|
|
|
'url': 'https://www.anime-on-demand.de/anime/162',
|
|
|
|
'only_matching': True,
|
2016-03-21 00:51:22 +09:00
|
|
|
}, {
|
|
|
|
# ger/jap, Dub/OmU, account required
|
|
|
|
'url': 'https://www.anime-on-demand.de/anime/169',
|
|
|
|
'only_matching': True,
|
2016-07-09 08:57:04 +09:00
|
|
|
}, {
|
|
|
|
# Full length film, non-series, ger/jap, Dub/OmU, account required
|
|
|
|
'url': 'https://www.anime-on-demand.de/anime/185',
|
|
|
|
'only_matching': True,
|
2017-09-11 06:14:54 +09:00
|
|
|
}, {
|
|
|
|
# Flash videos
|
|
|
|
'url': 'https://www.anime-on-demand.de/anime/12',
|
|
|
|
'only_matching': True,
|
2016-03-18 02:50:10 +09:00
|
|
|
}]
|
2016-02-13 16:30:31 +09:00
|
|
|
|
|
|
|
def _login(self):
|
2018-05-27 00:12:44 +09:00
|
|
|
username, password = self._get_login_info()
|
2016-02-13 16:30:31 +09:00
|
|
|
if username is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
login_page = self._download_webpage(
|
|
|
|
self._LOGIN_URL, None, 'Downloading login page')
|
|
|
|
|
2016-03-20 23:39:00 +09:00
|
|
|
if '>Our licensing terms allow the distribution of animes only to German-speaking countries of Europe' in login_page:
|
|
|
|
self.raise_geo_restricted(
|
|
|
|
'%s is only available in German-speaking countries of Europe' % self.IE_NAME)
|
|
|
|
|
2016-02-13 16:30:31 +09:00
|
|
|
login_form = self._form_hidden_inputs('new_user', login_page)
|
|
|
|
|
|
|
|
login_form.update({
|
|
|
|
'user[login]': username,
|
|
|
|
'user[password]': password,
|
|
|
|
})
|
|
|
|
|
|
|
|
post_url = self._search_regex(
|
|
|
|
r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
|
|
|
|
'post url', default=self._LOGIN_URL, group='url')
|
|
|
|
|
|
|
|
if not post_url.startswith('http'):
|
2017-09-11 06:32:35 +09:00
|
|
|
post_url = urljoin(self._LOGIN_URL, post_url)
|
2016-02-13 16:30:31 +09:00
|
|
|
|
|
|
|
response = self._download_webpage(
|
2017-11-11 22:49:03 +09:00
|
|
|
post_url, None, 'Logging in',
|
2017-09-11 06:32:35 +09:00
|
|
|
data=urlencode_postdata(login_form), headers={
|
|
|
|
'Referer': self._LOGIN_URL,
|
|
|
|
})
|
2016-02-13 16:30:31 +09:00
|
|
|
|
|
|
|
if all(p not in response for p in ('>Logout<', 'href="/users/sign_out"')):
|
|
|
|
error = self._search_regex(
|
2017-12-21 01:17:36 +09:00
|
|
|
r'<p[^>]+\bclass=(["\'])(?:(?!\1).)*\balert\b(?:(?!\1).)*\1[^>]*>(?P<error>.+?)</p>',
|
2017-12-20 00:53:04 +09:00
|
|
|
response, 'error', default=None, group='error')
|
2016-02-13 16:30:31 +09:00
|
|
|
if error:
|
|
|
|
raise ExtractorError('Unable to login: %s' % error, expected=True)
|
|
|
|
raise ExtractorError('Unable to log in')
|
|
|
|
|
|
|
|
def _real_initialize(self):
|
|
|
|
self._login()
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
|
|
|
anime_id = self._match_id(url)
|
|
|
|
|
|
|
|
webpage = self._download_webpage(url, anime_id)
|
|
|
|
|
|
|
|
if 'data-playlist=' not in webpage:
|
|
|
|
self._download_webpage(
|
|
|
|
self._APPLY_HTML5_URL, anime_id,
|
|
|
|
'Activating HTML5 beta', 'Unable to apply HTML5 beta')
|
|
|
|
webpage = self._download_webpage(url, anime_id)
|
|
|
|
|
|
|
|
csrf_token = self._html_search_meta(
|
|
|
|
'csrf-token', webpage, 'csrf token', fatal=True)
|
|
|
|
|
|
|
|
anime_title = self._html_search_regex(
|
|
|
|
r'(?s)<h1[^>]+itemprop="name"[^>]*>(.+?)</h1>',
|
|
|
|
webpage, 'anime name')
|
|
|
|
anime_description = self._html_search_regex(
|
|
|
|
r'(?s)<div[^>]+itemprop="description"[^>]*>(.+?)</div>',
|
|
|
|
webpage, 'anime description', default=None)
|
|
|
|
|
2016-07-09 09:13:32 +09:00
|
|
|
def extract_info(html, video_id, num=None):
|
2016-07-09 08:57:04 +09:00
|
|
|
title, description = [None] * 2
|
2016-02-13 16:30:31 +09:00
|
|
|
formats = []
|
|
|
|
|
2016-03-21 00:51:22 +09:00
|
|
|
for input_ in re.findall(
|
2017-09-11 06:14:54 +09:00
|
|
|
r'<input[^>]+class=["\'].*?streamstarter[^>]+>', html):
|
2016-03-21 00:51:22 +09:00
|
|
|
attributes = extract_attributes(input_)
|
2017-09-11 06:14:54 +09:00
|
|
|
title = attributes.get('data-dialog-header')
|
2016-03-21 00:51:22 +09:00
|
|
|
playlist_urls = []
|
2017-09-11 06:14:54 +09:00
|
|
|
for playlist_key in ('data-playlist', 'data-otherplaylist', 'data-stream'):
|
2016-03-21 00:51:22 +09:00
|
|
|
playlist_url = attributes.get(playlist_key)
|
|
|
|
if isinstance(playlist_url, compat_str) and re.match(
|
|
|
|
r'/?[\da-zA-Z]+', playlist_url):
|
|
|
|
playlist_urls.append(attributes[playlist_key])
|
|
|
|
if not playlist_urls:
|
|
|
|
continue
|
|
|
|
|
|
|
|
lang = attributes.get('data-lang')
|
|
|
|
lang_note = attributes.get('value')
|
|
|
|
|
|
|
|
for playlist_url in playlist_urls:
|
|
|
|
kind = self._search_regex(
|
|
|
|
r'videomaterialurl/\d+/([^/]+)/',
|
|
|
|
playlist_url, 'media kind', default=None)
|
|
|
|
format_id_list = []
|
|
|
|
if lang:
|
|
|
|
format_id_list.append(lang)
|
|
|
|
if kind:
|
|
|
|
format_id_list.append(kind)
|
2016-07-09 09:13:32 +09:00
|
|
|
if not format_id_list and num is not None:
|
2016-03-22 02:31:40 +09:00
|
|
|
format_id_list.append(compat_str(num))
|
2016-03-21 00:51:22 +09:00
|
|
|
format_id = '-'.join(format_id_list)
|
|
|
|
format_note = ', '.join(filter(None, (kind, lang_note)))
|
2017-09-11 06:32:35 +09:00
|
|
|
item_id_list = []
|
|
|
|
if format_id:
|
|
|
|
item_id_list.append(format_id)
|
|
|
|
item_id_list.append('videomaterial')
|
|
|
|
playlist = self._download_json(
|
|
|
|
urljoin(url, playlist_url), video_id,
|
|
|
|
'Downloading %s JSON' % ' '.join(item_id_list),
|
2016-03-21 00:51:22 +09:00
|
|
|
headers={
|
|
|
|
'X-Requested-With': 'XMLHttpRequest',
|
|
|
|
'X-CSRF-Token': csrf_token,
|
|
|
|
'Referer': url,
|
|
|
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
2017-09-11 06:32:35 +09:00
|
|
|
}, fatal=False)
|
2016-03-21 00:51:22 +09:00
|
|
|
if not playlist:
|
|
|
|
continue
|
2018-07-21 21:08:28 +09:00
|
|
|
stream_url = url_or_none(playlist.get('streamurl'))
|
2017-09-11 06:14:54 +09:00
|
|
|
if stream_url:
|
|
|
|
rtmp = re.search(
|
|
|
|
r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+/))(?P<playpath>mp[34]:.+)',
|
|
|
|
stream_url)
|
|
|
|
if rtmp:
|
|
|
|
formats.append({
|
|
|
|
'url': rtmp.group('url'),
|
|
|
|
'app': rtmp.group('app'),
|
|
|
|
'play_path': rtmp.group('playpath'),
|
|
|
|
'page_url': url,
|
|
|
|
'player_url': 'https://www.anime-on-demand.de/assets/jwplayer.flash-55abfb34080700304d49125ce9ffb4a6.swf',
|
|
|
|
'rtmp_real_time': True,
|
|
|
|
'format_id': 'rtmp',
|
|
|
|
'ext': 'flv',
|
|
|
|
})
|
|
|
|
continue
|
2016-03-22 02:31:40 +09:00
|
|
|
start_video = playlist.get('startvideo', 0)
|
2016-03-21 00:51:22 +09:00
|
|
|
playlist = playlist.get('playlist')
|
|
|
|
if not playlist or not isinstance(playlist, list):
|
|
|
|
continue
|
2016-03-22 02:31:40 +09:00
|
|
|
playlist = playlist[start_video]
|
2016-03-21 00:51:22 +09:00
|
|
|
title = playlist.get('title')
|
|
|
|
if not title:
|
|
|
|
continue
|
2016-02-13 16:30:31 +09:00
|
|
|
description = playlist.get('description')
|
|
|
|
for source in playlist.get('sources', []):
|
|
|
|
file_ = source.get('file')
|
2016-03-22 02:31:40 +09:00
|
|
|
if not file_:
|
|
|
|
continue
|
|
|
|
ext = determine_ext(file_)
|
|
|
|
format_id_list = [lang, kind]
|
|
|
|
if ext == 'm3u8':
|
|
|
|
format_id_list.append('hls')
|
|
|
|
elif source.get('type') == 'video/dash' or ext == 'mpd':
|
|
|
|
format_id_list.append('dash')
|
|
|
|
format_id = '-'.join(filter(None, format_id_list))
|
|
|
|
if ext == 'm3u8':
|
|
|
|
file_formats = self._extract_m3u8_formats(
|
2016-02-13 16:30:31 +09:00
|
|
|
file_, video_id, 'mp4',
|
2016-03-22 02:31:40 +09:00
|
|
|
entry_protocol='m3u8_native', m3u8_id=format_id, fatal=False)
|
|
|
|
elif source.get('type') == 'video/dash' or ext == 'mpd':
|
2016-03-22 02:37:39 +09:00
|
|
|
continue
|
2016-03-22 02:31:40 +09:00
|
|
|
file_formats = self._extract_mpd_formats(
|
|
|
|
file_, video_id, mpd_id=format_id, fatal=False)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
for f in file_formats:
|
|
|
|
f.update({
|
|
|
|
'language': lang,
|
|
|
|
'format_note': format_note,
|
|
|
|
})
|
|
|
|
formats.extend(file_formats)
|
2016-02-13 16:30:31 +09:00
|
|
|
|
2016-07-09 08:57:04 +09:00
|
|
|
return {
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'formats': formats,
|
|
|
|
}
|
|
|
|
|
2016-07-10 00:20:34 +09:00
|
|
|
def extract_entries(html, video_id, common_info, num=None):
|
2016-07-09 09:13:32 +09:00
|
|
|
info = extract_info(html, video_id, num)
|
2016-07-09 08:57:04 +09:00
|
|
|
|
|
|
|
if info['formats']:
|
|
|
|
self._sort_formats(info['formats'])
|
2016-02-13 16:30:31 +09:00
|
|
|
f = common_info.copy()
|
2016-07-09 08:57:04 +09:00
|
|
|
f.update(info)
|
2021-01-16 11:22:33 +09:00
|
|
|
yield f
|
2016-02-13 16:30:31 +09:00
|
|
|
|
2016-07-09 08:57:04 +09:00
|
|
|
# Extract teaser/trailer only when full episode is not available
|
|
|
|
if not info['formats']:
|
2016-03-22 02:35:50 +09:00
|
|
|
m = re.search(
|
2016-07-09 08:57:04 +09:00
|
|
|
r'data-dialog-header=(["\'])(?P<title>.+?)\1[^>]+href=(["\'])(?P<href>.+?)\3[^>]*>(?P<kind>Teaser|Trailer)<',
|
|
|
|
html)
|
2016-03-22 02:35:50 +09:00
|
|
|
if m:
|
|
|
|
f = common_info.copy()
|
|
|
|
f.update({
|
2016-07-09 08:57:04 +09:00
|
|
|
'id': '%s-%s' % (f['id'], m.group('kind').lower()),
|
2016-03-22 02:35:50 +09:00
|
|
|
'title': m.group('title'),
|
2017-09-11 06:32:35 +09:00
|
|
|
'url': urljoin(url, m.group('href')),
|
2016-03-22 02:35:50 +09:00
|
|
|
})
|
2021-01-16 11:22:33 +09:00
|
|
|
yield f
|
2016-02-13 16:30:31 +09:00
|
|
|
|
2016-07-09 08:57:04 +09:00
|
|
|
def extract_episodes(html):
|
|
|
|
for num, episode_html in enumerate(re.findall(
|
|
|
|
r'(?s)<h3[^>]+class="episodebox-title".+?>Episodeninhalt<', html), 1):
|
|
|
|
episodebox_title = self._search_regex(
|
|
|
|
(r'class="episodebox-title"[^>]+title=(["\'])(?P<title>.+?)\1',
|
|
|
|
r'class="episodebox-title"[^>]+>(?P<title>.+?)<'),
|
|
|
|
episode_html, 'episodebox title', default=None, group='title')
|
|
|
|
if not episodebox_title:
|
|
|
|
continue
|
|
|
|
|
|
|
|
episode_number = int(self._search_regex(
|
|
|
|
r'(?:Episode|Film)\s*(\d+)',
|
|
|
|
episodebox_title, 'episode number', default=num))
|
|
|
|
episode_title = self._search_regex(
|
|
|
|
r'(?:Episode|Film)\s*\d+\s*-\s*(.+)',
|
|
|
|
episodebox_title, 'episode title', default=None)
|
|
|
|
|
|
|
|
video_id = 'episode-%d' % episode_number
|
|
|
|
|
|
|
|
common_info = {
|
|
|
|
'id': video_id,
|
|
|
|
'series': anime_title,
|
|
|
|
'episode': episode_title,
|
|
|
|
'episode_number': episode_number,
|
|
|
|
}
|
|
|
|
|
2021-01-16 11:22:33 +09:00
|
|
|
for e in extract_entries(episode_html, video_id, common_info):
|
|
|
|
yield e
|
2016-07-09 08:57:04 +09:00
|
|
|
|
|
|
|
def extract_film(html, video_id):
|
|
|
|
common_info = {
|
|
|
|
'id': anime_id,
|
|
|
|
'title': anime_title,
|
|
|
|
'description': anime_description,
|
|
|
|
}
|
2021-01-16 11:22:33 +09:00
|
|
|
for e in extract_entries(html, video_id, common_info):
|
|
|
|
yield e
|
2016-07-09 08:57:04 +09:00
|
|
|
|
2021-01-16 11:22:33 +09:00
|
|
|
def entries():
|
|
|
|
has_episodes = False
|
|
|
|
for e in extract_episodes(webpage):
|
|
|
|
has_episodes = True
|
|
|
|
yield e
|
2016-07-09 08:57:04 +09:00
|
|
|
|
2021-01-16 11:22:33 +09:00
|
|
|
if not has_episodes:
|
|
|
|
for e in extract_film(webpage, anime_id):
|
|
|
|
yield e
|
2016-07-09 08:57:04 +09:00
|
|
|
|
2021-01-16 11:22:33 +09:00
|
|
|
return self.playlist_result(
|
|
|
|
entries(), anime_id, anime_title, anime_description)
|