1 from __future__ import unicode_literals
5 from .common import InfoExtractor
12 class NewgroundsIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>[0-9]+)'
15 'url': 'https://www.newgrounds.com/audio/listen/549479',
16 'md5': 'fe6033d297591288fa1c1f780386f07a',
20 'title': 'B7 - BusMode',
24 'url': 'https://www.newgrounds.com/portal/view/673111',
25 'md5': '3394735822aab2478c31b1004fe5e5bc',
30 'uploader': 'Squirrelman82',
33 # source format unavailable, additional mp4 formats
34 'url': 'http://www.newgrounds.com/portal/view/689400',
38 'title': 'ZTV News Episode 8',
39 'uploader': 'BennettTheSage',
42 'skip_download': True,
46 def _real_extract(self, url):
47 media_id = self._match_id(url)
49 webpage = self._download_webpage(url, media_id)
51 title = self._html_search_regex(
52 r'<title>([^>]+)</title>', webpage, 'title')
54 video_url = self._parse_json(self._search_regex(
55 r'"url"\s*:\s*("[^"]+"),', webpage, ''), media_id)
59 'format_id': 'source',
63 max_resolution = int_or_none(self._search_regex(
64 r'max_resolution["\']\s*:\s*(\d+)', webpage, 'max resolution',
67 url_base = video_url.rpartition('.')[0]
68 for resolution in (360, 720, 1080):
69 if resolution > max_resolution:
72 'url': '%s.%dp.mp4' % (url_base, resolution),
73 'format_id': '%dp' % resolution,
77 self._check_formats(formats, media_id)
78 self._sort_formats(formats)
80 uploader = self._html_search_regex(
81 r'(?:Author|Writer)\s*<a[^>]+>([^<]+)', webpage, 'uploader',
92 class NewgroundsPlaylistIE(InfoExtractor):
93 _VALID_URL = r'https?://(?:www\.)?newgrounds\.com/(?:collection|[^/]+/search/[^/]+)/(?P<id>[^/?#&]+)'
95 'url': 'https://www.newgrounds.com/collection/cats',
100 'playlist_mincount': 46,
102 'url': 'http://www.newgrounds.com/portal/search/author/ZONE-SAMA',
105 'title': 'Portal Search: ZONE-SAMA',
107 'playlist_mincount': 47,
109 'url': 'http://www.newgrounds.com/audio/search/title/cats',
110 'only_matching': True,
113 def _real_extract(self, url):
114 playlist_id = self._match_id(url)
116 webpage = self._download_webpage(url, playlist_id)
118 title = self._search_regex(
119 r'<title>([^>]+)</title>', webpage, 'title', default=None)
122 webpage = self._search_regex(
123 r'(?s)<div[^>]+\bclass=["\']column wide(.+)',
124 webpage, 'wide column', default=webpage)
127 for a, path, media_id in re.findall(
128 r'(<a[^>]+\bhref=["\']/?((?:portal/view|audio/listen)/(\d+))[^>]+>)',
130 a_class = extract_attributes(a).get('class')
131 if a_class not in ('item-portalsubmission', 'item-audiosubmission'):
135 'https://www.newgrounds.com/%s' % path,
136 ie=NewgroundsIE.ie_key(), video_id=media_id))
138 return self.playlist_result(entries, playlist_id, title)