1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
9 compat_urllib_parse_urlencode
,
10 compat_urllib_parse_urlparse
,
18 class AddAnimeIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:\w+\.)?add-anime\.net/(?:watch_video\.php\?(?:.*?)v=|video/)(?P<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',
29 'skip': 'Video is gone',
31 'url': 'http://add-anime.net/video/MDUGWYKNGBD8/One-Piece-687',
32 'only_matching': True,
35 def _real_extract(self
, url
):
36 video_id
= self
._match
_id
(url
)
39 webpage
= self
._download
_webpage
(url
, video_id
)
40 except ExtractorError
as ee
:
41 if not isinstance(ee
.cause
, compat_HTTPError
) or \
45 redir_webpage
= ee
.cause
.read().decode('utf-8')
46 action
= self
._search
_regex
(
47 r
'<form id="challenge-form" action="([^"]+)"',
48 redir_webpage
, 'Redirect form')
49 vc
= self
._search
_regex
(
50 r
'<input type="hidden" name="jschl_vc" value="([^"]+)"/>',
51 redir_webpage
, 'redirect vc value')
53 r
'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);',
56 raise ExtractorError('Cannot find redirect math task')
57 av_res
= int(av
.group(1)) + int(av
.group(2)) * int(av
.group(3))
59 parsed_url
= compat_urllib_parse_urlparse(url
)
60 av_val
= av_res
+ len(parsed_url
.netloc
)
62 parsed_url
.scheme
+ '://' + parsed_url
.netloc
64 + compat_urllib_parse_urlencode({
65 'jschl_vc': vc
, 'jschl_answer': compat_str(av_val
)}))
66 self
._download
_webpage
(
67 confirm_url
, video_id
,
68 note
='Confirming after redirect')
69 webpage
= self
._download
_webpage
(url
, video_id
)
71 FORMATS
= ('normal', 'hq')
72 quality
= qualities(FORMATS
)
74 for format_id
in FORMATS
:
75 rex
= r
"var %s_video_file = '(.*?)';" % re
.escape(format_id
)
76 video_url
= self
._search
_regex
(rex
, webpage
, 'video file URLx',
81 'format_id': format_id
,
83 'quality': quality(format_id
),
85 self
._sort
_formats
(formats
)
86 video_title
= self
._og
_search
_title
(webpage
)
87 video_description
= self
._og
_search
_description
(webpage
)
94 'description': video_description