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
) or \
 
  38             redir_webpage 
= ee
.cause
.read().decode('utf-8') 
  39             action 
= self
._search
_regex
( 
  40                 r
'<form id="challenge-form" action="([^"]+)"', 
  41                 redir_webpage
, u
'Redirect form') 
  42             vc 
= self
._search
_regex
( 
  43                 r
'<input type="hidden" name="jschl_vc" value="([^"]+)"/>', 
  44                 redir_webpage
, u
'redirect vc value') 
  46                 r
'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);', 
  49                 raise ExtractorError(u
'Cannot find redirect math task') 
  50             av_res 
= int(av
.group(1)) + int(av
.group(2)) * int(av
.group(3)) 
  52             parsed_url 
= compat_urllib_parse_urlparse(url
) 
  53             av_val 
= av_res 
+ len(parsed_url
.netloc
) 
  55                 parsed_url
.scheme 
+ u
'://' + parsed_url
.netloc 
+ 
  57                 compat_urllib_parse
.urlencode({ 
  58                     'jschl_vc': vc
, 'jschl_answer': compat_str(av_val
)})) 
  59             self
._download
_webpage
( 
  60                 confirm_url
, video_id
, 
  61                 note
=u
'Confirming after redirect') 
  62             webpage 
= self
._download
_webpage
(url
, video_id
) 
  65         for format_id 
in ('normal', 'hq'): 
  66             rex 
= r
"var %s_video_file = '(.*?)';" % re
.escape(format_id
) 
  67             video_url 
= self
._search
_regex
(rex
, webpage
, u
'video file URLx', 
  72                 'format_id': format_id
, 
  76             raise ExtractorError(u
'Cannot find any video format!') 
  77         video_title 
= self
._og
_search
_title
(webpage
) 
  78         video_description 
= self
._og
_search
_description
(webpage
) 
  85             'description': video_description