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