]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/nuvid.py
[youtube:comments] Add more options for limiting number of comments extracted (#1626)
[yt-dlp.git] / yt_dlp / extractor / nuvid.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 parse_duration,
7 int_or_none,
8 try_get,
9 )
10
11
12 class NuvidIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
14 _TESTS = [{
15 'url': 'https://www.nuvid.com/video/6513023/italian-babe',
16 'md5': '772d2f8288f3d3c5c45f7a41761c7844',
17 'info_dict': {
18 'id': '6513023',
19 'ext': 'mp4',
20 'title': 'italian babe',
21 'duration': 321.0,
22 'age_limit': 18,
23 }
24 }, {
25 'url': 'https://m.nuvid.com/video/6523263',
26 'info_dict': {
27 'id': '6523263',
28 'ext': 'mp4',
29 'age_limit': 18,
30 'title': 'Slut brunette college student anal dorm',
31 }
32 }]
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
36
37 qualities = {
38 'lq': '360p',
39 'hq': '720p',
40 }
41
42 json_url = f'https://www.nuvid.com/player_config_json/?vid={video_id}&aid=0&domain_id=0&embed=0&check_speed=0'
43 video_data = self._download_json(
44 json_url, video_id, headers={
45 'Accept': 'application/json, text/javascript, */*; q = 0.01',
46 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
47 })
48
49 formats = [{
50 'url': source,
51 'format_id': qualities.get(quality),
52 'height': int_or_none(qualities.get(quality)[:-1]),
53 } for quality, source in video_data.get('files').items() if source]
54
55 self._check_formats(formats, video_id)
56 self._sort_formats(formats)
57
58 title = video_data.get('title')
59 thumbnail_base_url = try_get(video_data, lambda x: x['thumbs']['url'])
60 thumbnail_extension = try_get(video_data, lambda x: x['thumbs']['extension'])
61 thumbnail_id = self._search_regex(
62 r'/media/videos/tmb/6523263/preview/(/d+)' + thumbnail_extension, video_data.get('poster', ''), 'thumbnail id', default=19)
63 thumbnail = f'{thumbnail_base_url}player/{thumbnail_id}{thumbnail_extension}'
64 duration = parse_duration(video_data.get('duration') or video_data.get('duration_format'))
65
66 return {
67 'id': video_id,
68 'formats': formats,
69 'title': title,
70 'thumbnail': thumbnail,
71 'duration': duration,
72 'age_limit': 18,
73 }