]>
Commit | Line | Data |
---|---|---|
f847ca02 PH |
1 | from __future__ import unicode_literals |
2 | ||
4f5f18ac PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
8c25f81b | 6 | from ..compat import ( |
4f5f18ac PH |
7 | compat_HTTPError, |
8 | compat_str, | |
9 | compat_urllib_parse, | |
10 | compat_urllib_parse_urlparse, | |
8c25f81b PH |
11 | ) |
12 | from ..utils import ( | |
4f5f18ac | 13 | ExtractorError, |
beb10f84 | 14 | qualities, |
4f5f18ac PH |
15 | ) |
16 | ||
17 | ||
18 | class AddAnimeIE(InfoExtractor): | |
5f4b5cf0 | 19 | _VALID_URL = r'http://(?:\w+\.)?add-anime\.net/(?:watch_video\.php\?(?:.*?)v=|video/)(?P<id>[\w_]+)' |
a35099bd | 20 | _TESTS = [{ |
f847ca02 PH |
21 | 'url': 'http://www.add-anime.net/watch_video.php?v=24MR3YO5SAS9', |
22 | 'md5': '72954ea10bc979ab5e2eb288b21425a0', | |
23 | 'info_dict': { | |
24 | 'id': '24MR3YO5SAS9', | |
25 | 'ext': 'mp4', | |
26 | 'description': 'One Piece 606', | |
27 | 'title': 'One Piece 606', | |
4f5f18ac | 28 | } |
a35099bd S |
29 | }, { |
30 | 'url': 'http://add-anime.net/video/MDUGWYKNGBD8/One-Piece-687', | |
31 | 'only_matching': True, | |
32 | }] | |
4f5f18ac PH |
33 | |
34 | def _real_extract(self, url): | |
e0938e77 PH |
35 | video_id = self._match_id(url) |
36 | ||
4f5f18ac | 37 | try: |
4f5f18ac PH |
38 | webpage = self._download_webpage(url, video_id) |
39 | except ExtractorError as ee: | |
77d0a82f PH |
40 | if not isinstance(ee.cause, compat_HTTPError) or \ |
41 | ee.cause.code != 503: | |
4f5f18ac PH |
42 | raise |
43 | ||
44 | redir_webpage = ee.cause.read().decode('utf-8') | |
45 | action = self._search_regex( | |
46 | r'<form id="challenge-form" action="([^"]+)"', | |
f847ca02 | 47 | redir_webpage, 'Redirect form') |
4f5f18ac PH |
48 | vc = self._search_regex( |
49 | r'<input type="hidden" name="jschl_vc" value="([^"]+)"/>', | |
f847ca02 | 50 | redir_webpage, 'redirect vc value') |
4f5f18ac PH |
51 | av = re.search( |
52 | r'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);', | |
53 | redir_webpage) | |
54 | if av is None: | |
e0938e77 | 55 | raise ExtractorError('Cannot find redirect math task') |
4f5f18ac PH |
56 | av_res = int(av.group(1)) + int(av.group(2)) * int(av.group(3)) |
57 | ||
58 | parsed_url = compat_urllib_parse_urlparse(url) | |
59 | av_val = av_res + len(parsed_url.netloc) | |
60 | confirm_url = ( | |
f847ca02 | 61 | parsed_url.scheme + '://' + parsed_url.netloc + |
4f5f18ac PH |
62 | action + '?' + |
63 | compat_urllib_parse.urlencode({ | |
64 | 'jschl_vc': vc, 'jschl_answer': compat_str(av_val)})) | |
65 | self._download_webpage( | |
66 | confirm_url, video_id, | |
f847ca02 | 67 | note='Confirming after redirect') |
4f5f18ac PH |
68 | webpage = self._download_webpage(url, video_id) |
69 | ||
beb10f84 S |
70 | FORMATS = ('normal', 'hq') |
71 | quality = qualities(FORMATS) | |
77d0a82f | 72 | formats = [] |
beb10f84 | 73 | for format_id in FORMATS: |
77d0a82f | 74 | rex = r"var %s_video_file = '(.*?)';" % re.escape(format_id) |
f847ca02 | 75 | video_url = self._search_regex(rex, webpage, 'video file URLx', |
77d0a82f PH |
76 | fatal=False) |
77 | if not video_url: | |
78 | continue | |
79 | formats.append({ | |
80 | 'format_id': format_id, | |
81 | 'url': video_url, | |
beb10f84 | 82 | 'quality': quality(format_id), |
77d0a82f | 83 | }) |
f847ca02 | 84 | self._sort_formats(formats) |
4f5f18ac PH |
85 | video_title = self._og_search_title(webpage) |
86 | video_description = self._og_search_description(webpage) | |
87 | ||
88 | return { | |
89 | '_type': 'video', | |
f847ca02 | 90 | 'id': video_id, |
77d0a82f | 91 | 'formats': formats, |
4f5f18ac PH |
92 | 'title': video_title, |
93 | 'description': video_description | |
94 | } |