]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/allmyvideos.py
Added new host: allmyvideos.net
[youtube-dl] / youtube_dl / extractor / allmyvideos.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     compat_urllib_parse,
9     compat_urllib_request,
10 )
11
12
13 class AllmyvideosIE(InfoExtractor):
14     IE_NAME = 'allmyvideos.net'
15     _VALID_URL = r'https?://allmyvideos\.net/(?P<id>[a-zA-Z0-9_-]+)'
16
17     _TEST = {
18         'url': 'http://allmyvideos.net/jih3nce3x6wn',
19         'md5': '8f26c1e7102556a0d7f24306d32c2092',
20         'info_dict': {
21             'id': 'jih3nce3x6wn',
22             'ext': 'mp4',
23             'title': 'youtube-dl test video',
24         },
25     }
26
27     def _real_extract(self, url):
28                 mobj = re.match(self._VALID_URL, url)
29                 video_id = mobj.group('id')
30
31                 orig_webpage = self._download_webpage(url, video_id)
32                 fields = re.findall(r'type="hidden" name="(.+?)"\s* value="?(.+?)">', orig_webpage)
33                 data = {}
34                 for name, value in fields:
35                         data[name] = value
36
37                 post = compat_urllib_parse.urlencode(data)
38                 headers = {
39                         b'Content-Type': b'application/x-www-form-urlencoded',
40                 }
41                 req = compat_urllib_request.Request(url, post, headers)
42                 webpage = self._download_webpage(req, video_id, note='Downloading video page ...')
43
44                 #Could be several links with different quality
45                 links = re.findall(r'"file" : "?(.+?)",', webpage)
46
47                 return {
48                         'id': video_id,
49                         'title': data['fname'][:len(data['fname'])-4],  #Remove .mp4 extension
50                         'url': links[len(links)-1]                                              #Choose the higher quality link
51                 }