]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/veehd.py
Finalize release.
[youtubedl] / youtube_dl / extractor / veehd.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import (
8 compat_urlparse,
9 get_element_by_id,
10 clean_html,
11 )
12
13
14 class VeeHDIE(InfoExtractor):
15 _VALID_URL = r'https?://veehd\.com/video/(?P<id>\d+)'
16
17 _TEST = {
18 'url': 'http://veehd.com/video/4686958',
19 'file': '4686958.mp4',
20 'info_dict': {
21 'title': 'Time Lapse View from Space ( ISS)',
22 'uploader_id': 'spotted',
23 'description': 'md5:f0094c4cf3a72e22bc4e4239ef767ad7',
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 # VeeHD seems to send garbage on the first request.
32 # See https://github.com/rg3/youtube-dl/issues/2102
33 self._download_webpage(url, video_id, 'Requesting webpage')
34 webpage = self._download_webpage(url, video_id)
35 player_path = self._search_regex(
36 r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
37 webpage, 'player path')
38 player_url = compat_urlparse.urljoin(url, player_path)
39
40 self._download_webpage(player_url, video_id, 'Requesting player page')
41 player_page = self._download_webpage(
42 player_url, video_id, 'Downloading player page')
43 config_json = self._search_regex(
44 r'value=\'config=({.+?})\'', player_page, 'config json')
45 config = json.loads(config_json)
46
47 video_url = compat_urlparse.unquote(config['clip']['url'])
48 title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
49 uploader_id = self._html_search_regex(r'<a href="/profile/\d+">(.+?)</a>',
50 webpage, 'uploader')
51 thumbnail = self._search_regex(r'<img id="veehdpreview" src="(.+?)"',
52 webpage, 'thumbnail')
53 description = self._html_search_regex(r'<td class="infodropdown".*?<div>(.*?)<ul',
54 webpage, 'description', flags=re.DOTALL)
55
56 return {
57 '_type': 'video',
58 'id': video_id,
59 'title': title,
60 'url': video_url,
61 'ext': 'mp4',
62 'uploader_id': uploader_id,
63 'thumbnail': thumbnail,
64 'description': description,
65 }