mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-20 12:04:03 +00:00
[freesound] Improve and remove unrelated metadata (closes #11608)
This commit is contained in:
parent
cb655f34fb
commit
3a407e707a
@ -4,18 +4,15 @@ import re
|
|||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
determine_ext,
|
|
||||||
float_or_none,
|
float_or_none,
|
||||||
get_element_by_class,
|
get_element_by_class,
|
||||||
get_element_by_id,
|
get_element_by_id,
|
||||||
int_or_none,
|
|
||||||
parse_filesize,
|
|
||||||
unified_strdate,
|
unified_strdate,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class FreesoundIE(InfoExtractor):
|
class FreesoundIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?freesound\.org/people/([^/]+)/sounds/(?P<id>[^/]+)'
|
_VALID_URL = r'https?://(?:www\.)?freesound\.org/people/[^/]+/sounds/(?P<id>[^/]+)'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
'url': 'http://www.freesound.org/people/miklovan/sounds/194503/',
|
'url': 'http://www.freesound.org/people/miklovan/sounds/194503/',
|
||||||
'md5': '12280ceb42c81f19a515c745eae07650',
|
'md5': '12280ceb42c81f19a515c745eae07650',
|
||||||
@ -23,62 +20,60 @@ class FreesoundIE(InfoExtractor):
|
|||||||
'id': '194503',
|
'id': '194503',
|
||||||
'ext': 'mp3',
|
'ext': 'mp3',
|
||||||
'title': 'gulls in the city.wav',
|
'title': 'gulls in the city.wav',
|
||||||
'uploader': 'miklovan',
|
|
||||||
'description': 'the sounds of seagulls in the city',
|
'description': 'the sounds of seagulls in the city',
|
||||||
|
'duration': 130.233,
|
||||||
|
'uploader': 'miklovan',
|
||||||
|
'upload_date': '20130715',
|
||||||
|
'tags': list,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
audio_id = self._match_id(url)
|
||||||
music_id = mobj.group('id')
|
|
||||||
webpage = self._download_webpage(url, music_id)
|
webpage = self._download_webpage(url, audio_id)
|
||||||
|
|
||||||
audio_url = self._og_search_property('audio', webpage, 'song url')
|
audio_url = self._og_search_property('audio', webpage, 'song url')
|
||||||
title = self._og_search_property('audio:title', webpage, 'song title')
|
title = self._og_search_property('audio:title', webpage, 'song title')
|
||||||
duration = float_or_none(get_element_by_class('duration', webpage), scale=1000)
|
|
||||||
tags = get_element_by_class('tags', webpage)
|
|
||||||
sound_info = get_element_by_id('sound_information_box', webpage)
|
|
||||||
release_date = get_element_by_id('sound_date', webpage)
|
|
||||||
|
|
||||||
description = self._html_search_regex(
|
description = self._html_search_regex(
|
||||||
r'<div id="sound_description">(.*?)</div>', webpage, 'description',
|
r'(?s)id=["\']sound_description["\'][^>]*>(.+?)</div>',
|
||||||
fatal=False, flags=re.DOTALL)
|
webpage, 'description', fatal=False)
|
||||||
|
|
||||||
download_count = int_or_none(self._html_search_regex(
|
duration = float_or_none(
|
||||||
r'Downloaded.*>(\d+)<', webpage, 'downloaded', fatal=False))
|
get_element_by_class('duration', webpage), scale=1000)
|
||||||
|
|
||||||
filesize = float_or_none(parse_filesize(self._search_regex(
|
upload_date = unified_strdate(get_element_by_id('sound_date', webpage))
|
||||||
r'Filesize</dt><dd>(.*)</dd>', sound_info, 'file size (approx)', fatal=False)))
|
uploader = self._og_search_property(
|
||||||
|
'audio:artist', webpage, 'uploader', fatal=False)
|
||||||
if release_date:
|
|
||||||
release_date = unified_strdate(release_date.replace('th', ''))
|
|
||||||
|
|
||||||
bitdepth = self._html_search_regex(
|
|
||||||
r'Bitdepth</dt><dd>(.*)</dd>', sound_info, 'Bitdepth', fatal=False)
|
|
||||||
|
|
||||||
channels = self._html_search_regex(
|
channels = self._html_search_regex(
|
||||||
r'Channels</dt><dd>(.*)</dd>', sound_info, 'Channels info', fatal=False)
|
r'Channels</dt><dd>(.+?)</dd>', webpage,
|
||||||
|
'channels info', fatal=False)
|
||||||
|
|
||||||
|
tags_str = get_element_by_class('tags', webpage)
|
||||||
|
tags = re.findall(r'<a[^>]+>([^<]+)', tags_str) if tags_str else None
|
||||||
|
|
||||||
|
audio_urls = [audio_url]
|
||||||
|
|
||||||
|
LQ_FORMAT = '-lq.mp3'
|
||||||
|
if LQ_FORMAT in audio_url:
|
||||||
|
audio_urls.append(audio_url.replace(LQ_FORMAT, '-hq.mp3'))
|
||||||
|
|
||||||
formats = [{
|
formats = [{
|
||||||
'url': audio_url,
|
'url': format_url,
|
||||||
'id': music_id,
|
'format_note': channels,
|
||||||
'format_id': self._og_search_property('audio:type', webpage, 'audio format', fatal=False),
|
'quality': quality,
|
||||||
'format_note': '{0} {1} {2}'.format(determine_ext(audio_url), bitdepth, channels),
|
} for quality, format_url in enumerate(audio_urls)]
|
||||||
'filesize_approx': filesize,
|
self._sort_formats(formats)
|
||||||
'asr': int_or_none(self._html_search_regex(
|
|
||||||
r'Samplerate</dt><dd>(\d+).*</dd>',
|
|
||||||
sound_info, 'samplerate', fatal=False)),
|
|
||||||
}]
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': music_id,
|
'id': audio_id,
|
||||||
'title': title,
|
'title': title,
|
||||||
'uploader': self._og_search_property('audio:artist', webpage, 'music uploader', fatal=False),
|
|
||||||
'description': description,
|
'description': description,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'tags': [self._html_search_regex(r'>(.*)</a>', t, 'tag', fatal=False)
|
'uploader': uploader,
|
||||||
for t in tags.split('\n') if t.strip()],
|
'upload_date': upload_date,
|
||||||
|
'tags': tags,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'release_date': release_date,
|
|
||||||
'likes_count': download_count,
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user