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