mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-27 06:10:38 +01:00
[Nuvid] Use site JSON for video details (#29332)
Back-port yt-dlp PR 1022 onto PR #17890 and update Video details aren't in the original HTML now but populated by async JS Co-authored by: u-spec-png Co-authored by: vidaritos
This commit is contained in:
parent
47b0c8697a
commit
825d3426c5
|
@ -1,71 +1,113 @@
|
||||||
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..compat import compat_str
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
parse_duration,
|
parse_duration,
|
||||||
|
int_or_none,
|
||||||
|
try_get,
|
||||||
|
url_or_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
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,
|
'format_id': '360p',
|
||||||
|
'duration': 321.0,
|
||||||
'age_limit': 18,
|
'age_limit': 18,
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'thumbnails': list,
|
||||||
}
|
}
|
||||||
}
|
}, {
|
||||||
|
'url': 'https://m.nuvid.com/video/6523263',
|
||||||
|
'md5': 'ebd22ce8e47e1d9a4d0756a15c67da52',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '6523263',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'Slut brunette college student anal dorm',
|
||||||
|
'format_id': '720p',
|
||||||
|
'duration': 421.0,
|
||||||
|
'age_limit': 18,
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'thumbnails': list,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
'url': 'http://m.nuvid.com/video/6415801/',
|
||||||
|
'md5': '638d5ececb138d5753593f751ae3f697',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '6415801',
|
||||||
|
'ext': 'mp4',
|
||||||
|
'title': 'My best friend wanted to fuck my wife for a long time',
|
||||||
|
'format_id': '720p',
|
||||||
|
'duration': 1882,
|
||||||
|
'age_limit': 18,
|
||||||
|
'thumbnail': r're:https?://.+\.jpg',
|
||||||
|
'thumbnails': list,
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
|
||||||
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 = {
|
||||||
|
'lq': '360p',
|
||||||
|
'hq': '720p',
|
||||||
|
}
|
||||||
|
|
||||||
|
json_url = 'https://www.nuvid.com/player_config_json/?vid={video_id}&aid=0&domain_id=0&embed=0&check_speed=0'.format(**locals())
|
||||||
|
video_data = self._download_json(
|
||||||
|
json_url, video_id, headers={
|
||||||
|
'Accept': 'application/json, text/javascript, */*; q = 0.01',
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
|
||||||
|
}) or {}
|
||||||
|
|
||||||
|
# nice to have, not required
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(
|
||||||
page_url, video_id, 'Downloading video page')
|
'http://m.nuvid.com/video/%s' % (video_id, ),
|
||||||
# When dwnld_speed exists and has a value larger than the MP4 file's
|
video_id, 'Downloading video page', fatal=False) or ''
|
||||||
# bitrate, Nuvid returns the MP4 URL
|
|
||||||
# It's unit is 100bytes/millisecond, see mobile-nuvid-min.js for the algorithm
|
title = (
|
||||||
self._set_cookie('nuvid.com', 'dwnld_speed', '10.0')
|
try_get(video_data, lambda x: x['title'], compat_str)
|
||||||
mp4_webpage = self._download_webpage(
|
or self._html_search_regex(
|
||||||
page_url, video_id, 'Downloading video page for MP4 format')
|
(r'''<span\s[^>]*?\btitle\s*=\s*(?P<q>"|'|\b)(?P<title>[^"]+)(?P=q)\s*>''',
|
||||||
|
r'''<div\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)thumb-holder video(?P=q)>\s*<h5\b[^>]*>(?P<title>[^<]+)</h5''',
|
||||||
|
r'''<span\s[^>]*?\bclass\s*=\s*(?P<q>"|'|\b)title_thumb(?P=q)>(?P<title>[^<]+)</span'''),
|
||||||
|
webpage, 'title', group='title')).strip()
|
||||||
|
|
||||||
html5_video_re = r'(?s)<(?:video|audio)[^<]*(?:>.*?<source[^>]*)?\s+src=["\'](.*?)["\']',
|
|
||||||
video_url = self._html_search_regex(html5_video_re, webpage, video_id)
|
|
||||||
mp4_video_url = self._html_search_regex(html5_video_re, mp4_webpage, video_id)
|
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': video_url,
|
'url': source,
|
||||||
}]
|
'format_id': qualities.get(quality),
|
||||||
if mp4_video_url != video_url:
|
'height': int_or_none(qualities.get(quality)[:-1]),
|
||||||
formats.append({
|
} for quality, source in video_data.get('files').items() if source]
|
||||||
'url': mp4_video_url,
|
|
||||||
})
|
|
||||||
|
|
||||||
title = self._html_search_regex(
|
self._check_formats(formats, video_id)
|
||||||
[r'<span title="([^"]+)">',
|
self._sort_formats(formats)
|
||||||
r'<div class="thumb-holder video">\s*<h5[^>]*>([^<]+)</h5>',
|
|
||||||
r'<span[^>]+class="title_thumb">([^<]+)</span>'], webpage, 'title').strip()
|
duration = parse_duration(video_data.get('duration') or video_data.get('duration_format'))
|
||||||
thumbnails = [
|
thumbnails = [
|
||||||
{
|
{'url': thumb_url, }
|
||||||
'url': thumb_url,
|
for thumb_url in (
|
||||||
} for thumb_url in re.findall(r'<img src="([^"]+)" alt="" />', webpage)
|
url_or_none(src) for src in re.findall(
|
||||||
|
r'<div\s+class\s*=\s*"video-tmb-wrap"\s*>\s*<img\s+src\s*=\s*"([^"]+)"\s*/>',
|
||||||
|
webpage))
|
||||||
]
|
]
|
||||||
thumbnail = thumbnails[0]['url'] if thumbnails else None
|
|
||||||
duration = parse_duration(self._html_search_regex(
|
|
||||||
[r'<i class="fa fa-clock-o"></i>\s*(\d{2}:\d{2})',
|
|
||||||
r'<span[^>]+class="view_time">([^<]+)</span>'], webpage, 'duration', fatal=False))
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
|
'formats': formats,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
'thumbnail': url_or_none(video_data.get('poster')),
|
||||||
'thumbnails': thumbnails,
|
'thumbnails': thumbnails,
|
||||||
'thumbnail': thumbnail,
|
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'age_limit': 18,
|
'age_limit': 18,
|
||||||
'formats': formats,
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user