]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/veehd.py
debian/changelog: Annotate bugs being closed.
[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 'info_dict': {
20 'id': '4686958',
21 'ext': 'mp4',
22 'title': 'Time Lapse View from Space ( ISS)',
23 'uploader_id': 'spotted',
24 'description': 'md5:f0094c4cf3a72e22bc4e4239ef767ad7',
25 },
26 }
27
28 def _real_extract(self, url):
29 mobj = re.match(self._VALID_URL, url)
30 video_id = mobj.group('id')
31
32 # VeeHD seems to send garbage on the first request.
33 # See https://github.com/rg3/youtube-dl/issues/2102
34 self._download_webpage(url, video_id, 'Requesting webpage')
35 webpage = self._download_webpage(url, video_id)
36 player_path = self._search_regex(
37 r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
38 webpage, 'player path')
39 player_url = compat_urlparse.urljoin(url, player_path)
40
41 self._download_webpage(player_url, video_id, 'Requesting player page')
42 player_page = self._download_webpage(
43 player_url, video_id, 'Downloading player page')
44 config_json = self._search_regex(
45 r'value=\'config=({.+?})\'', player_page, 'config json')
46 config = json.loads(config_json)
47
48 video_url = compat_urlparse.unquote(config['clip']['url'])
49 title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
50 uploader_id = self._html_search_regex(r'<a href="/profile/\d+">(.+?)</a>',
51 webpage, 'uploader')
52 thumbnail = self._search_regex(r'<img id="veehdpreview" src="(.+?)"',
53 webpage, 'thumbnail')
54 description = self._html_search_regex(r'<td class="infodropdown".*?<div>(.*?)<ul',
55 webpage, 'description', flags=re.DOTALL)
56
57 return {
58 '_type': 'video',
59 'id': video_id,
60 'title': title,
61 'url': video_url,
62 'ext': 'mp4',
63 'uploader_id': uploader_id,
64 'thumbnail': thumbnail,
65 'description': description,
66 }