]>
Commit | Line | Data |
---|---|---|
f46f4a99 PH |
1 | from __future__ import unicode_literals |
2 | ||
99e350d9 JMF |
3 | import re |
4 | import json | |
5 | ||
6 | from .common import InfoExtractor | |
1cc79574 | 7 | from ..utils import ( |
b540697a | 8 | int_or_none, |
09ffa08b | 9 | ExtractorError, |
5c2266df | 10 | sanitized_Request, |
b540697a | 11 | ) |
f46f4a99 | 12 | |
99e350d9 JMF |
13 | |
14 | class VeohIE(InfoExtractor): | |
5886b38d | 15 | _VALID_URL = r'https?://(?:www\.)?veoh\.com/(?:watch|iphone/#_Watch)/(?P<id>(?:v|yapi-)[\da-zA-Z]+)' |
b540697a S |
16 | |
17 | _TESTS = [ | |
18 | { | |
19 | 'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3', | |
20 | 'md5': '620e68e6a3cff80086df3348426c9ca3', | |
21 | 'info_dict': { | |
22 | 'id': '56314296', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Straight Backs Are Stronger', | |
25 | 'uploader': 'LUMOback', | |
26 | '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. ', | |
27 | }, | |
28 | }, | |
29 | { | |
30 | 'url': 'http://www.veoh.com/watch/v27701988pbTc4wzN?h1=Chile+workers+cover+up+to+avoid+skin+damage', | |
31 | 'md5': '4a6ff84b87d536a6a71e6aa6c0ad07fa', | |
32 | 'info_dict': { | |
33 | 'id': '27701988', | |
34 | 'ext': 'mp4', | |
35 | 'title': 'Chile workers cover up to avoid skin damage', | |
36 | 'description': 'md5:2bd151625a60a32822873efc246ba20d', | |
37 | 'uploader': 'afp-news', | |
38 | 'duration': 123, | |
39 | }, | |
277c7465 | 40 | 'skip': 'This video has been deleted.', |
b540697a S |
41 | }, |
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', | |
52 | }, | |
6e1e0e4b | 53 | 'skip': 'This video has been deleted.', |
b540697a S |
54 | }, |
55 | ] | |
56 | ||
57 | def _extract_formats(self, source): | |
58 | formats = [] | |
59 | link = source.get('aowPermalink') | |
60 | if link: | |
61 | formats.append({ | |
62 | 'url': link, | |
63 | 'ext': 'mp4', | |
64 | 'format_id': 'aow', | |
65 | }) | |
66 | link = source.get('fullPreviewHashLowPath') | |
67 | if link: | |
68 | formats.append({ | |
69 | 'url': link, | |
70 | 'format_id': 'low', | |
71 | }) | |
72 | link = source.get('fullPreviewHashHighPath') | |
73 | if link: | |
74 | formats.append({ | |
75 | 'url': link, | |
76 | 'format_id': 'high', | |
77 | }) | |
78 | return formats | |
79 | ||
80 | def _extract_video(self, source): | |
81 | return { | |
82 | 'id': source.get('videoId'), | |
83 | 'title': source.get('title'), | |
84 | 'description': source.get('description'), | |
85 | 'thumbnail': source.get('highResImage') or source.get('medResImage'), | |
86 | 'uploader': source.get('username'), | |
87 | 'duration': int_or_none(source.get('length')), | |
88 | 'view_count': int_or_none(source.get('views')), | |
89 | 'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0, | |
90 | 'formats': self._extract_formats(source), | |
99e350d9 | 91 | } |
99e350d9 JMF |
92 | |
93 | def _real_extract(self, url): | |
94 | mobj = re.match(self._VALID_URL, url) | |
95 | video_id = mobj.group('id') | |
b540697a S |
96 | |
97 | if video_id.startswith('v'): | |
98 | rsp = self._download_xml( | |
99 | r'http://www.veoh.com/api/findByPermalink?permalink=%s' % video_id, video_id, 'Downloading video XML') | |
09ffa08b S |
100 | stat = rsp.get('stat') |
101 | if stat == 'ok': | |
b540697a | 102 | return self._extract_video(rsp.find('./videoList/video')) |
09ffa08b S |
103 | elif stat == 'fail': |
104 | raise ExtractorError( | |
105 | '%s said: %s' % (self.IE_NAME, rsp.find('./errorList/error').get('errorMessage')), expected=True) | |
b540697a | 106 | |
99e350d9 | 107 | webpage = self._download_webpage(url, video_id) |
2bfe4ead JMF |
108 | age_limit = 0 |
109 | if 'class="adultwarning-container"' in webpage: | |
110 | self.report_age_confirmation() | |
111 | age_limit = 18 | |
5c2266df | 112 | request = sanitized_Request(url) |
2bfe4ead JMF |
113 | request.add_header('Cookie', 'confirmedAdult=true') |
114 | webpage = self._download_webpage(request, video_id) | |
99e350d9 | 115 | |
b540697a | 116 | m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|"|\?)', webpage) |
99e350d9 JMF |
117 | if m_youtube is not None: |
118 | youtube_id = m_youtube.group(1) | |
f46f4a99 | 119 | self.to_screen('%s: detected Youtube video.' % video_id) |
99e350d9 JMF |
120 | return self.url_result(youtube_id, 'Youtube') |
121 | ||
b540697a S |
122 | info = json.loads( |
123 | self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info').replace('\\\'', '\'')) | |
f46f4a99 | 124 | |
b540697a S |
125 | video = self._extract_video(info) |
126 | video['age_limit'] = age_limit | |
127 | ||
128 | return video |