]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | sanitized_Request, | |
7 | urlencode_postdata, | |
8 | xpath_text, | |
9 | xpath_with_ns, | |
10 | ) | |
11 | ||
12 | _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'}) | |
13 | ||
14 | ||
15 | class NosVideoIE(InfoExtractor): | |
16 | _VALID_URL = r'https?://(?:www\.)?nosvideo\.com/' + \ | |
17 | r'(?:embed/|\?v=)(?P<id>[A-Za-z0-9]{12})/?' | |
18 | _PLAYLIST_URL = 'http://nosvideo.com/xml/{xml_id:s}.xml' | |
19 | _FILE_DELETED_REGEX = r'<b>File Not Found</b>' | |
20 | _TEST = { | |
21 | 'url': 'http://nosvideo.com/?v=mu8fle7g7rpq', | |
22 | 'md5': '6124ed47130d8be3eacae635b071e6b6', | |
23 | 'info_dict': { | |
24 | 'id': 'mu8fle7g7rpq', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'big_buck_bunny_480p_surround-fix.avi.mp4', | |
27 | 'thumbnail': r're:^https?://.*\.jpg$', | |
28 | } | |
29 | } | |
30 | ||
31 | def _real_extract(self, url): | |
32 | video_id = self._match_id(url) | |
33 | ||
34 | fields = { | |
35 | 'id': video_id, | |
36 | 'op': 'download1', | |
37 | 'method_free': 'Continue to Video', | |
38 | } | |
39 | req = sanitized_Request(url, urlencode_postdata(fields)) | |
40 | req.add_header('Content-type', 'application/x-www-form-urlencoded') | |
41 | webpage = self._download_webpage(req, video_id, | |
42 | 'Downloading download page') | |
43 | if re.search(self._FILE_DELETED_REGEX, webpage) is not None: | |
44 | raise ExtractorError('Video %s does not exist' % video_id, | |
45 | expected=True) | |
46 | ||
47 | xml_id = self._search_regex(r'php\|([^\|]+)\|', webpage, 'XML ID') | |
48 | playlist_url = self._PLAYLIST_URL.format(xml_id=xml_id) | |
49 | playlist = self._download_xml(playlist_url, video_id) | |
50 | ||
51 | track = playlist.find(_x('.//xspf:track')) | |
52 | if track is None: | |
53 | raise ExtractorError( | |
54 | 'XML playlist is missing the \'track\' element', | |
55 | expected=True) | |
56 | title = xpath_text(track, _x('./xspf:title'), 'title') | |
57 | url = xpath_text(track, _x('./xspf:file'), 'URL', fatal=True) | |
58 | thumbnail = xpath_text(track, _x('./xspf:image'), 'thumbnail') | |
59 | if title is not None: | |
60 | title = title.strip() | |
61 | ||
62 | formats = [{ | |
63 | 'format_id': 'sd', | |
64 | 'url': url, | |
65 | }] | |
66 | ||
67 | return { | |
68 | 'id': video_id, | |
69 | 'title': title, | |
70 | 'thumbnail': thumbnail, | |
71 | 'formats': formats, | |
72 | } |