1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-02-09 20:45:33 +08:00

[Freesound] requested fixes

This commit is contained in:
sh!zeeg 2017-01-07 23:56:53 +03:00
parent e3acd5406f
commit 45372b7e7b

View File

@ -5,10 +5,11 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, determine_ext,
float_or_none,
get_element_by_class, get_element_by_class,
get_element_by_id, get_element_by_id,
int_or_none, int_or_none,
float_or_none, parse_filesize,
unified_strdate, unified_strdate,
) )
@ -31,36 +32,37 @@ class FreesoundIE(InfoExtractor):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
music_id = mobj.group('id') music_id = mobj.group('id')
webpage = self._download_webpage(url, music_id) webpage = self._download_webpage(url, music_id)
audio_url = self._og_search_property('audio', webpage, 'song url')
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'<div id="sound_description">(.*?)</div>', webpage, 'description',
fatal=False, flags=re.DOTALL) fatal=False, flags=re.DOTALL)
duration = float_or_none(get_element_by_class('duration', webpage)) download_count = int_or_none(self._html_search_regex(
if duration: r'Downloaded.*>(\d+)<', webpage, 'downloaded', fatal=False))
duration = duration / 1000
filesize = float_or_none(parse_filesize(self._search_regex(
r'Filesize</dt><dd>(.*)</dd>', sound_info, 'file size (approx)', fatal=False)))
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)
filesize = float_or_none(self._search_regex(
r'Filesize</dt><dd>(\d+.\d+).*</dd>', sound_info, 'file size (approx)', fatal=False))
if filesize:
filesize = filesize * 1048576
if release_date: if release_date:
release_date = unified_strdate(release_date.replace('th', '')) release_date = unified_strdate(release_date.replace('th', ''))
channels = self._html_search_regex(
r'Channels</dt><dd>(.*)</dd>', sound_info, 'Channels info', fatal=False)
bitdepth = self._html_search_regex( bitdepth = self._html_search_regex(
r'Bitdepth</dt><dd>(.*)</dd>', sound_info, 'Bitdepth', fatal=False) r'Bitdepth</dt><dd>(.*)</dd>', sound_info, 'Bitdepth', fatal=False)
download_count = int_or_none(self._html_search_regex( channels = self._html_search_regex(
r'Downloaded.*>(\d+)<', webpage, 'downloaded', fatal=False)) r'Channels</dt><dd>(.*)</dd>', sound_info, 'Channels info', fatal=False)
audio_url = self._og_search_property('audio', webpage, 'song url')
formats = [{ formats = [{
'url': audio_url, 'url': audio_url,
'id': music_id, 'id': music_id,
'format_id': self._og_search_property('audio:type', webpage, 'audio format'), 'format_id': self._og_search_property('audio:type', webpage, 'audio format', fatal=False),
'format_note': '{0} {1} {2}'.format(determine_ext(audio_url), bitdepth, channels), 'format_note': '{0} {1} {2}'.format(determine_ext(audio_url), bitdepth, channels),
'filesize_approx': filesize, 'filesize_approx': filesize,
'asr': int_or_none(self._html_search_regex( 'asr': int_or_none(self._html_search_regex(
@ -70,8 +72,8 @@ class FreesoundIE(InfoExtractor):
return { return {
'id': music_id, 'id': music_id,
'title': self._og_search_property('audio:title', webpage, 'song title'), 'title': title,
'uploader': self._og_search_property('audio:artist', webpage, 'music uploader'), '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) 'tags': [self._html_search_regex(r'>(.*)</a>', t, 'tag', fatal=False)