Merge remote-tracking branch 'origin/master'
[youtube-dl] / 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 compat_urllib_request
8
9
10 class VeohIE(InfoExtractor):
11     _VALID_URL = r'http://(?:www\.)?veoh\.com/(?:watch|iphone/#_Watch)/v(?P<id>\d*)'
12
13     _TEST = {
14         'url': 'http://www.veoh.com/watch/v56314296nk7Zdmz3',
15         'file': '56314296.mp4',
16         'md5': '620e68e6a3cff80086df3348426c9ca3',
17         'info_dict': {
18             'title': 'Straight Backs Are Stronger',
19             'uploader': 'LUMOback',
20             '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. ',
21         }
22     }
23
24     def _real_extract(self, url):
25         mobj = re.match(self._VALID_URL, url)
26         video_id = mobj.group('id')
27         webpage = self._download_webpage(url, video_id)
28         age_limit = 0
29         if 'class="adultwarning-container"' in webpage:
30             self.report_age_confirmation()
31             age_limit = 18
32             request = compat_urllib_request.Request(url)
33             request.add_header('Cookie', 'confirmedAdult=true')
34             webpage = self._download_webpage(request, video_id)
35
36         m_youtube = re.search(r'http://www\.youtube\.com/v/(.*?)(\&|")', webpage)
37         if m_youtube is not None:
38             youtube_id = m_youtube.group(1)
39             self.to_screen('%s: detected Youtube video.' % video_id)
40             return self.url_result(youtube_id, 'Youtube')
41
42         self.report_extraction(video_id)
43         info = self._search_regex(r'videoDetailsJSON = \'({.*?})\';', webpage, 'info')
44         info = json.loads(info)
45         video_url = info.get('fullPreviewHashHighPath') or info.get('fullPreviewHashLowPath')
46
47         return {
48             'id': info['videoId'],
49             'title': info['title'],
50             'url': video_url,
51             'uploader': info['username'],
52             'thumbnail': info.get('highResImage') or info.get('medResImage'),
53             'description': info['description'],
54             'view_count': info['views'],
55             'age_limit': age_limit,
56         }