]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/addanime.py
82a785a19c34517c17da294ad64c1cbe7d22cba4
[youtubedl] / youtube_dl / extractor / addanime.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 compat_HTTPError,
6 compat_str,
7 compat_urllib_parse,
8 compat_urllib_parse_urlparse,
9
10 ExtractorError,
11 )
12
13
14 class AddAnimeIE(InfoExtractor):
15
16 _VALID_URL = r'^http://(?:\w+\.)?add-anime\.net/watch_video.php\?(?:.*?)v=(?P<video_id>[\w_]+)(?:.*)'
17 IE_NAME = u'AddAnime'
18 _TEST = {
19 u'url': u'http://www.add-anime.net/watch_video.php?v=24MR3YO5SAS9',
20 u'file': u'24MR3YO5SAS9.flv',
21 u'md5': u'1036a0e0cd307b95bd8a8c3a5c8cfaf1',
22 u'info_dict': {
23 u"description": u"One Piece 606",
24 u"title": u"One Piece 606"
25 }
26 }
27
28 def _real_extract(self, url):
29 try:
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):
35 raise
36
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')
44 av = re.search(
45 r'a\.value = ([0-9]+)[+]([0-9]+)[*]([0-9]+);',
46 redir_webpage)
47 if av is None:
48 raise ExtractorError(u'Cannot find redirect math task')
49 av_res = int(av.group(1)) + int(av.group(2)) * int(av.group(3))
50
51 parsed_url = compat_urllib_parse_urlparse(url)
52 av_val = av_res + len(parsed_url.netloc)
53 confirm_url = (
54 parsed_url.scheme + u'://' + parsed_url.netloc +
55 action + '?' +
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)
62
63 video_url = self._search_regex(r"var normal_video_file = '(.*?)';",
64 webpage, u'video file URL')
65 video_title = self._og_search_title(webpage)
66 video_description = self._og_search_description(webpage)
67
68 return {
69 '_type': 'video',
70 'id': video_id,
71 'url': video_url,
72 'ext': 'flv',
73 'title': video_title,
74 'description': video_description
75 }