3 from .common
import InfoExtractor
8 compat_urllib_parse_urlparse
,
14 class AddAnimeIE(InfoExtractor
):
16 _VALID_URL
= r
'^http://(?:\w+\.)?add-anime\.net/watch_video.php\?(?:.*?)v=(?P<video_id>[\w_]+)(?:.*)'
19 u
'url': u
'http://www.add-anime.net/watch_video.php?v=24MR3YO5SAS9',
20 u
'file': u
'24MR3YO5SAS9.mp4',
21 u
'md5': u
'72954ea10bc979ab5e2eb288b21425a0',
23 u
"description": u
"One Piece 606",
24 u
"title": u
"One Piece 606"
28 def _real_extract(self
, url
):
30 mobj
= re
.match(self
._VALID
_URL
, url
)
31 video_id
= mobj
.group('video_id')
32 webpage
= self
._download
_webpage
(url
, video_id
)
33 except ExtractorError
as ee
:
34 if not isinstance(ee
.cause
, compat_HTTPError
):
37 redir_webpage
= ee
.cause
.read().decode('utf-8')
38 action
= self
._search
_regex
(
39 r
'<form id="challenge-form" action="([^"]+)"',
40 redir_webpage
, u
'Redirect form')
41 vc
= self
._search
_regex
(
42 r
'<input type="hidden" name="jschl_vc" value="([^"]+)"/>',
43 redir_webpage
, u
'redirect vc value')
45 r
'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);',
48 raise ExtractorError(u
'Cannot find redirect math task')
49 av_res
= int(av
.group(1)) + int(av
.group(2)) * int(av
.group(3))
51 parsed_url
= compat_urllib_parse_urlparse(url
)
52 av_val
= av_res
+ len(parsed_url
.netloc
)
54 parsed_url
.scheme
+ u
'://' + parsed_url
.netloc
+
56 compat_urllib_parse
.urlencode({
57 'jschl_vc': vc
, 'jschl_answer': compat_str(av_val
)}))
58 self
._download
_webpage
(
59 confirm_url
, video_id
,
60 note
=u
'Confirming after redirect')
61 webpage
= self
._download
_webpage
(url
, video_id
)
63 video_url
= self
._search
_regex
(r
"var (?:hq|normal)_video_file = '(.*?)';",
64 webpage
, u
'video file URL')
66 video_extension
= video_url
[-3:] # mp4 or flv ?
67 video_title
= self
._og
_search
_title
(webpage
)
68 video_description
= self
._og
_search
_description
(webpage
)
74 'ext': video_extension
,
76 'description': video_description