]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/veoh.py
[pornhub:uservideos] Add support for new URLs (closes #17388)
[yt-dlp.git] / youtube_dl / extractor / veoh.py
CommitLineData
f46f4a99
PH
1from __future__ import unicode_literals
2
99e350d9
JMF
3import re
4import json
5
6from .common import InfoExtractor
1cc79574 7from ..utils import (
b540697a 8 int_or_none,
09ffa08b 9 ExtractorError,
5c2266df 10 sanitized_Request,
b540697a 11)
f46f4a99 12
99e350d9
JMF
13
14class VeohIE(InfoExtractor):
a072a12e 15 _VALID_URL = r'https?://(?:www\.)?veoh\.com/(?:watch|embed|iphone/#_Watch)/(?P<id>(?:v|e|yapi-)[\da-zA-Z]+)'
b540697a 16
15237fcd 17 _TESTS = [{
18 'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3',
19 'md5': '620e68e6a3cff80086df3348426c9ca3',
20 'info_dict': {
21 'id': '56314296',
22 'ext': 'mp4',
23 'title': 'Straight Backs Are Stronger',
24 'uploader': 'LUMOback',
25 'description': 'At LUMOback, we believe straight backs are stronger. The LUMOback Posture & Movement Sensor: It gently vibrates when you slouch, inspiring improved posture and mobility. Use the app to track your data and improve your posture over time. ',
b540697a 26 },
a072a12e
JS
27 }, {
28 'url': 'http://www.veoh.com/embed/v56314296nk7Zdmz3',
29 'only_matching': True,
15237fcd 30 }, {
31 'url': 'http://www.veoh.com/watch/v27701988pbTc4wzN?h1=Chile+workers+cover+up+to+avoid+skin+damage',
32 'md5': '4a6ff84b87d536a6a71e6aa6c0ad07fa',
33 'info_dict': {
34 'id': '27701988',
35 'ext': 'mp4',
36 'title': 'Chile workers cover up to avoid skin damage',
37 'description': 'md5:2bd151625a60a32822873efc246ba20d',
38 'uploader': 'afp-news',
39 'duration': 123,
b540697a 40 },
15237fcd 41 'skip': 'This video has been deleted.',
42 }, {
43 'url': 'http://www.veoh.com/watch/v69525809F6Nc4frX',
44 'md5': '4fde7b9e33577bab2f2f8f260e30e979',
45 'note': 'Embedded ooyala video',
46 'info_dict': {
47 'id': '69525809',
48 'ext': 'mp4',
49 'title': 'Doctors Alter Plan For Preteen\'s Weight Loss Surgery',
50 'description': 'md5:f5a11c51f8fb51d2315bca0937526891',
51 'uploader': 'newsy-videos',
b540697a 52 },
15237fcd 53 'skip': 'This video has been deleted.',
54 }, {
55 'url': 'http://www.veoh.com/watch/e152215AJxZktGS',
56 'only_matching': True,
57 }]
b540697a
S
58
59 def _extract_formats(self, source):
60 formats = []
61 link = source.get('aowPermalink')
62 if link:
63 formats.append({
64 'url': link,
65 'ext': 'mp4',
66 'format_id': 'aow',
67 })
68 link = source.get('fullPreviewHashLowPath')
69 if link:
70 formats.append({
71 'url': link,
72 'format_id': 'low',
73 })
74 link = source.get('fullPreviewHashHighPath')
75 if link:
76 formats.append({
77 'url': link,
78 'format_id': 'high',
79 })
80 return formats
81
82 def _extract_video(self, source):
83 return {
84 'id': source.get('videoId'),
85 'title': source.get('title'),
86 'description': source.get('description'),
87 'thumbnail': source.get('highResImage') or source.get('medResImage'),
88 'uploader': source.get('username'),
89 'duration': int_or_none(source.get('length')),
90 'view_count': int_or_none(source.get('views')),
91 'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0,
92 'formats': self._extract_formats(source),
99e350d9 93 }
99e350d9
JMF
94
95 def _real_extract(self, url):
96 mobj = re.match(self._VALID_URL, url)
97 video_id = mobj.group('id')
b540697a
S
98
99 if video_id.startswith('v'):
100 rsp = self._download_xml(
101 r'http://www.veoh.com/api/findByPermalink?permalink=%s' % video_id, video_id, 'Downloading video XML')
09ffa08b
S
102 stat = rsp.get('stat')
103 if stat == 'ok':
b540697a 104 return self._extract_video(rsp.find('./videoList/video'))
09ffa08b
S
105 elif stat == 'fail':
106 raise ExtractorError(
107 '%s said: %s' % (self.IE_NAME, rsp.find('./errorList/error').get('errorMessage')), expected=True)
b540697a 108
99e350d9 109 webpage = self._download_webpage(url, video_id)
2bfe4ead
JMF
110 age_limit = 0
111 if 'class="adultwarning-container"' in webpage:
112 self.report_age_confirmation()
113 age_limit = 18
5c2266df 114 request = sanitized_Request(url)
2bfe4ead
JMF
115 request.add_header('Cookie', 'confirmedAdult=true')
116 webpage = self._download_webpage(request, video_id)
99e350d9 117
b540697a 118 m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|"|\?)', webpage)
99e350d9
JMF
119 if m_youtube is not None:
120 youtube_id = m_youtube.group(1)
f46f4a99 121 self.to_screen('%s: detected Youtube video.' % video_id)
99e350d9
JMF
122 return self.url_result(youtube_id, 'Youtube')
123
b540697a
S
124 info = json.loads(
125 self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info').replace('\\\'', '\''))
f46f4a99 126
b540697a
S
127 video = self._extract_video(info)
128 video['age_limit'] = age_limit
129
130 return video