mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-16 21:25:45 +00:00
[Newgrounds] Apply suggestion
This commit is contained in:
parent
aa8433993f
commit
39681044bc
1 changed files with 36 additions and 31 deletions
|
@ -5,13 +5,11 @@ 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,
|
||||||
parse_count,
|
parse_count,
|
||||||
unified_timestamp,
|
unified_timestamp,
|
||||||
unified_strdate,
|
|
||||||
RegexNotFoundError,
|
|
||||||
ExtractorError,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +26,7 @@ class NewgroundsIE(InfoExtractor):
|
||||||
'timestamp': 1378878540,
|
'timestamp': 1378878540,
|
||||||
'upload_date': '20130911',
|
'upload_date': '20130911',
|
||||||
'duration': 143,
|
'duration': 143,
|
||||||
|
'description': 'Sonic blahblahblah I\'m late again SEPTEMBER 11TH: Busmode-The story of ants on a log. ',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.newgrounds.com/portal/view/297383',
|
'url': 'https://www.newgrounds.com/portal/view/297383',
|
||||||
|
@ -38,6 +37,7 @@ class NewgroundsIE(InfoExtractor):
|
||||||
'uploader': 'Egoraptor',
|
'uploader': 'Egoraptor',
|
||||||
'timestamp': 1140663240,
|
'timestamp': 1140663240,
|
||||||
'upload_date': '20060223',
|
'upload_date': '20060223',
|
||||||
|
'description': 'Metal Gear is awesome is so is this movie.',
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
# source format unavailable, additional mp4 formats
|
# source format unavailable, additional mp4 formats
|
||||||
|
@ -46,9 +46,10 @@ 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',
|
||||||
|
'description': 'ZTV News Episode 8 (February 2017)',
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True,
|
'skip_download': True,
|
||||||
|
@ -57,20 +58,18 @@ class NewgroundsIE(InfoExtractor):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
media_id = self._match_id(url)
|
media_id = self._match_id(url)
|
||||||
|
formats = []
|
||||||
|
uploader = None
|
||||||
|
|
||||||
webpage = self._download_webpage(url, media_id)
|
webpage = self._download_webpage(url, media_id)
|
||||||
|
|
||||||
title = self._html_search_regex(
|
title = self._html_search_regex(
|
||||||
r'<title>(.+?)</title>', webpage, 'title')
|
r'<title>(.+?)</title>', webpage, 'title')
|
||||||
|
|
||||||
try:
|
media_url_string = self._search_regex(r'"url"\s*:\s*("[^"]+"),', webpage, 'media url string', fatal=False, default=None)
|
||||||
media_url = self._parse_json(self._search_regex(
|
|
||||||
r'"url"\s*:\s*("[^"]+"),', webpage, ''), media_id)
|
|
||||||
except RegexNotFoundError or ExtractorError:
|
|
||||||
media_url = None
|
|
||||||
formats = []
|
|
||||||
|
|
||||||
if media_url:
|
if media_url_string:
|
||||||
|
media_url = self._parse_json(media_url_string, media_id)
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': media_url,
|
'url': media_url,
|
||||||
'format_id': 'source',
|
'format_id': 'source',
|
||||||
|
@ -81,32 +80,29 @@ class NewgroundsIE(InfoExtractor):
|
||||||
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
'Accept': 'application/json, text/javascript, */*; q=0.01',
|
||||||
'Accept-Encoding': 'gzip, deflate, br',
|
'Accept-Encoding': 'gzip, deflate, br',
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
'Connection': 'keep-alive',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for resolution in ('360p', '720p', '1080p'):
|
uploader = json_data.get('author')
|
||||||
if resolution in json_data['sources']:
|
media_formats = json_data.get('sources', [])
|
||||||
|
for media_format in media_formats:
|
||||||
|
media_sources = media_formats[media_format]
|
||||||
|
for source in media_sources:
|
||||||
formats.append({
|
formats.append({
|
||||||
'url': json_data['sources'][resolution][0]['src'],
|
'format_id': media_format,
|
||||||
'format_id': resolution,
|
'quality': int_or_none(media_format[:-1]),
|
||||||
'height': int(resolution[:-1]),
|
'url': source.get('src')
|
||||||
})
|
})
|
||||||
|
|
||||||
self._sort_formats(formats)
|
if not uploader:
|
||||||
|
|
||||||
uploader = self._html_search_regex(
|
uploader = self._html_search_regex(
|
||||||
(r'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*Author\s*</em>',
|
(r'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*Author\s*</em>',
|
||||||
r'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage, 'uploader',
|
r'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage, 'uploader',
|
||||||
fatal=False)
|
fatal=False)
|
||||||
|
|
||||||
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',
|
||||||
default=None)
|
default=None))
|
||||||
|
|
||||||
upload_date = unified_strdate(timestamp)
|
|
||||||
|
|
||||||
timestamp = unified_timestamp(timestamp)
|
|
||||||
|
|
||||||
thumbnail = self._og_search_thumbnail(webpage)
|
thumbnail = self._og_search_thumbnail(webpage)
|
||||||
|
|
||||||
|
@ -127,6 +123,9 @@ class NewgroundsIE(InfoExtractor):
|
||||||
|
|
||||||
if '<dd>Song' in webpage:
|
if '<dd>Song' in webpage:
|
||||||
formats[0]['vcodec'] = 'none'
|
formats[0]['vcodec'] = 'none'
|
||||||
|
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': media_id,
|
'id': media_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
|
@ -137,7 +136,6 @@ class NewgroundsIE(InfoExtractor):
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'view_count': view_count,
|
'view_count': view_count,
|
||||||
'upload_date': upload_date,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,6 +148,13 @@ class NewgroundsPlaylistIE(InfoExtractor):
|
||||||
'title': 'Cats',
|
'title': 'Cats',
|
||||||
},
|
},
|
||||||
'playlist_mincount': 45,
|
'playlist_mincount': 45,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.newgrounds.com/collection/dogs',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'dogs',
|
||||||
|
'title': 'Dogs',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 25,
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.newgrounds.com/audio/search/title/cats',
|
'url': 'http://www.newgrounds.com/audio/search/title/cats',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
|
@ -177,7 +182,7 @@ class NewgroundsPlaylistIE(InfoExtractor):
|
||||||
continue
|
continue
|
||||||
entries.append(
|
entries.append(
|
||||||
self.url_result(
|
self.url_result(
|
||||||
'https://www.newgrounds.com/' + path + '/' + media_id,
|
'https://www.newgrounds.com/%s/%s' % (path, media_id),
|
||||||
ie=NewgroundsIE.ie_key(), video_id=media_id))
|
ie=NewgroundsIE.ie_key(), video_id=media_id))
|
||||||
|
|
||||||
return self.playlist_result(entries, playlist_id, title)
|
return self.playlist_result(entries, playlist_id, title)
|
||||||
|
|
Loading…
Reference in a new issue