1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
10 compat_urllib_parse_urlparse
,
17 class AddAnimeIE(InfoExtractor
):
19 _VALID_URL
= r
'^http://(?:\w+\.)?add-anime\.net/watch_video\.php\?(?:.*?)v=(?P<video_id>[\w_]+)(?:.*)'
21 'url': 'http://www.add-anime.net/watch_video.php?v=24MR3YO5SAS9',
22 'md5': '72954ea10bc979ab5e2eb288b21425a0',
26 'description': 'One Piece 606',
27 'title': 'One Piece 606',
31 def _real_extract(self
, url
):
33 mobj
= re
.match(self
._VALID
_URL
, url
)
34 video_id
= mobj
.group('video_id')
35 webpage
= self
._download
_webpage
(url
, video_id
)
36 except ExtractorError
as ee
:
37 if not isinstance(ee
.cause
, compat_HTTPError
) or \
41 redir_webpage
= ee
.cause
.read().decode('utf-8')
42 action
= self
._search
_regex
(
43 r
'<form id="challenge-form" action="([^"]+)"',
44 redir_webpage
, 'Redirect form')
45 vc
= self
._search
_regex
(
46 r
'<input type="hidden" name="jschl_vc" value="([^"]+)"/>',
47 redir_webpage
, 'redirect vc value')
49 r
'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);',
52 raise ExtractorError(u
'Cannot find redirect math task')
53 av_res
= int(av
.group(1)) + int(av
.group(2)) * int(av
.group(3))
55 parsed_url
= compat_urllib_parse_urlparse(url
)
56 av_val
= av_res
+ len(parsed_url
.netloc
)
58 parsed_url
.scheme
+ '://' + parsed_url
.netloc
+
60 compat_urllib_parse
.urlencode({
61 'jschl_vc': vc
, 'jschl_answer': compat_str(av_val
)}))
62 self
._download
_webpage
(
63 confirm_url
, video_id
,
64 note
='Confirming after redirect')
65 webpage
= self
._download
_webpage
(url
, video_id
)
68 for format_id
in ('normal', 'hq'):
69 rex
= r
"var %s_video_file = '(.*?)';" % re
.escape(format_id
)
70 video_url
= self
._search
_regex
(rex
, webpage
, 'video file URLx',
75 'format_id': format_id
,
78 self
._sort
_formats
(formats
)
79 video_title
= self
._og
_search
_title
(webpage
)
80 video_description
= self
._og
_search
_description
(webpage
)
87 'description': video_description