]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/newgrounds.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
19 class NewgroundsIE(InfoExtractor
):
20 _VALID_URL
= r
'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>\d+)(?:/format/flash)?'
22 'url': 'https://www.newgrounds.com/audio/listen/549479',
23 'md5': 'fe6033d297591288fa1c1f780386f07a',
27 'title': 'B7 - BusMode',
29 'timestamp': 1378878540,
30 'upload_date': '20130911',
32 'description': 'md5:6d885138814015dfd656c2ddb00dacfc',
35 'url': 'https://www.newgrounds.com/portal/view/1',
36 'md5': 'fbfb40e2dc765a7e830cb251d370d981',
41 'uploader': 'Brian-Beaton',
42 'timestamp': 955064100,
43 'upload_date': '20000406',
44 'description': 'Scrotum plays "catch."',
47 # source format unavailable, additional mp4 formats
48 'url': 'http://www.newgrounds.com/portal/view/689400',
52 'title': 'ZTV News Episode 8',
53 'uploader': 'ZONE-SAMA',
54 'timestamp': 1487965140,
55 'upload_date': '20170224',
56 'description': 'ZTV News Episode 8 (February 2017)',
59 'skip_download': True,
62 'url': 'https://www.newgrounds.com/portal/view/297383',
63 'md5': '2c11f5fd8cb6b433a63c89ba3141436c',
67 'title': 'Metal Gear Awesome',
68 'uploader': 'Egoraptor',
69 'timestamp': 1140663240,
70 'upload_date': '20060223',
71 'description': 'Metal Gear is awesome is so is this movie.',
74 'url': 'https://www.newgrounds.com/portal/view/297383/format/flash',
75 'md5': '5d05585a9a0caca059f5abfbd3865524',
79 'title': 'Metal Gear Awesome',
80 'description': 'Metal Gear is awesome is so is this movie.',
81 'uploader': 'Egoraptor',
82 'upload_date': '20060223',
83 'timestamp': 1140663240,
87 def _real_extract(self
, url
):
88 media_id
= self
._match
_id
(url
)
91 webpage
= self
._download
_webpage
(url
, media_id
)
93 title
= self
._html
_search
_regex
(
94 r
'<title>(.+?)</title>', webpage
, 'title')
96 media_url_string
= self
._search
_regex
(
97 r
'"url"\s*:\s*("[^"]+"),', webpage
, 'media url', default
=None)
100 media_url
= self
._parse
_json
(media_url_string
, media_id
)
103 'format_id': 'source',
107 json_video
= self
._download
_json
('https://www.newgrounds.com/portal/video/' + media_id
, media_id
, headers
={
108 'Accept': 'application/json',
110 'X-Requested-With': 'XMLHttpRequest'
113 uploader
= json_video
.get('author')
114 media_formats
= json_video
.get('sources', [])
115 for media_format
in media_formats
:
116 media_sources
= media_formats
[media_format
]
117 for source
in media_sources
:
119 'format_id': media_format
,
120 'quality': int_or_none(media_format
[:-1]),
121 'url': source
.get('src')
125 uploader
= self
._html
_search
_regex
(
126 (r
'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*(?:Author|Artist)\s*</em>',
127 r
'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage
, 'uploader',
130 timestamp
= unified_timestamp(self
._html
_search
_regex
(
131 (r
'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+</dd>\s*<dd>[^<]+)',
132 r
'<dt>\s*Uploaded\s*</dt>\s*<dd>([^<]+)'), webpage
, 'timestamp',
134 duration
= parse_duration(self
._html
_search
_regex
(
135 r
'"duration"\s*:\s*["\']?
([\d
]+)["\']?,', webpage,
136 'duration', default=None))
138 view_count = parse_count(self._html_search_regex(
139 r'(?s)<dt>\s*(?:Views|Listens)\s*</dt>\s*<dd>([\d\.,]+)</dd>', webpage,
140 'view count', default=None))
142 filesize = int_or_none(self._html_search_regex(
143 r'"filesize
"\s*:\s*["\']?
([\d
]+)["\']?,', webpage, 'filesize',
146 video_type_description = self._html_search_regex(
147 r'"description
"\s*:\s*["\']?
([^
"\']+)["\']?
,', webpage, 'filesize
',
150 if len(formats) == 1:
151 formats[0]['filesize
'] = filesize
153 if video_type_description == 'Audio File
':
154 formats[0]['vcodec
'] = 'none
'
155 self._check_formats(formats, media_id)
156 self._sort_formats(formats)
161 'uploader
': uploader,
162 'timestamp
': timestamp,
163 'duration
': duration,
165 'thumbnail
': self._og_search_thumbnail(webpage),
166 'description
': self._og_search_description(webpage),
167 'view_count
': view_count,
171 class NewgroundsPlaylistIE(InfoExtractor):
172 IE_NAME = 'Newgrounds
:playlist
'
173 _VALID_URL = r'https?
://(?
:www\
.)?newgrounds\
.com
/(?
:collection|
[^
/]+/search
/[^
/]+)/(?P
<id>[^
/?
#&]+)'
175 'url': 'https://www.newgrounds.com/collection/cats',
180 'playlist_mincount': 45,
182 'url': 'https://www.newgrounds.com/collection/dogs',
187 'playlist_mincount': 26,
189 'url': 'http://www.newgrounds.com/audio/search/title/cats',
190 'only_matching': True,
193 def _real_extract(self
, url
):
194 playlist_id
= self
._match
_id
(url
)
196 webpage
= self
._download
_webpage
(url
, playlist_id
)
198 title
= self
._search
_regex
(
199 r
'<title>([^>]+)</title>', webpage
, 'title', default
=None)
202 webpage
= self
._search
_regex
(
203 r
'(?s)<div[^>]+\bclass=["\']column
wide(.+)',
204 webpage, 'wide column
', default=webpage)
207 for a, path, media_id in re.findall(
208 r'(<a
[^
>]+\bhref
=["\'][^"\']+((?
:portal
/view|audio
/listen
)/(\d
+))[^
>]+>)',
210 a_class = extract_attributes(a).get('class')
211 if a_class not in ('item
-portalsubmission
', 'item
-audiosubmission
'):
215 f'https
://www
.newgrounds
.com
/{path}
',
216 ie=NewgroundsIE.ie_key(), video_id=media_id))
218 return self.playlist_result(entries, playlist_id, title)
221 class NewgroundsUserIE(InfoExtractor):
222 IE_NAME = 'Newgrounds
:user
'
223 _VALID_URL = r'https?
://(?P
<id>[^\
.]+)\
.newgrounds\
.com
/(?
:movies|audio
)/?
(?
:[#?]|$)'
225 'url': 'https://burn7.newgrounds.com/audio',
229 'playlist_mincount': 150,
231 'url': 'https://burn7.newgrounds.com/movies',
235 'playlist_mincount': 2,
237 'url': 'https://brian-beaton.newgrounds.com/movies',
239 'id': 'brian-beaton',
241 'playlist_mincount': 10,
245 def _fetch_page(self
, channel_id
, url
, page
):
247 posts_info
= self
._download
_json
(
248 f
'{url}/page/{page}', channel_id
,
249 note
=f
'Downloading page {page}', headers
={
250 'Accept': 'application/json, text/javascript, */*; q = 0.01',
251 'X-Requested-With': 'XMLHttpRequest',
253 sequence
= posts_info
.get('sequence', [])
254 for year
in sequence
:
255 posts
= try_get(posts_info
, lambda x
: x
['years'][str(year
)]['items'])
257 path
, media_id
= self
._search
_regex
(
258 r
'<a[^>]+\bhref=["\'][^
"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
259 post, 'url', group=(1, 2))
260 yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)
262 def _real_extract(self, url):
263 channel_id = self._match_id(url)
265 entries = OnDemandPagedList(functools.partial(
266 self._fetch_page, channel_id, url), self._PAGE_SIZE)
268 return self.playlist_result(entries, channel_id)