Niyazi Suleymanov 2 months ago committed by GitHub
commit ef7ee94b67
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,7 +5,6 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
extract_attributes, extract_attributes,
int_or_none,
parse_duration, parse_duration,
parse_filesize, parse_filesize,
unified_timestamp, unified_timestamp,
@ -27,15 +26,15 @@ class NewgroundsIE(InfoExtractor):
'duration': 143, 'duration': 143,
}, },
}, { }, {
'url': 'https://www.newgrounds.com/portal/view/673111', 'url': 'https://www.newgrounds.com/portal/view/850292',
'md5': '3394735822aab2478c31b1004fe5e5bc', 'md5': 'bb7cacf45e1b4d648e2dac2d79284d67',
'info_dict': { 'info_dict': {
'id': '673111', 'id': '850292',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Dancin', 'title': 'Timeless (2021)',
'uploader': 'Squirrelman82', 'uploader': 'Kevuhn',
'timestamp': 1460256780, 'timestamp': 1657896960,
'upload_date': '20160410', 'upload_date': '20220715',
}, },
}, { }, {
# source format unavailable, additional mp4 formats # source format unavailable, additional mp4 formats
@ -44,7 +43,7 @@ class NewgroundsIE(InfoExtractor):
'id': '689400', 'id': '689400',
'ext': 'mp4', 'ext': 'mp4',
'title': 'ZTV News Episode 8', 'title': 'ZTV News Episode 8',
'uploader': 'BennettTheSage', 'uploader': 'ZONE-SAMA',
'timestamp': 1487965140, 'timestamp': 1487965140,
'upload_date': '20170224', 'upload_date': '20170224',
}, },
@ -58,40 +57,46 @@ class NewgroundsIE(InfoExtractor):
webpage = self._download_webpage(url, media_id) webpage = self._download_webpage(url, media_id)
title = self._html_search_regex( paths = url.split('/')
r'<title>([^>]+)</title>', webpage, 'title') if paths[-3] == 'audio':
isAudio = True
else:
isAudio = False
media_url = self._parse_json(self._search_regex( if isAudio:
r'"url"\s*:\s*("[^"]+"),', webpage, ''), media_id) media_url = self._parse_json(self._search_regex(
r'"url"\s*:\s*("[^"]+"),', webpage, ''), media_id)
formats = [{ uploader = self._html_search_regex(
'url': media_url, (r'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*Author\s*</em>',
'format_id': 'source', r'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage, 'uploader',
'quality': 1, fatal=False)
}]
max_resolution = int_or_none(self._search_regex( formats = [{
r'max_resolution["\']\s*:\s*(\d+)', webpage, 'max resolution', 'url': media_url,
default=None)) 'format_id': 'source',
if max_resolution: 'quality': 1,
url_base = media_url.rpartition('.')[0] }]
for resolution in (360, 720, 1080):
if resolution > max_resolution:
break
formats.append({
'url': '%s.%dp.mp4' % (url_base, resolution),
'format_id': '%dp' % resolution,
'height': resolution,
})
self._check_formats(formats, media_id) else:
self._sort_formats(formats) media_url = 'https://www.newgrounds.com/portal/video/' + media_id
media = self._download_json(media_url, media_id, headers={'X-Requested-With': 'XMLHttpRequest'})
uploader = media['author']
sources = media['sources']
uploader = self._html_search_regex( formats = []
(r'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*Author\s*</em>', for source in sources:
r'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage, 'uploader', for i in range(len(sources[source])):
fatal=False) formats.append({
'url': sources[source][i]['src'],
'format_id': source,
'height': int(source[:-2]) # 1080p -> 1080
})
title = self._html_search_regex(
r'<title>([^>]+)</title>', webpage, 'title')
timestamp = unified_timestamp(self._html_search_regex( timestamp = unified_timestamp(self._html_search_regex(
(r'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+</dd>\s*<dd>[^<]+)', (r'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+</dd>\s*<dd>[^<]+)',
r'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+)'), webpage, 'timestamp', r'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+)'), webpage, 'timestamp',
@ -99,7 +104,6 @@ class NewgroundsIE(InfoExtractor):
duration = parse_duration(self._search_regex( duration = parse_duration(self._search_regex(
r'(?s)<dd>\s*Song\s*</dd>\s*<dd>.+?</dd>\s*<dd>([^<]+)', webpage, r'(?s)<dd>\s*Song\s*</dd>\s*<dd>.+?</dd>\s*<dd>([^<]+)', webpage,
'duration', default=None)) 'duration', default=None))
filesize_approx = parse_filesize(self._html_search_regex( filesize_approx = parse_filesize(self._html_search_regex(
r'(?s)<dd>\s*Song\s*</dd>\s*<dd>(.+?)</dd>', webpage, 'filesize', r'(?s)<dd>\s*Song\s*</dd>\s*<dd>(.+?)</dd>', webpage, 'filesize',
default=None)) default=None))
@ -109,6 +113,9 @@ class NewgroundsIE(InfoExtractor):
if '<dd>Song' in webpage: if '<dd>Song' in webpage:
formats[0]['vcodec'] = 'none' formats[0]['vcodec'] = 'none'
self._check_formats(formats, media_id)
self._sort_formats(formats)
return { return {
'id': media_id, 'id': media_id,
'title': title, 'title': title,

Loading…
Cancel
Save