]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/newgrounds.py
4 from .common
import InfoExtractor
18 class NewgroundsIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>\d+)(?:/format/flash)?'
21 'url': 'https://www.newgrounds.com/audio/listen/549479',
22 'md5': 'fe6033d297591288fa1c1f780386f07a',
26 'title': 'B7 - BusMode',
28 'timestamp': 1378878540,
29 'upload_date': '20130911',
32 'description': 'md5:b8b3c2958875189f07d8e313462e8c4f',
35 'url': 'https://www.newgrounds.com/portal/view/1',
36 'md5': 'fbfb40e2dc765a7e830cb251d370d981',
41 'uploader': 'Brian-Beaton',
42 'timestamp': 955064100,
43 'upload_date': '20000406',
45 'description': 'Scrotum plays "catch."',
49 # source format unavailable, additional mp4 formats
50 'url': 'http://www.newgrounds.com/portal/view/689400',
54 'title': 'ZTV News Episode 8',
55 'uploader': 'ZONE-SAMA',
56 'timestamp': 1487965140,
57 'upload_date': '20170224',
59 'description': 'md5:aff9b330ec2e78ed93b1ad6d017accc6',
63 'skip_download': True,
66 'url': 'https://www.newgrounds.com/portal/view/297383',
67 'md5': '2c11f5fd8cb6b433a63c89ba3141436c',
71 'title': 'Metal Gear Awesome',
72 'uploader': 'Egoraptor',
73 'timestamp': 1140663240,
74 'upload_date': '20060223',
76 'description': 'md5:9246c181614e23754571995104da92e0',
80 'url': 'https://www.newgrounds.com/portal/view/297383/format/flash',
81 'md5': '5d05585a9a0caca059f5abfbd3865524',
85 'title': 'Metal Gear Awesome',
86 'description': 'Metal Gear Awesome',
87 'uploader': 'Egoraptor',
88 'upload_date': '20060223',
89 'timestamp': 1140663240,
100 def _real_extract(self
, url
):
101 media_id
= self
._match
_id
(url
)
104 webpage
= self
._download
_webpage
(url
, media_id
)
106 title
= self
._html
_extract
_title
(webpage
)
108 media_url_string
= self
._search
_regex
(
109 r
'"url"\s*:\s*("[^"]+"),', webpage
, 'media url', default
=None)
112 media_url
= self
._parse
_json
(media_url_string
, media_id
)
115 'format_id': 'source',
119 json_video
= self
._download
_json
('https://www.newgrounds.com/portal/video/' + media_id
, media_id
, headers
={
120 'Accept': 'application/json',
122 'X-Requested-With': 'XMLHttpRequest'
125 uploader
= json_video
.get('author')
126 media_formats
= json_video
.get('sources', [])
127 for media_format
in media_formats
:
128 media_sources
= media_formats
[media_format
]
129 for source
in media_sources
:
131 'format_id': media_format
,
132 'quality': int_or_none(media_format
[:-1]),
133 'url': source
.get('src')
137 uploader
= self
._html
_search
_regex
(
138 (r
'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*(?:Author|Artist)\s*</em>',
139 r
'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage
, 'uploader',
142 age_limit
= self
._html
_search
_regex
(
143 r
'<h2\s*class=["\']rated
-([^
"\'])["\'][^
>]+>', webpage, 'age_limit
', default='e
')
144 age_limit = self._AGE_LIMIT.get(age_limit)
146 timestamp = unified_timestamp(self._html_search_regex(
147 (r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+</dd
>\s
*<dd
>[^
<]+)',
148 r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+)'), webpage, 'timestamp
',
151 duration = parse_duration(self._html_search_regex(
152 r'"duration"\s
*:\s
*["\']?(\d+)["\']?
', webpage,
153 'duration
', default=None))
155 description = clean_html(get_element_by_id('author_comments
', webpage)) or self._og_search_description(webpage)
157 view_count = parse_count(self._html_search_regex(
158 r'(?s
)<dt
>\s
*(?
:Views|Listens
)\s
*</dt
>\s
*<dd
>([\d\
.,]+)</dd
>', webpage,
159 'view count
', default=None))
161 filesize = int_or_none(self._html_search_regex(
162 r'"filesize"\s
*:\s
*["\']?([\d]+)["\']?
,', webpage, 'filesize
',
165 video_type_description = self._html_search_regex(
166 r'"description"\s
*:\s
*["\']?([^"\']+)["\']?,', webpage, 'filesize',
169 if len(formats) == 1:
170 formats[0]['filesize'] = filesize
172 if video_type_description == 'Audio File':
173 formats[0]['vcodec'] = 'none'
174 self._check_formats(formats, media_id)
175 self._sort_formats(formats)
180 'uploader': uploader,
181 'timestamp': timestamp,
182 'duration': duration,
184 'thumbnail': self._og_search_thumbnail(webpage),
185 'description': description,
186 'age_limit': age_limit,
187 'view_count': view_count,
191 class NewgroundsPlaylistIE(InfoExtractor):
192 IE_NAME = 'Newgrounds:playlist'
193 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:collection|[^/]+/search/[^/]+)/(?P<id>[^/?#&]+)'
195 'url': 'https://www.newgrounds.com/collection/cats',
200 'playlist_mincount': 45,
202 'url': 'https://www.newgrounds.com/collection/dogs',
207 'playlist_mincount': 26,
209 'url': 'http://www.newgrounds.com/audio/search/title/cats',
210 'only_matching': True,
213 def _real_extract(self, url):
214 playlist_id = self._match_id(url)
216 webpage = self._download_webpage(url, playlist_id)
218 title = self._html_extract_title(webpage, default=None)
221 webpage = self._search_regex(
222 r'(?s)<div[^>]+\bclass=["\']column
wide(.+)',
223 webpage, 'wide column
', default=webpage)
226 for a, path, media_id in re.findall(
227 r'(<a
[^
>]+\bhref
=["\'][^"\']+((?
:portal
/view|audio
/listen
)/(\d
+))[^
>]+>)',
229 a_class = extract_attributes(a).get('class')
230 if a_class not in ('item
-portalsubmission
', 'item
-audiosubmission
'):
234 f'https
://www
.newgrounds
.com
/{path}
',
235 ie=NewgroundsIE.ie_key(), video_id=media_id))
237 return self.playlist_result(entries, playlist_id, title)
240 class NewgroundsUserIE(InfoExtractor):
241 IE_NAME = 'Newgrounds
:user
'
242 _VALID_URL = r'https?
://(?P
<id>[^\
.]+)\
.newgrounds\
.com
/(?
:movies|audio
)/?
(?
:[#?]|$)'
244 'url': 'https://burn7.newgrounds.com/audio',
248 'playlist_mincount': 150,
250 'url': 'https://burn7.newgrounds.com/movies',
254 'playlist_mincount': 2,
256 'url': 'https://brian-beaton.newgrounds.com/movies',
258 'id': 'brian-beaton',
260 'playlist_mincount': 10,
264 def _fetch_page(self
, channel_id
, url
, page
):
266 posts_info
= self
._download
_json
(
267 f
'{url}/page/{page}', channel_id
,
268 note
=f
'Downloading page {page}', headers
={
269 'Accept': 'application/json, text/javascript, */*; q = 0.01',
270 'X-Requested-With': 'XMLHttpRequest',
272 sequence
= posts_info
.get('sequence', [])
273 for year
in sequence
:
274 posts
= try_get(posts_info
, lambda x
: x
['years'][str(year
)]['items'])
276 path
, media_id
= self
._search
_regex
(
277 r
'<a[^>]+\bhref=["\'][^
"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
278 post, 'url', group=(1, 2))
279 yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)
281 def _real_extract(self, url):
282 channel_id = self._match_id(url)
284 entries = OnDemandPagedList(functools.partial(
285 self._fetch_page, channel_id, url), self._PAGE_SIZE)
287 return self.playlist_result(entries, channel_id)