]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/veoh.py
[veoh] Allow to download videos with age protection (fixes #2455)
[yt-dlp.git] / youtube_dl / extractor / veoh.py
CommitLineData
f46f4a99
PH
1from __future__ import unicode_literals
2
99e350d9
JMF
3import re
4import json
5
6from .common import InfoExtractor
2bfe4ead 7from ..utils import compat_urllib_request
f46f4a99 8
99e350d9
JMF
9
10class VeohIE(InfoExtractor):
4ddba33f 11 _VALID_URL = r'http://(?:www\.)?veoh\.com/(?:watch|iphone/#_Watch)/v(?P<id>\d*)'
99e350d9
JMF
12
13 _TEST = {
f46f4a99
PH
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. ',
99e350d9
JMF
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)
2bfe4ead
JMF
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)
99e350d9
JMF
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)
f46f4a99 39 self.to_screen('%s: detected Youtube video.' % video_id)
99e350d9
JMF
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)
f46f4a99
PH
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'],
2bfe4ead 55 'age_limit': age_limit,
f46f4a99 56 }