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