]>
Commit | Line | Data |
---|---|---|
38349518 CR |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
e825c380 | 4 | import os.path |
38349518 CR |
5 | import re |
6 | ||
7 | from .common import InfoExtractor | |
1cc79574 | 8 | from ..compat import ( |
38349518 CR |
9 | compat_urllib_parse, |
10 | compat_urllib_request, | |
11 | ) | |
e206740f | 12 | from ..utils import ExtractorError |
38349518 CR |
13 | |
14 | ||
589d3d7c | 15 | class MonikerIE(InfoExtractor): |
0529eef5 | 16 | IE_DESC = 'allmyvideos.net and vidspot.net' |
37bfe8ac | 17 | _VALID_URL = r'https?://(?:www\.)?(?:allmyvideos|vidspot)\.net/(?P<id>[a-zA-Z0-9_-]+)' |
38349518 | 18 | |
0529eef5 | 19 | _TESTS = [{ |
38349518 | 20 | 'url': 'http://allmyvideos.net/jih3nce3x6wn', |
e825c380 | 21 | 'md5': '710883dee1bfc370ecf9fa6a89307c88', |
38349518 CR |
22 | 'info_dict': { |
23 | 'id': 'jih3nce3x6wn', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'youtube-dl test video', | |
26 | }, | |
0529eef5 PH |
27 | }, { |
28 | 'url': 'http://vidspot.net/l2ngsmhs8ci5', | |
29 | 'md5': '710883dee1bfc370ecf9fa6a89307c88', | |
30 | 'info_dict': { | |
31 | 'id': 'l2ngsmhs8ci5', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'youtube-dl test video', | |
34 | }, | |
37bfe8ac PH |
35 | }, { |
36 | 'url': 'https://www.vidspot.net/l2ngsmhs8ci5', | |
37 | 'only_matching': True, | |
0529eef5 | 38 | }] |
38349518 CR |
39 | |
40 | def _real_extract(self, url): | |
1cc79574 | 41 | video_id = self._match_id(url) |
7cdd5339 | 42 | orig_webpage = self._download_webpage(url, video_id) |
1cc79574 | 43 | |
2419a376 S |
44 | if '>File Not Found<' in orig_webpage: |
45 | raise ExtractorError('Video %s does not exist' % video_id, expected=True) | |
46 | ||
e206740f S |
47 | error = self._search_regex( |
48 | r'class="err">([^<]+)<', orig_webpage, 'error', default=None) | |
49 | if error: | |
50 | raise ExtractorError( | |
51 | '%s returned error: %s' % (self.IE_NAME, error), expected=True) | |
52 | ||
7cdd5339 | 53 | fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage) |
e825c380 | 54 | data = dict(fields) |
7cdd5339 CR |
55 | |
56 | post = compat_urllib_parse.urlencode(data) | |
57 | headers = { | |
58 | b'Content-Type': b'application/x-www-form-urlencoded', | |
59 | } | |
60 | req = compat_urllib_request.Request(url, post, headers) | |
e825c380 PH |
61 | webpage = self._download_webpage( |
62 | req, video_id, note='Downloading video page ...') | |
63 | ||
64 | title = os.path.splitext(data['fname'])[0] | |
7cdd5339 | 65 | |
5f6a1245 | 66 | # Could be several links with different quality |
7cdd5339 | 67 | links = re.findall(r'"file" : "?(.+?)",', webpage) |
e825c380 PH |
68 | # Assume the links are ordered in quality |
69 | formats = [{ | |
70 | 'url': l, | |
71 | 'quality': i, | |
72 | } for i, l in enumerate(links)] | |
73 | self._sort_formats(formats) | |
7cdd5339 CR |
74 | |
75 | return { | |
76 | 'id': video_id, | |
e825c380 PH |
77 | 'title': title, |
78 | 'formats': formats, | |
79 | } |