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,
30 # Film wording is used instead of Episode
31 'url': 'https://www.anime-on-demand.de/anime/39',
32 'only_matching': True,
34 # Episodes without titles
35 'url': 'https://www.anime-on-demand.de/anime/162',
36 'only_matching': True,
40 (username, password) = self._get_login_info()
44 login_page = self._download_webpage(
45 self._LOGIN_URL, None, 'Downloading login page')
47 login_form = self._form_hidden_inputs('new_user', login_page)
50 'user[login]': username,
51 'user[password]': password,
54 post_url = self._search_regex(
55 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page,
56 'post url', default=self._LOGIN_URL, group='url')
58 if not post_url.startswith('http'):
59 post_url = compat_urlparse.urljoin(self._LOGIN_URL, post_url)
61 request = sanitized_Request(
62 post_url, urlencode_postdata(encode_dict(login_form)))
63 request.add_header('Referer', self._LOGIN_URL)
65 response = self._download_webpage(
66 request, None, 'Logging in as %s' % username)
68 if all(p not in response for p in ('>Logout<', 'href="/users/sign_out"')):
69 error = self._search_regex(
70 r'<p class="alert alert-danger">(.+?)</p>',
71 response, 'error', default=None)
73 raise ExtractorError('Unable to login: %s' % error, expected=True)
74 raise ExtractorError('Unable to log in')
76 def _real_initialize(self):
79 def _real_extract(self, url):
80 anime_id = self._match_id(url)
82 webpage = self._download_webpage(url, anime_id)
84 if 'data-playlist=' not in webpage:
85 self._download_webpage(
86 self._APPLY_HTML5_URL, anime_id,
87 'Activating HTML5 beta', 'Unable to apply HTML5 beta')
88 webpage = self._download_webpage(url, anime_id)
90 csrf_token = self._html_search_meta(
91 'csrf-token', webpage, 'csrf token', fatal=True)
93 anime_title = self._html_search_regex(
94 r'(?s)<h1[^>]+itemprop="name"[^>]*>(.+?)</h1>',
95 webpage, 'anime name')
96 anime_description = self._html_search_regex(
97 r'(?s)<div[^>]+itemprop="description"[^>]*>(.+?)</div>',
98 webpage, 'anime description', default=None)
102 for num, episode_html in enumerate(re.findall(
103 r'(?s)<h3[^>]+class="episodebox-title".+?>Episodeninhalt<', webpage), 1):
104 episodebox_title = self._search_regex(
105 (r'class="episodebox-title"[^>]+title=(["\'])(?P<title>.+?)\1',
106 r'class="episodebox-title"[^>]+>(?P<title>.+?)<'),
107 episode_html, 'episodebox title', default=None, group='title')
108 if not episodebox_title:
111 episode_number = int(self._search_regex(
112 r'(?:Episode|Film)\s*(\d+)',
113 episodebox_title, 'episode number', default=num))
114 episode_title = self._search_regex(
115 r'(?:Episode|Film)\s*\d+\s*-\s*(.+)',
116 episodebox_title, 'episode title', default=None)
118 video_id = 'episode-%d' % episode_number
122 'series': anime_title,
123 'episode': episode_title,
124 'episode_number': episode_number,
129 playlist_url = self._search_regex(
130 r'data-playlist=(["\'])(?P<url>.+?)\1',
131 episode_html, 'data playlist', default=None, group='url')
133 request = sanitized_Request(
134 compat_urlparse.urljoin(url, playlist_url),
136 'X-Requested-With': 'XMLHttpRequest',
137 'X-CSRF-Token': csrf_token,
139 'Accept': 'application/json, text/javascript, */*; q=0.01',
142 playlist = self._download_json(
143 request, video_id, 'Downloading playlist JSON', fatal=False)
145 playlist = playlist['playlist'][0]
146 title = playlist['title']
147 description = playlist.get('description')
148 for source in playlist.get('sources', []):
149 file_ = source.get('file')
150 if file_ and determine_ext(file_) == 'm3u8':
151 formats = self._extract_m3u8_formats(
152 file_, video_id, 'mp4',
153 entry_protocol='m3u8_native', m3u8_id='hls')
156 f = common_info.copy()
159 'description': description,
165 r'data-dialog-header=(["\'])(?P<title>.+?)\1[^>]+href=(["\'])(?P<href>.+?)\3[^>]*>Teaser<',
168 f = common_info.copy()
170 'id': '%s-teaser' % f['id'],
171 'title': m.group('title'),
172 'url': compat_urlparse.urljoin(url, m.group('href')),
176 return self.playlist_result(entries, anime_id, anime_title, anime_description)