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