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