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