mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-01 02:37:29 +01:00
[Nuvid] Fix extractor (#1022)
Fixes: https://github.com/ytdl-org/youtube-dl/issues/29886 Authored by: u-spec-png
This commit is contained in:
parent
09906f554d
commit
8f8e8eba24
@ -1,71 +1,73 @@
|
|||||||
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
int_or_none,
|
||||||
|
try_get,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NuvidIE(InfoExtractor):
|
class NuvidIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
|
_VALID_URL = r'https?://(?:www|m)\.nuvid\.com/video/(?P<id>[0-9]+)'
|
||||||
_TEST = {
|
_TESTS = [{
|
||||||
'url': 'http://m.nuvid.com/video/1310741/',
|
'url': 'https://www.nuvid.com/video/6513023/italian-babe',
|
||||||
'md5': 'eab207b7ac4fccfb4e23c86201f11277',
|
'md5': '772d2f8288f3d3c5c45f7a41761c7844',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '1310741',
|
'id': '6513023',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Horny babes show their awesome bodeis and',
|
'title': 'italian babe',
|
||||||
'duration': 129,
|
'duration': 321.0,
|
||||||
'age_limit': 18,
|
'age_limit': 18,
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
'url': 'https://m.nuvid.com/video/6523263',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '6523263',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'age_limit': 18,
|
||||||
|
'title': 'Slut brunette college student anal dorm',
|
||||||
}
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
|
|
||||||
page_url = 'http://m.nuvid.com/video/%s' % video_id
|
qualities = {
|
||||||
webpage = self._download_webpage(
|
'lq': '360p',
|
||||||
page_url, video_id, 'Downloading video page')
|
'hq': '720p',
|
||||||
# When dwnld_speed exists and has a value larger than the MP4 file's
|
}
|
||||||
# bitrate, Nuvid returns the MP4 URL
|
|
||||||
# It's unit is 100bytes/millisecond, see mobile-nuvid-min.js for the algorithm
|
|
||||||
self._set_cookie('nuvid.com', 'dwnld_speed', '10.0')
|
|
||||||
mp4_webpage = self._download_webpage(
|
|
||||||
page_url, video_id, 'Downloading video page for MP4 format')
|
|
||||||
|
|
||||||
html5_video_re = r'(?s)<(?:video|audio)[^<]*(?:>.*?<source[^>]*)?\s+src=["\'](.*?)["\']',
|
json_url = f'https://www.nuvid.com/player_config_json/?vid={video_id}&aid=0&domain_id=0&embed=0&check_speed=0'
|
||||||
video_url = self._html_search_regex(html5_video_re, webpage, video_id)
|
video_data = self._download_json(
|
||||||
mp4_video_url = self._html_search_regex(html5_video_re, mp4_webpage, video_id)
|
json_url, video_id, headers={
|
||||||
formats = [{
|
'Accept': 'application/json, text/javascript, */*; q = 0.01',
|
||||||
'url': video_url,
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||||
}]
|
|
||||||
if mp4_video_url != video_url:
|
|
||||||
formats.append({
|
|
||||||
'url': mp4_video_url,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
title = self._html_search_regex(
|
formats = [{
|
||||||
[r'<span title="([^"]+)">',
|
'url': source,
|
||||||
r'<div class="thumb-holder video">\s*<h5[^>]*>([^<]+)</h5>',
|
'format_id': qualities.get(quality),
|
||||||
r'<span[^>]+class="title_thumb">([^<]+)</span>'], webpage, 'title').strip()
|
'height': int_or_none(qualities.get(quality)[:-1]),
|
||||||
thumbnails = [
|
} for quality, source in video_data.get('files').items() if source]
|
||||||
{
|
|
||||||
'url': thumb_url,
|
self._check_formats(formats, video_id)
|
||||||
} for thumb_url in re.findall(r'<img src="([^"]+)" alt="" />', webpage)
|
self._sort_formats(formats)
|
||||||
]
|
|
||||||
thumbnail = thumbnails[0]['url'] if thumbnails else None
|
title = video_data.get('title')
|
||||||
duration = parse_duration(self._html_search_regex(
|
thumbnail_base_url = try_get(video_data, lambda x: x['thumbs']['url'])
|
||||||
[r'<i class="fa fa-clock-o"></i>\s*(\d{2}:\d{2})',
|
thumbnail_extension = try_get(video_data, lambda x: x['thumbs']['extension'])
|
||||||
r'<span[^>]+class="view_time">([^<]+)</span>'], webpage, 'duration', fatal=False))
|
thumbnail_id = self._search_regex(
|
||||||
|
r'/media/videos/tmb/6523263/preview/(/d+)' + thumbnail_extension, video_data.get('poster', ''), 'thumbnail id', default=19)
|
||||||
|
thumbnail = f'{thumbnail_base_url}player/{thumbnail_id}{thumbnail_extension}'
|
||||||
|
duration = parse_duration(video_data.get('duration') or video_data.get('duration_format'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
'formats': formats,
|
||||||
'title': title,
|
'title': title,
|
||||||
'thumbnails': thumbnails,
|
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'age_limit': 18,
|
'age_limit': 18,
|
||||||
'formats': formats,
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user