]>
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
_search
_regex
(
110 r
'<title>(.+?)</title>', webpage
, 'title')
112 media_url_string
= self
._search
_regex
(
113 r
'"url"\s*:\s*("[^"]+"),', webpage
, 'media url', default
=None)
116 media_url
= self
._parse
_json
(media_url_string
, media_id
)
119 'format_id': 'source',
123 json_video
= self
._download
_json
('https://www.newgrounds.com/portal/video/' + media_id
, media_id
, headers
={
124 'Accept': 'application/json',
126 'X-Requested-With': 'XMLHttpRequest'
129 uploader
= json_video
.get('author')
130 media_formats
= json_video
.get('sources', [])
131 for media_format
in media_formats
:
132 media_sources
= media_formats
[media_format
]
133 for source
in media_sources
:
135 'format_id': media_format
,
136 'quality': int_or_none(media_format
[:-1]),
137 'url': source
.get('src')
141 uploader
= self
._html
_search
_regex
(
142 (r
'(?s)<h4[^>]*>(.+?)</h4>.*?<em>\s*(?:Author|Artist)\s*</em>',
143 r
'(?:Author|Writer)\s*<a[^>]+>([^<]+)'), webpage
, 'uploader',
146 age_limit
= self
._html
_search
_regex
(
147 r
'<h2\s*class=["\']rated
-([^
"\'])["\'][^
>]+>', webpage, 'age_limit
', default='e
')
148 age_limit = self._AGE_LIMIT.get(age_limit)
150 timestamp = unified_timestamp(self._html_search_regex(
151 (r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+</dd
>\s
*<dd
>[^
<]+)',
152 r'<dt
>\s
*Uploaded\s
*</dt
>\s
*<dd
>([^
<]+)'), webpage, 'timestamp
',
155 duration = parse_duration(self._html_search_regex(
156 r'"duration"\s
*:\s
*["\']?(\d+)["\']?
', webpage,
157 'duration
', default=None))
159 description = clean_html(get_element_by_id('author_comments
', webpage)) or self._og_search_description(webpage)
161 view_count = parse_count(self._html_search_regex(
162 r'(?s
)<dt
>\s
*(?
:Views|Listens
)\s
*</dt
>\s
*<dd
>([\d\
.,]+)</dd
>', webpage,
163 'view count
', default=None))
165 filesize = int_or_none(self._html_search_regex(
166 r'"filesize"\s
*:\s
*["\']?([\d]+)["\']?
,', webpage, 'filesize
',
169 video_type_description = self._html_search_regex(
170 r'"description"\s
*:\s
*["\']?([^"\']+)["\']?,', webpage, 'filesize',
173 if len(formats) == 1:
174 formats[0]['filesize'] = filesize
176 if video_type_description == 'Audio File':
177 formats[0]['vcodec'] = 'none'
178 self._check_formats(formats, media_id)
179 self._sort_formats(formats)
184 'uploader': uploader,
185 'timestamp': timestamp,
186 'duration': duration,
188 'thumbnail': self._og_search_thumbnail(webpage),
189 'description': description,
190 'age_limit': age_limit,
191 'view_count': view_count,
195 class NewgroundsPlaylistIE(InfoExtractor):
196 IE_NAME = 'Newgrounds:playlist'
197 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:collection|[^/]+/search/[^/]+)/(?P<id>[^/?#&]+)'
199 'url': 'https://www.newgrounds.com/collection/cats',
204 'playlist_mincount': 45,
206 'url': 'https://www.newgrounds.com/collection/dogs',
211 'playlist_mincount': 26,
213 'url': 'http://www.newgrounds.com/audio/search/title/cats',
214 'only_matching': True,
217 def _real_extract(self, url):
218 playlist_id = self._match_id(url)
220 webpage = self._download_webpage(url, playlist_id)
222 title = self._search_regex(
223 r'<title>([^>]+)</title>', webpage, 'title', default=None)
226 webpage = self._search_regex(
227 r'(?s)<div[^>]+\bclass=["\']column
wide(.+)',
228 webpage, 'wide column
', default=webpage)
231 for a, path, media_id in re.findall(
232 r'(<a
[^
>]+\bhref
=["\'][^"\']+((?
:portal
/view|audio
/listen
)/(\d
+))[^
>]+>)',
234 a_class = extract_attributes(a).get('class')
235 if a_class not in ('item
-portalsubmission
', 'item
-audiosubmission
'):
239 f'https
://www
.newgrounds
.com
/{path}
',
240 ie=NewgroundsIE.ie_key(), video_id=media_id))
242 return self.playlist_result(entries, playlist_id, title)
245 class NewgroundsUserIE(InfoExtractor):
246 IE_NAME = 'Newgrounds
:user
'
247 _VALID_URL = r'https?
://(?P
<id>[^\
.]+)\
.newgrounds\
.com
/(?
:movies|audio
)/?
(?
:[#?]|$)'
249 'url': 'https://burn7.newgrounds.com/audio',
253 'playlist_mincount': 150,
255 'url': 'https://burn7.newgrounds.com/movies',
259 'playlist_mincount': 2,
261 'url': 'https://brian-beaton.newgrounds.com/movies',
263 'id': 'brian-beaton',
265 'playlist_mincount': 10,
269 def _fetch_page(self
, channel_id
, url
, page
):
271 posts_info
= self
._download
_json
(
272 f
'{url}/page/{page}', channel_id
,
273 note
=f
'Downloading page {page}', headers
={
274 'Accept': 'application/json, text/javascript, */*; q = 0.01',
275 'X-Requested-With': 'XMLHttpRequest',
277 sequence
= posts_info
.get('sequence', [])
278 for year
in sequence
:
279 posts
= try_get(posts_info
, lambda x
: x
['years'][str(year
)]['items'])
281 path
, media_id
= self
._search
_regex
(
282 r
'<a[^>]+\bhref=["\'][^
"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
283 post, 'url', group=(1, 2))
284 yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)
286 def _real_extract(self, url):
287 channel_id = self._match_id(url)
289 entries = OnDemandPagedList(functools.partial(
290 self._fetch_page, channel_id, url), self._PAGE_SIZE)
292 return self.playlist_result(entries, channel_id)