]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/nuvid.py
[misc] Add `hatch`, `ruff`, `pre-commit` and improve dev docs (#7409)
[yt-dlp.git] / yt_dlp / extractor / nuvid.py
CommitLineData
50e93e03 1import re
87724af7 2
749fe60c 3from .common import InfoExtractor
3048e82a 4from ..utils import (
8f8e8eba 5 int_or_none,
e897bd82 6 parse_duration,
50e93e03 7 strip_or_none,
8 traverse_obj,
9 url_or_none,
3048e82a 10)
749fe60c 11
87724af7 12
749fe60c 13class NuvidIE(InfoExtractor):
1cc79574 14 _VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
8f8e8eba 15 _TESTS = [{
16 'url': 'https://www.nuvid.com/video/6513023/italian-babe',
17 'md5': '772d2f8288f3d3c5c45f7a41761c7844',
18 'info_dict': {
19 'id': '6513023',
20 'ext': 'mp4',
21 'title': 'italian babe',
22 'duration': 321.0,
23 'age_limit': 18,
50e93e03 24 'thumbnail': r're:https?://.+\.jpg',
8f8e8eba 25 }
26 }, {
27 'url': 'https://m.nuvid.com/video/6523263',
50e93e03 28 'md5': 'ebd22ce8e47e1d9a4d0756a15c67da52',
87724af7 29 'info_dict': {
8f8e8eba 30 'id': '6523263',
87724af7 31 'ext': 'mp4',
8f8e8eba 32 'title': 'Slut brunette college student anal dorm',
50e93e03 33 'duration': 421.0,
34 'age_limit': 18,
35 'thumbnail': r're:https?://.+\.jpg',
36 'thumbnails': list,
37 }
38 }, {
39 'url': 'http://m.nuvid.com/video/6415801/',
40 'md5': '638d5ececb138d5753593f751ae3f697',
41 'info_dict': {
42 'id': '6415801',
43 'ext': 'mp4',
44 'title': 'My best friend wanted to fuck my wife for a long time',
45 'duration': 1882,
46 'age_limit': 18,
47 'thumbnail': r're:https?://.+\.jpg',
749fe60c 48 }
8f8e8eba 49 }]
749fe60c 50
51 def _real_extract(self, url):
1cc79574 52 video_id = self._match_id(url)
749fe60c 53
8f8e8eba 54 qualities = {
55 'lq': '360p',
56 'hq': '720p',
57 }
58
59 json_url = f'https://www.nuvid.com/player_config_json/?vid={video_id}&aid=0&domain_id=0&embed=0&check_speed=0'
60 video_data = self._download_json(
61 json_url, video_id, headers={
62 'Accept': 'application/json, text/javascript, */*; q = 0.01',
63 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
64 })
87724af7 65
50e93e03 66 webpage = self._download_webpage(
67 'http://m.nuvid.com/video/%s' % (video_id, ),
68 video_id, 'Downloading video page', fatal=False) or ''
69
70 title = strip_or_none(video_data.get('title') or self._html_search_regex(
71 (r'''<span\s[^>]*?\btitle\s*=\s*(?P<q>"|'|\b)(?P<title>[^"]+)(?P=q)\s*>''',
72 r'''<div\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)thumb-holder video(?P=q)>\s*<h5\b[^>]*>(?P<title>[^<]+)</h5''',
73 r'''<span\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)title_thumb(?P=q)>(?P<title>[^<]+)</span'''),
74 webpage, 'title', group='title'))
75
0cbcbdd8 76 formats = [{
8f8e8eba 77 'url': source,
78 'format_id': qualities.get(quality),
79 'height': int_or_none(qualities.get(quality)[:-1]),
80 } for quality, source in video_data.get('files').items() if source]
87724af7 81
8f8e8eba 82 self._check_formats(formats, video_id)
8f8e8eba 83
50e93e03 84 duration = parse_duration(traverse_obj(video_data, 'duration', 'duration_format'))
85 thumbnails = [
86 {'url': thumb_url} for thumb_url in re.findall(
87 r'<div\s+class\s*=\s*"video-tmb-wrap"\s*>\s*<img\s+src\s*=\s*"([^"]+)"\s*/>', webpage)
88 if url_or_none(thumb_url)]
89 if url_or_none(video_data.get('poster')):
90 thumbnails.append({'url': video_data['poster'], 'preference': 1})
87724af7
PH
91
92 return {
93 'id': video_id,
8f8e8eba 94 'formats': formats,
87724af7 95 'title': title,
50e93e03 96 'thumbnails': thumbnails,
3048e82a 97 'duration': duration,
87724af7 98 'age_limit': 18,
5f6a1245 99 }