]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/veoh.py
debian/{compat,control}: Update compat to 10.
[youtubedl] / youtube_dl / extractor / veoh.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 ExtractorError,
10 sanitized_Request,
11 )
12
13
14 class VeohIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?veoh\.com/(?:watch|iphone/#_Watch)/(?P<id>(?:v|e|yapi-)[\da-zA-Z]+)'
16
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. ',
26 },
27 }, {
28 'url': 'http://www.veoh.com/watch/v27701988pbTc4wzN?h1=Chile+workers+cover+up+to+avoid+skin+damage',
29 'md5': '4a6ff84b87d536a6a71e6aa6c0ad07fa',
30 'info_dict': {
31 'id': '27701988',
32 'ext': 'mp4',
33 'title': 'Chile workers cover up to avoid skin damage',
34 'description': 'md5:2bd151625a60a32822873efc246ba20d',
35 'uploader': 'afp-news',
36 'duration': 123,
37 },
38 'skip': 'This video has been deleted.',
39 }, {
40 'url': 'http://www.veoh.com/watch/v69525809F6Nc4frX',
41 'md5': '4fde7b9e33577bab2f2f8f260e30e979',
42 'note': 'Embedded ooyala video',
43 'info_dict': {
44 'id': '69525809',
45 'ext': 'mp4',
46 'title': 'Doctors Alter Plan For Preteen\'s Weight Loss Surgery',
47 'description': 'md5:f5a11c51f8fb51d2315bca0937526891',
48 'uploader': 'newsy-videos',
49 },
50 'skip': 'This video has been deleted.',
51 }, {
52 'url': 'http://www.veoh.com/watch/e152215AJxZktGS',
53 'only_matching': True,
54 }]
55
56 def _extract_formats(self, source):
57 formats = []
58 link = source.get('aowPermalink')
59 if link:
60 formats.append({
61 'url': link,
62 'ext': 'mp4',
63 'format_id': 'aow',
64 })
65 link = source.get('fullPreviewHashLowPath')
66 if link:
67 formats.append({
68 'url': link,
69 'format_id': 'low',
70 })
71 link = source.get('fullPreviewHashHighPath')
72 if link:
73 formats.append({
74 'url': link,
75 'format_id': 'high',
76 })
77 return formats
78
79 def _extract_video(self, source):
80 return {
81 'id': source.get('videoId'),
82 'title': source.get('title'),
83 'description': source.get('description'),
84 'thumbnail': source.get('highResImage') or source.get('medResImage'),
85 'uploader': source.get('username'),
86 'duration': int_or_none(source.get('length')),
87 'view_count': int_or_none(source.get('views')),
88 'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0,
89 'formats': self._extract_formats(source),
90 }
91
92 def _real_extract(self, url):
93 mobj = re.match(self._VALID_URL, url)
94 video_id = mobj.group('id')
95
96 if video_id.startswith('v'):
97 rsp = self._download_xml(
98 r'http://www.veoh.com/api/findByPermalink?permalink=%s' % video_id, video_id, 'Downloading video XML')
99 stat = rsp.get('stat')
100 if stat == 'ok':
101 return self._extract_video(rsp.find('./videoList/video'))
102 elif stat == 'fail':
103 raise ExtractorError(
104 '%s said: %s' % (self.IE_NAME, rsp.find('./errorList/error').get('errorMessage')), expected=True)
105
106 webpage = self._download_webpage(url, video_id)
107 age_limit = 0
108 if 'class="adultwarning-container"' in webpage:
109 self.report_age_confirmation()
110 age_limit = 18
111 request = sanitized_Request(url)
112 request.add_header('Cookie', 'confirmedAdult=true')
113 webpage = self._download_webpage(request, video_id)
114
115 m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|"|\?)', webpage)
116 if m_youtube is not None:
117 youtube_id = m_youtube.group(1)
118 self.to_screen('%s: detected Youtube video.' % video_id)
119 return self.url_result(youtube_id, 'Youtube')
120
121 info = json.loads(
122 self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info').replace('\\\'', '\''))
123
124 video = self._extract_video(info)
125 video['age_limit'] = age_limit
126
127 return video