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