[youtube] Fix extraction.
[youtube-dl] / youtube_dl / extractor / veoh.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..utils import (
5     int_or_none,
6     parse_duration,
7     qualities,
8 )
9
10
11 class VeohIE(InfoExtractor):
12     _VALID_URL = r'https?://(?:www\.)?veoh\.com/(?:watch|embed|iphone/#_Watch)/(?P<id>(?:v|e|yapi-)[\da-zA-Z]+)'
13
14     _TESTS = [{
15         'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3',
16         'md5': '9e7ecc0fd8bbee7a69fe38953aeebd30',
17         'info_dict': {
18             'id': 'v56314296nk7Zdmz3',
19             'ext': 'mp4',
20             'title': 'Straight Backs Are Stronger',
21             'uploader': 'LUMOback',
22             '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. ',
23         },
24     }, {
25         'url': 'http://www.veoh.com/embed/v56314296nk7Zdmz3',
26         'only_matching': True,
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_video(self, source):
57         return {
58             'id': source.get('videoId'),
59             'title': source.get('title'),
60             'description': source.get('description'),
61             'thumbnail': source.get('highResImage') or source.get('medResImage'),
62             'uploader': source.get('username'),
63             'duration': int_or_none(source.get('length')),
64             'view_count': int_or_none(source.get('views')),
65             'age_limit': 18 if source.get('isMature') == 'true' or source.get('isSexy') == 'true' else 0,
66             'formats': self._extract_formats(source),
67         }
68
69     def _real_extract(self, url):
70         video_id = self._match_id(url)
71         video = self._download_json(
72             'https://www.veoh.com/watch/getVideo/' + video_id,
73             video_id)['video']
74         title = video['title']
75
76         thumbnail_url = None
77         q = qualities(['HQ', 'Regular'])
78         formats = []
79         for f_id, f_url in video.get('src', {}).items():
80             if not f_url:
81                 continue
82             if f_id == 'poster':
83                 thumbnail_url = f_url
84             else:
85                 formats.append({
86                     'format_id': f_id,
87                     'quality': q(f_id),
88                     'url': f_url,
89                 })
90         self._sort_formats(formats)
91
92         return {
93             'id': video_id,
94             'title': title,
95             'description': video.get('description'),
96             'thumbnail': thumbnail_url,
97             'uploader': video.get('author', {}).get('nickname'),
98             'duration': int_or_none(video.get('lengthBySec')) or parse_duration(video.get('length')),
99             'view_count': int_or_none(video.get('views')),
100             'formats': formats,
101             'average_rating': int_or_none(video.get('rating')),
102             'comment_count': int_or_none(video.get('numOfComments')),
103         }