]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/moniker.py
79bb2ca5935cb7ad888081540696e256c31faa98
[youtubedl] / youtube_dl / extractor / moniker.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import os.path
5 import re
6
7 from .common import InfoExtractor
8 from ..utils import (
9 compat_urllib_parse,
10 compat_urllib_request,
11 )
12
13
14 class MonikerIE(InfoExtractor):
15 IE_DESC = 'allmyvideos.net and vidspot.net'
16 _VALID_URL = r'https?://(?:www\.)?(?:allmyvideos|vidspot)\.net/(?P<id>[a-zA-Z0-9_-]+)'
17
18 _TESTS = [{
19 'url': 'http://allmyvideos.net/jih3nce3x6wn',
20 'md5': '710883dee1bfc370ecf9fa6a89307c88',
21 'info_dict': {
22 'id': 'jih3nce3x6wn',
23 'ext': 'mp4',
24 'title': 'youtube-dl test video',
25 },
26 }, {
27 'url': 'http://vidspot.net/l2ngsmhs8ci5',
28 'md5': '710883dee1bfc370ecf9fa6a89307c88',
29 'info_dict': {
30 'id': 'l2ngsmhs8ci5',
31 'ext': 'mp4',
32 'title': 'youtube-dl test video',
33 },
34 }, {
35 'url': 'https://www.vidspot.net/l2ngsmhs8ci5',
36 'only_matching': True,
37 }]
38
39 def _real_extract(self, url):
40 mobj = re.match(self._VALID_URL, url)
41 video_id = mobj.group('id')
42
43 orig_webpage = self._download_webpage(url, video_id)
44 fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
45 data = dict(fields)
46
47 post = compat_urllib_parse.urlencode(data)
48 headers = {
49 b'Content-Type': b'application/x-www-form-urlencoded',
50 }
51 req = compat_urllib_request.Request(url, post, headers)
52 webpage = self._download_webpage(
53 req, video_id, note='Downloading video page ...')
54
55 title = os.path.splitext(data['fname'])[0]
56
57 #Could be several links with different quality
58 links = re.findall(r'"file" : "?(.+?)",', webpage)
59 # Assume the links are ordered in quality
60 formats = [{
61 'url': l,
62 'quality': i,
63 } for i, l in enumerate(links)]
64 self._sort_formats(formats)
65
66 return {
67 'id': video_id,
68 'title': title,
69 'formats': formats,
70 }