]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/newgrounds.py
2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
21 class NewgroundsIE(InfoExtractor
):
22 _VALID_URL
= r
'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>\d+)(?:/format/flash)?'
24 'url': 'https://www.newgrounds.com/audio/listen/549479',
25 'md5': 'fe6033d297591288fa1c1f780386f07a',
29 'title': 'B7 - BusMode',
31 'timestamp': 1378878540,
32 'upload_date': '20130911',
35 'description': 'md5:b8b3c2958875189f07d8e313462e8c4f',
38 'url': 'https://www.newgrounds.com/portal/view/1',
39 'md5': 'fbfb40e2dc765a7e830cb251d370d981',
44 'uploader': 'Brian-Beaton',
45 'timestamp': 955064100,
46 'upload_date': '20000406',
48 'description': 'Scrotum plays "catch."',
52 # source format unavailable, additional mp4 formats
53 'url': 'http://www.newgrounds.com/portal/view/689400',
57 'title': 'ZTV News Episode 8',
58 'uploader': 'ZONE-SAMA',
59 'timestamp': 1487965140,
60 'upload_date': '20170224',
62 'description': 'md5:aff9b330ec2e78ed93b1ad6d017accc6',
66 'skip_download': True,
69 'url': 'https://www.newgrounds.com/portal/view/297383',
70 'md5': '2c11f5fd8cb6b433a63c89ba3141436c',
74 'title': 'Metal Gear Awesome',
75 'uploader': 'Egoraptor',
76 'timestamp': 1140663240,
77 'upload_date': '20060223',
79 'description': 'md5:9246c181614e23754571995104da92e0',
83 'url': 'https://www.newgrounds.com/portal/view/297383/format/flash',
84 'md5': '5d05585a9a0caca059f5abfbd3865524',
88 'title': 'Metal Gear Awesome',
89 'description': 'Metal Gear Awesome',
90 'uploader': 'Egoraptor',
91 'upload_date': '20060223',
92 'timestamp': 1140663240,
103 def _real_extract(self
, url
):
104 media_id
= self
._match
_id
(url
)
107 webpage
= self
._download
_webpage
(url
, media_id
)
109 title
= self
._html
_extract
_title
(webpage
)
111 media_url_string
= self
._search
_regex
(
112 r
'"url"\s*:\s*("[^"]+"),', webpage
, 'media url', default
=None)
115 media_url
= self
._parse
_json
(media_url_string
, media_id
)
118 'format_id': 'source',
122 json_video
= self
._download
_json
('https://www.newgrounds.com/portal/video/' + media_id
, media_id
, headers
={
123 'Accept': 'application/json',
125 'X-Requested-With': 'XMLHttpRequest'
128 uploader
= json_video
.get('author')
129 media_formats
= json_video
.get('sources', [])
130 for media_format
in media_formats
:
131 media_sources
= media_formats
[media_format
]
132 for source
in media_sources
:
134 'format_id': media_format
,
135 'quality': int_or_none(media_format
[:-1]),
136 'url': source
.get('src')
140 uploader
= self
._html
_search
_regex
(
141 (r
'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*(?:Author|Artist)\s*</em>',
142 r
'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage
, 'uploader',
145 age_limit
= self
._html
_search
_regex
(
146 r
'<h2\s*class=["\']rated
-([^
"\'])["\'][^
>]+>', webpage, 'age_limit
', default='e
')
147 age_limit = self._AGE_LIMIT.get(age_limit)
149 timestamp = unified_timestamp(self._html_search_regex(
150 (r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+</dd
>\s
*<dd
>[^
<]+)',
151 r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+)'), webpage, 'timestamp
',
154 duration = parse_duration(self._html_search_regex(
155 r'"duration"\s
*:\s
*["\']?(\d+)["\']?
', webpage,
156 'duration
', default=None))
158 description = clean_html(get_element_by_id('author_comments
', webpage)) or self._og_search_description(webpage)
160 view_count = parse_count(self._html_search_regex(
161 r'(?s
)<dt
>\s
*(?
:Views|Listens
)\s
*</dt
>\s
*<dd
>([\d\
.,]+)</dd
>', webpage,
162 'view count
', default=None))
164 filesize = int_or_none(self._html_search_regex(
165 r'"filesize"\s
*:\s
*["\']?([\d]+)["\']?
,', webpage, 'filesize
',
168 video_type_description = self._html_search_regex(
169 r'"description"\s
*:\s
*["\']?([^"\']+)["\']?,', webpage, 'filesize',
172 if len(formats) == 1:
173 formats[0]['filesize'] = filesize
175 if video_type_description == 'Audio File':
176 formats[0]['vcodec'] = 'none'
177 self._check_formats(formats, media_id)
178 self._sort_formats(formats)
183 'uploader': uploader,
184 'timestamp': timestamp,
185 'duration': duration,
187 'thumbnail': self._og_search_thumbnail(webpage),
188 'description': description,
189 'age_limit': age_limit,
190 'view_count': view_count,
194 class NewgroundsPlaylistIE(InfoExtractor):
195 IE_NAME = 'Newgrounds:playlist'
196 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:collection|[^/]+/search/[^/]+)/(?P<id>[^/?#&]+)'
198 'url': 'https://www.newgrounds.com/collection/cats',
203 'playlist_mincount': 45,
205 'url': 'https://www.newgrounds.com/collection/dogs',
210 'playlist_mincount': 26,
212 'url': 'http://www.newgrounds.com/audio/search/title/cats',
213 'only_matching': True,
216 def _real_extract(self, url):
217 playlist_id = self._match_id(url)
219 webpage = self._download_webpage(url, playlist_id)
221 title = self._html_extract_title(webpage, default=None)
224 webpage = self._search_regex(
225 r'(?s)<div[^>]+\bclass=["\']column
wide(.+)',
226 webpage, 'wide column
', default=webpage)
229 for a, path, media_id in re.findall(
230 r'(<a
[^
>]+\bhref
=["\'][^"\']+((?
:portal
/view|audio
/listen
)/(\d
+))[^
>]+>)',
232 a_class = extract_attributes(a).get('class')
233 if a_class not in ('item
-portalsubmission
', 'item
-audiosubmission
'):
237 f'https
://www
.newgrounds
.com
/{path}
',
238 ie=NewgroundsIE.ie_key(), video_id=media_id))
240 return self.playlist_result(entries, playlist_id, title)
243 class NewgroundsUserIE(InfoExtractor):
244 IE_NAME = 'Newgrounds
:user
'
245 _VALID_URL = r'https?
://(?P
<id>[^\
.]+)\
.newgrounds\
.com
/(?
:movies|audio
)/?
(?
:[#?]|$)'
247 'url': 'https://burn7.newgrounds.com/audio',
251 'playlist_mincount': 150,
253 'url': 'https://burn7.newgrounds.com/movies',
257 'playlist_mincount': 2,
259 'url': 'https://brian-beaton.newgrounds.com/movies',
261 'id': 'brian-beaton',
263 'playlist_mincount': 10,
267 def _fetch_page(self
, channel_id
, url
, page
):
269 posts_info
= self
._download
_json
(
270 f
'{url}/page/{page}', channel_id
,
271 note
=f
'Downloading page {page}', headers
={
272 'Accept': 'application/json, text/javascript, */*; q = 0.01',
273 'X-Requested-With': 'XMLHttpRequest',
275 sequence
= posts_info
.get('sequence', [])
276 for year
in sequence
:
277 posts
= try_get(posts_info
, lambda x
: x
['years'][str(year
)]['items'])
279 path
, media_id
= self
._search
_regex
(
280 r
'<a[^>]+\bhref=["\'][^
"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
281 post, 'url', group=(1, 2))
282 yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)
284 def _real_extract(self, url):
285 channel_id = self._match_id(url)
287 entries = OnDemandPagedList(functools.partial(
288 self._fetch_page, channel_id, url), self._PAGE_SIZE)
290 return self.playlist_result(entries, channel_id)