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