]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/novamov.py
[thescene] Fix extraction and improve style (Closes #8978)
[yt-dlp.git] / youtube_dl / extractor / novamov.py
CommitLineData
cc253000 1from __future__ import unicode_literals
2
3import re
4
5from .common import InfoExtractor
5c2266df 6from ..compat import compat_urlparse
cc253000 7from ..utils import (
8 ExtractorError,
82393e2b
S
9 NO_DEFAULT,
10 encode_dict,
5c2266df 11 sanitized_Request,
82393e2b 12 urlencode_postdata,
cc253000 13)
14
10bff13a 15
ce78943a
S
16class NovaMovIE(InfoExtractor):
17 IE_NAME = 'novamov'
18 IE_DESC = 'NovaMov'
19
ee86e2c6 20 _VALID_URL_TEMPLATE = r'http://(?:(?:www\.)?%(host)s/(?:file|video|mobile/#/videos)/|(?:(?:embed|www)\.)%(host)s/embed\.php\?(?:.*?&)?v=)(?P<id>[a-z\d]{13})'
60ccc59a 21 _VALID_URL = _VALID_URL_TEMPLATE % {'host': 'novamov\.com'}
ce78943a
S
22
23 _HOST = 'www.novamov.com'
24
25 _FILE_DELETED_REGEX = r'This file no longer exists on our servers!</h2>'
47c7f3d9 26 _FILEKEY_REGEX = r'flashvars\.filekey=(?P<filekey>"?[^"]+"?);'
ce78943a
S
27 _TITLE_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>([^<]+)</h3>'
28 _DESCRIPTION_REGEX = r'(?s)<div class="v_tab blockborder rounded5" id="v_tab1">\s*<h3>[^<]+</h3><p>([^<]+)</p>'
47c7f3d9 29 _URL_TEMPLATE = 'http://%s/video/%s'
cc253000 30
31 _TEST = {
32 'url': 'http://www.novamov.com/video/4rurhn9x446jj',
cc253000 33 'md5': '7205f346a52bbeba427603ba10d4b935',
34 'info_dict': {
ce78943a
S
35 'id': '4rurhn9x446jj',
36 'ext': 'flv',
cc253000 37 'title': 'search engine optimization',
38 'description': 'search engine optimization is used to rank the web page in the google search engine'
90f479b6
PH
39 },
40 'skip': '"Invalid token" errors abound (in web interface as well as youtube-dl, there is nothing we can do about it.)'
cc253000 41 }
42
b5424acd
YCH
43 def _check_existence(self, webpage, video_id):
44 if re.search(self._FILE_DELETED_REGEX, webpage) is not None:
45 raise ExtractorError('Video %s does not exist' % video_id, expected=True)
46
cc253000 47 def _real_extract(self, url):
699ed30c 48 video_id = self._match_id(url)
cc253000 49
47c7f3d9 50 url = self._URL_TEMPLATE % (self._HOST, video_id)
cc253000 51
82393e2b
S
52 webpage = self._download_webpage(
53 url, video_id, 'Downloading video page')
cc253000 54
b5424acd 55 self._check_existence(webpage, video_id)
cc253000 56
82393e2b 57 def extract_filekey(default=NO_DEFAULT):
47c7f3d9 58 filekey = self._search_regex(
82393e2b 59 self._FILEKEY_REGEX, webpage, 'filekey', default=default)
47c7f3d9
YCH
60 if filekey is not default and (filekey[0] != '"' or filekey[-1] != '"'):
61 return self._search_regex(
eb0bdc2c 62 r'var\s+%s\s*=\s*"([^"]+)"' % re.escape(filekey), webpage, 'filekey', default=default)
47c7f3d9
YCH
63 else:
64 return filekey
82393e2b
S
65
66 filekey = extract_filekey(default=None)
67
68 if not filekey:
69 fields = self._hidden_inputs(webpage)
70 post_url = self._search_regex(
71 r'<form[^>]+action=(["\'])(?P<url>.+?)\1', webpage,
72 'post url', default=url, group='url')
73 if not post_url.startswith('http'):
74 post_url = compat_urlparse.urljoin(url, post_url)
5c2266df 75 request = sanitized_Request(
82393e2b
S
76 post_url, urlencode_postdata(encode_dict(fields)))
77 request.add_header('Content-Type', 'application/x-www-form-urlencoded')
78 request.add_header('Referer', post_url)
79 webpage = self._download_webpage(
80 request, video_id, 'Downloading continue to the video page')
b5424acd 81 self._check_existence(webpage, video_id)
82393e2b
S
82
83 filekey = extract_filekey()
84
85 title = self._html_search_regex(self._TITLE_REGEX, webpage, 'title', fatal=False)
86 description = self._html_search_regex(self._DESCRIPTION_REGEX, webpage, 'description', default='', fatal=False)
cc253000 87
10bff13a 88 api_response = self._download_webpage(
ce78943a
S
89 'http://%s/api/player.api.php?key=%s&file=%s' % (self._HOST, filekey, video_id), video_id,
90 'Downloading video api response')
cc253000 91
92 response = compat_urlparse.parse_qs(api_response)
93
94 if 'error_msg' in response:
ce78943a 95 raise ExtractorError('%s returned error: %s' % (self.IE_NAME, response['error_msg'][0]), expected=True)
cc253000 96
97 video_url = response['url'][0]
98
99 return {
100 'id': video_id,
101 'url': video_url,
102 'title': title,
103 'description': description
5f6a1245 104 }
33d152b6
S
105
106
36066dd3
S
107class WholeCloudIE(NovaMovIE):
108 IE_NAME = 'wholecloud'
109 IE_DESC = 'WholeCloud'
33d152b6 110
36066dd3 111 _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': '(?:wholecloud\.net|movshare\.(?:net|sx|ag))'}
33d152b6 112
36066dd3 113 _HOST = 'www.wholecloud.net'
33d152b6
S
114
115 _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
116 _TITLE_REGEX = r'<strong>Title:</strong> ([^<]+)</p>'
117 _DESCRIPTION_REGEX = r'<strong>Description:</strong> ([^<]+)</p>'
118
119 _TEST = {
36066dd3 120 'url': 'http://www.wholecloud.net/video/559e28be54d96',
33d152b6
S
121 'md5': 'abd31a2132947262c50429e1d16c1bfd',
122 'info_dict': {
123 'id': '559e28be54d96',
124 'ext': 'flv',
125 'title': 'dissapeared image',
126 'description': 'optical illusion dissapeared image magic illusion',
127 }
128 }
129
130
131class NowVideoIE(NovaMovIE):
132 IE_NAME = 'nowvideo'
133 IE_DESC = 'NowVideo'
134
135 _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'nowvideo\.(?:to|ch|ec|sx|eu|at|ag|co|li)'}
136
137 _HOST = 'www.nowvideo.to'
138
139 _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
33d152b6
S
140 _TITLE_REGEX = r'<h4>([^<]+)</h4>'
141 _DESCRIPTION_REGEX = r'</h4>\s*<p>([^<]+)</p>'
142
143 _TEST = {
6583c741
YCH
144 'url': 'http://www.nowvideo.sx/video/f1d6fce9a968b',
145 'md5': '12c82cad4f2084881d8bc60ee29df092',
33d152b6 146 'info_dict': {
6583c741 147 'id': 'f1d6fce9a968b',
33d152b6 148 'ext': 'flv',
6583c741 149 'title': 'youtubedl test video BaWjenozKc',
33d152b6 150 'description': 'Description',
f6abca50 151 },
33d152b6
S
152 }
153
154
155class VideoWeedIE(NovaMovIE):
156 IE_NAME = 'videoweed'
157 IE_DESC = 'VideoWeed'
158
159 _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'videoweed\.(?:es|com)'}
160
161 _HOST = 'www.videoweed.es'
162
163 _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
164 _TITLE_REGEX = r'<h1 class="text_shadow">([^<]+)</h1>'
47c7f3d9 165 _URL_TEMPLATE = 'http://%s/file/%s'
33d152b6
S
166
167 _TEST = {
168 'url': 'http://www.videoweed.es/file/b42178afbea14',
169 'md5': 'abd31a2132947262c50429e1d16c1bfd',
170 'info_dict': {
171 'id': 'b42178afbea14',
172 'ext': 'flv',
173 'title': 'optical illusion dissapeared image magic illusion',
174 'description': ''
175 },
176 }
636aa83e
S
177
178
179class CloudTimeIE(NovaMovIE):
180 IE_NAME = 'cloudtime'
181 IE_DESC = 'CloudTime'
182
183 _VALID_URL = NovaMovIE._VALID_URL_TEMPLATE % {'host': 'cloudtime\.to'}
184
185 _HOST = 'www.cloudtime.to'
186
187 _FILE_DELETED_REGEX = r'>This file no longer exists on our servers.<'
188 _TITLE_REGEX = r'<div[^>]+class=["\']video_det["\'][^>]*>\s*<strong>([^<]+)</strong>'
189
190 _TEST = None