]>
Commit | Line | Data |
---|---|---|
c11a0611 PH |
1 | from __future__ import unicode_literals |
2 | ||
8e4e89f1 JMF |
3 | import re |
4 | import json | |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..compat import ( |
8e4e89f1 | 8 | compat_urlparse, |
1cc79574 PH |
9 | ) |
10 | from ..utils import ( | |
d5bb814d | 11 | ExtractorError, |
8e4e89f1 | 12 | clean_html, |
1cc79574 | 13 | get_element_by_id, |
8e4e89f1 JMF |
14 | ) |
15 | ||
c11a0611 | 16 | |
8e4e89f1 | 17 | class VeeHDIE(InfoExtractor): |
c0ade33e | 18 | _VALID_URL = r'https?://veehd\.com/video/(?P<id>\d+)' |
8e4e89f1 | 19 | |
f7f1df1d YCH |
20 | # Seems VeeHD videos have multiple copies on several servers, all of |
21 | # whom have different MD5 checksums, so omit md5 field in all tests | |
22 | _TESTS = [{ | |
aa24de39 | 23 | 'url': 'http://veehd.com/video/4639434_Solar-Sinter', |
c11a0611 | 24 | 'info_dict': { |
aa24de39 | 25 | 'id': '4639434', |
df53b635 | 26 | 'ext': 'mp4', |
aa24de39 S |
27 | 'title': 'Solar Sinter', |
28 | 'uploader_id': 'VideoEyes', | |
29 | 'description': 'md5:46a840e8692ddbaffb5f81d9885cb457', | |
8e4e89f1 | 30 | }, |
f7f1df1d YCH |
31 | 'skip': 'Video deleted', |
32 | }, { | |
33 | 'url': 'http://veehd.com/video/4905758_Elysian-Fields-Channeling', | |
34 | 'info_dict': { | |
35 | 'id': '4905758', | |
36 | 'ext': 'mp4', | |
37 | 'title': 'Elysian Fields - Channeling', | |
38 | 'description': 'md5:360e4e95fdab58aefbea0f2a19e5604b', | |
39 | 'uploader_id': 'spotted', | |
40 | } | |
41 | }, { | |
482a1258 | 42 | 'url': 'http://veehd.com/video/2046729_2012-2009-DivX-Trailer', |
f7f1df1d | 43 | 'info_dict': { |
482a1258 | 44 | 'id': '2046729', |
f7f1df1d | 45 | 'ext': 'avi', |
482a1258 YCH |
46 | 'title': '2012 (2009) DivX Trailer', |
47 | 'description': 'md5:75435ee95255e6a9838ac6f6f3a2396b', | |
48 | 'uploader_id': 'Movie_Trailers', | |
f7f1df1d YCH |
49 | } |
50 | }] | |
8e4e89f1 JMF |
51 | |
52 | def _real_extract(self, url): | |
1cc79574 | 53 | video_id = self._match_id(url) |
8e4e89f1 | 54 | |
c11a0611 PH |
55 | # VeeHD seems to send garbage on the first request. |
56 | # See https://github.com/rg3/youtube-dl/issues/2102 | |
57 | self._download_webpage(url, video_id, 'Requesting webpage') | |
8e4e89f1 | 58 | webpage = self._download_webpage(url, video_id) |
d5bb814d S |
59 | |
60 | if 'This video has been removed<' in webpage: | |
61 | raise ExtractorError('Video %s has been removed' % video_id, expected=True) | |
62 | ||
c11a0611 PH |
63 | player_path = self._search_regex( |
64 | r'\$\("#playeriframe"\).attr\({src : "(.+?)"', | |
65 | webpage, 'player path') | |
8e4e89f1 | 66 | player_url = compat_urlparse.urljoin(url, player_path) |
c11a0611 PH |
67 | |
68 | self._download_webpage(player_url, video_id, 'Requesting player page') | |
69 | player_page = self._download_webpage( | |
70 | player_url, video_id, 'Downloading player page') | |
a798e64c | 71 | |
f7f1df1d YCH |
72 | video_url = None |
73 | ||
c11a0611 | 74 | config_json = self._search_regex( |
a798e64c S |
75 | r'value=\'config=({.+?})\'', player_page, 'config json', default=None) |
76 | ||
77 | if config_json: | |
78 | config = json.loads(config_json) | |
79 | video_url = compat_urlparse.unquote(config['clip']['url']) | |
f7f1df1d YCH |
80 | |
81 | if not video_url: | |
82 | video_url = self._html_search_regex( | |
83 | r'<embed[^>]+type="video/divx"[^>]+src="([^"]+)"', | |
84 | player_page, 'video url', default=None) | |
85 | ||
86 | if not video_url: | |
a798e64c S |
87 | iframe_src = self._search_regex( |
88 | r'<iframe[^>]+src="/?([^"]+)"', player_page, 'iframe url') | |
89 | iframe_url = 'http://veehd.com/%s' % iframe_src | |
90 | ||
91 | self._download_webpage(iframe_url, video_id, 'Requesting iframe page') | |
92 | iframe_page = self._download_webpage( | |
93 | iframe_url, video_id, 'Downloading iframe page') | |
94 | ||
95 | video_url = self._search_regex( | |
96 | r"file\s*:\s*'([^']+)'", iframe_page, 'video url') | |
8e4e89f1 | 97 | |
8e4e89f1 | 98 | title = clean_html(get_element_by_id('videoName', webpage).rpartition('|')[0]) |
a798e64c S |
99 | uploader_id = self._html_search_regex( |
100 | r'<a href="/profile/\d+">(.+?)</a>', | |
101 | webpage, 'uploader') | |
102 | thumbnail = self._search_regex( | |
103 | r'<img id="veehdpreview" src="(.+?)"', | |
104 | webpage, 'thumbnail') | |
105 | description = self._html_search_regex( | |
106 | r'<td class="infodropdown".*?<div>(.*?)<ul', | |
107 | webpage, 'description', flags=re.DOTALL) | |
8e4e89f1 JMF |
108 | |
109 | return { | |
110 | '_type': 'video', | |
111 | 'id': video_id, | |
112 | 'title': title, | |
113 | 'url': video_url, | |
8e4e89f1 JMF |
114 | 'uploader_id': uploader_id, |
115 | 'thumbnail': thumbnail, | |
116 | 'description': description, | |
117 | } |