]>
Commit | Line | Data |
---|---|---|
49fa38ad NJ |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
3d2623a8 | 4 | from ..networking import Request |
49fa38ad | 5 | from ..utils import ( |
6024b0f2 | 6 | ExtractorError, |
6024b0f2 | 7 | urlencode_postdata, |
d0e8b3d5 | 8 | xpath_text, |
49fa38ad NJ |
9 | xpath_with_ns, |
10 | ) | |
11 | ||
12 | _x = lambda p: xpath_with_ns(p, {'xspf': 'http://xspf.org/ns/0/'}) | |
49fa38ad NJ |
13 | |
14 | ||
15 | class NosVideoIE(InfoExtractor): | |
16 | _VALID_URL = r'https?://(?:www\.)?nosvideo\.com/' + \ | |
ec85ded8 | 17 | r'(?:embed/|\?v=)(?P<id>[A-Za-z0-9]{12})/?' |
49fa38ad | 18 | _PLAYLIST_URL = 'http://nosvideo.com/xml/{xml_id:s}.xml' |
6024b0f2 | 19 | _FILE_DELETED_REGEX = r'<b>File Not Found</b>' |
49fa38ad | 20 | _TEST = { |
08d03730 NJ |
21 | 'url': 'http://nosvideo.com/?v=mu8fle7g7rpq', |
22 | 'md5': '6124ed47130d8be3eacae635b071e6b6', | |
49fa38ad | 23 | 'info_dict': { |
08d03730 | 24 | 'id': 'mu8fle7g7rpq', |
49fa38ad NJ |
25 | 'ext': 'mp4', |
26 | 'title': 'big_buck_bunny_480p_surround-fix.avi.mp4', | |
ec85ded8 | 27 | 'thumbnail': r're:^https?://.*\.jpg$', |
49fa38ad NJ |
28 | } |
29 | } | |
30 | ||
31 | def _real_extract(self, url): | |
1cc79574 | 32 | video_id = self._match_id(url) |
49fa38ad NJ |
33 | |
34 | fields = { | |
35 | 'id': video_id, | |
36 | 'op': 'download1', | |
37 | 'method_free': 'Continue to Video', | |
38 | } | |
3d2623a8 | 39 | req = Request(url, urlencode_postdata(fields)) |
40 | req.headers['Content-type'] = 'application/x-www-form-urlencoded' | |
49fa38ad NJ |
41 | webpage = self._download_webpage(req, video_id, |
42 | 'Downloading download page') | |
6024b0f2 NJ |
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 | ||
49fa38ad NJ |
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')) | |
d0e8b3d5 NJ |
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() | |
49fa38ad NJ |
61 | |
62 | formats = [{ | |
63 | 'format_id': 'sd', | |
64 | 'url': url, | |
49fa38ad NJ |
65 | }] |
66 | ||
67 | return { | |
68 | 'id': video_id, | |
69 | 'title': title, | |
70 | 'thumbnail': thumbnail, | |
71 | 'formats': formats, | |
72 | } |