]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/veehd.py
Prepare for 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 ..compat import (
8 compat_urlparse,
9 )
10 from ..utils import (
11 ExtractorError,
12 clean_html,
13 get_element_by_id,
14 )
15
16
17 class VeeHDIE(InfoExtractor):
18 _VALID_URL = r'https?://veehd\.com/video/(?P<id>\d+)'
19
20 _TEST = {
21 'url': 'http://veehd.com/video/4639434_Solar-Sinter',
22 'info_dict': {
23 'id': '4639434',
24 'ext': 'mp4',
25 'title': 'Solar Sinter',
26 'uploader_id': 'VideoEyes',
27 'description': 'md5:46a840e8692ddbaffb5f81d9885cb457',
28 },
29 }
30
31 def _real_extract(self, url):
32 video_id = self._match_id(url)
33
34 # VeeHD seems to send garbage on the first request.
35 # See https://github.com/rg3/youtube-dl/issues/2102
36 self._download_webpage(url, video_id, 'Requesting webpage')
37 webpage = self._download_webpage(url, video_id)
38
39 if 'This video has been removed<' in webpage:
40 raise ExtractorError('Video %s has been removed' % video_id, expected=True)
41
42 player_path = self._search_regex(
43 r'\$\("#playeriframe"\).attr\({src : "(.+?)"',
44 webpage, 'player path')
45 player_url = compat_urlparse.urljoin(url, player_path)
46
47 self._download_webpage(player_url, video_id, 'Requesting player page')
48 player_page = self._download_webpage(
49 player_url, video_id, 'Downloading player page')
50
51 config_json = self._search_regex(
52 r'value=\'config=({.+?})\'', player_page, 'config json', default=None)
53
54 if config_json:
55 config = json.loads(config_json)
56 video_url = compat_urlparse.unquote(config['clip']['url'])
57 else:
58 iframe_src = self._search_regex(
59 r'<iframe[^>]+src="/?([^"]+)"', player_page, 'iframe url')
60 iframe_url = 'http://veehd.com/%s' % iframe_src
61
62 self._download_webpage(iframe_url, video_id, 'Requesting iframe page')
63 iframe_page = self._download_webpage(
64 iframe_url, video_id, 'Downloading iframe page')
65
66 video_url = self._search_regex(
67 r"file\s*:\s*'([^']+)'", iframe_page, 'video url')
68
69 title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0])
70 uploader_id = self._html_search_regex(
71 r'<a href="/profile/\d+">(.+?)</a>',
72 webpage, 'uploader')
73 thumbnail = self._search_regex(
74 r'<img id="veehdpreview" src="(.+?)"',
75 webpage, 'thumbnail')
76 description = self._html_search_regex(
77 r'<td class="infodropdown".*?<div>(.*?)<ul',
78 webpage, 'description', flags=re.DOTALL)
79
80 return {
81 '_type': 'video',
82 'id': video_id,
83 'title': title,
84 'url': video_url,
85 'ext': 'mp4',
86 'uploader_id': uploader_id,
87 'thumbnail': thumbnail,
88 'description': description,
89 }