]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/newgrounds.py
0e26f8399dd8ea8777c28d0bb61483e27f954965
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class NewgroundsIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:www\.)?newgrounds\.com/(?:audio/listen|portal/view)/(?P<id>[0-9]+)'
18 'url': 'https://www.newgrounds.com/audio/listen/549479',
19 'md5': 'fe6033d297591288fa1c1f780386f07a',
23 'title': 'B7 - BusMode',
25 'timestamp': 1378878540,
26 'upload_date': '20130911',
30 'url': 'https://www.newgrounds.com/portal/view/673111',
31 'md5': '3394735822aab2478c31b1004fe5e5bc',
36 'uploader': 'Squirrelman82',
37 'timestamp': 1460256780,
38 'upload_date': '20160410',
41 # source format unavailable, additional mp4 formats
42 'url': 'http://www.newgrounds.com/portal/view/689400',
46 'title': 'ZTV News Episode 8',
47 'uploader': 'BennettTheSage',
48 'timestamp': 1487965140,
49 'upload_date': '20170224',
52 'skip_download': True,
56 def _real_extract(self
, url
):
57 media_id
= self
._match
_id
(url
)
59 webpage
= self
._download
_webpage
(url
, media_id
)
61 title
= self
._html
_search
_regex
(
62 r
'<title>([^>]+)</title>', webpage
, 'title')
64 media_url
= self
._parse
_json
(self
._search
_regex
(
65 r
'"url"\s*:\s*("[^"]+"),', webpage
, ''), media_id
)
69 'format_id': 'source',
73 max_resolution
= int_or_none(self
._search
_regex
(
74 r
'max_resolution["\']\s
*:\s
*(\d
+)', webpage, 'max resolution
',
77 url_base = media_url.rpartition('.')[0]
78 for resolution in (360, 720, 1080):
79 if resolution > max_resolution:
82 'url
': '%s.%dp
.mp4
' % (url_base, resolution),
83 'format_id
': '%dp
' % resolution,
87 self._check_formats(formats, media_id)
88 self._sort_formats(formats)
90 uploader = self._search_regex(
91 r'(?
:Author|Writer
)\s
*<a
[^
>]+>([^
<]+)', webpage, 'uploader
',
94 timestamp = unified_timestamp(self._search_regex(
95 r'<dt
>Uploaded
</dt
>\s
*<dd
>([^
<]+)', webpage, 'timestamp
',
97 duration = parse_duration(self._search_regex(
98 r'<dd
>Song\s
*</dd
><dd
>.+?
</dd
><dd
>([^
<]+)', webpage, 'duration
',
101 filesize_approx = parse_filesize(self._html_search_regex(
102 r'<dd
>Song\s
*</dd
><dd
>(.+?
)</dd
>', webpage, 'filesize
',
104 if len(formats) == 1:
105 formats[0]['filesize_approx
'] = filesize_approx
107 if '<dd
>Song
' in webpage:
108 formats[0]['vcodec
'] = 'none
'
113 'uploader
': uploader,
114 'timestamp
': timestamp,
115 'duration
': duration,
120 class NewgroundsPlaylistIE(InfoExtractor):
121 _VALID_URL = r'https?
://(?
:www\
.)?newgrounds\
.com
/(?
:collection|
[^
/]+/search
/[^
/]+)/(?P
<id>[^
/?
#&]+)'
123 'url': 'https://www.newgrounds.com/collection/cats',
128 'playlist_mincount': 46,
130 'url': 'http://www.newgrounds.com/portal/search/author/ZONE-SAMA',
133 'title': 'Portal Search: ZONE-SAMA',
135 'playlist_mincount': 47,
137 'url': 'http://www.newgrounds.com/audio/search/title/cats',
138 'only_matching': True,
141 def _real_extract(self
, url
):
142 playlist_id
= self
._match
_id
(url
)
144 webpage
= self
._download
_webpage
(url
, playlist_id
)
146 title
= self
._search
_regex
(
147 r
'<title>([^>]+)</title>', webpage
, 'title', default
=None)
150 webpage
= self
._search
_regex
(
151 r
'(?s)<div[^>]+\bclass=["\']column
wide(.+)',
152 webpage, 'wide column
', default=webpage)
155 for a, path, media_id in re.findall(
156 r'(<a
[^
>]+\bhref
=["\']/?((?:portal/view|audio/listen)/(\d+))[^>]+>)',
158 a_class = extract_attributes(a).get('class')
159 if a_class not in ('item-portalsubmission', 'item-audiosubmission'):
163 'https://www.newgrounds.com/%s' % path,
164 ie=NewgroundsIE.ie_key(), video_id=media_id))
166 return self.playlist_result(entries, playlist_id, title)