]>
Commit | Line | Data |
---|---|---|
5d9b7505 YK |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
ed06da4e | 4 | from ..utils import ( |
ed06da4e | 5 | float_or_none, |
6 | get_element_by_class, | |
7 | get_element_by_id, | |
ed06da4e | 8 | unified_strdate, |
9 | ) | |
34bd9878 | 10 | |
5d9b7505 | 11 | |
67de24e4 | 12 | class FreesoundIE(InfoExtractor): |
3a407e70 | 13 | _VALID_URL = r'https?://(?:www\.)?freesound\.org/people/[^/]+/sounds/(?P<id>[^/]+)' |
76650102 | 14 | _TEST = { |
34bd9878 JMF |
15 | 'url': 'http://www.freesound.org/people/miklovan/sounds/194503/', |
16 | 'md5': '12280ceb42c81f19a515c745eae07650', | |
17 | 'info_dict': { | |
18 | 'id': '194503', | |
19 | 'ext': 'mp3', | |
20 | 'title': 'gulls in the city.wav', | |
34bd9878 | 21 | 'description': 'the sounds of seagulls in the city', |
3a407e70 S |
22 | 'duration': 130.233, |
23 | 'uploader': 'miklovan', | |
24 | 'upload_date': '20130715', | |
25 | 'tags': list, | |
76650102 YK |
26 | } |
27 | } | |
5d9b7505 YK |
28 | |
29 | def _real_extract(self, url): | |
3a407e70 S |
30 | audio_id = self._match_id(url) |
31 | ||
32 | webpage = self._download_webpage(url, audio_id) | |
ed06da4e | 33 | |
34 | audio_url = self._og_search_property('audio', webpage, 'song url') | |
35 | title = self._og_search_property('audio:title', webpage, 'song title') | |
ed06da4e | 36 | |
34bd9878 | 37 | description = self._html_search_regex( |
3a407e70 S |
38 | r'(?s)id=["\']sound_description["\'][^>]*>(.+?)</div>', |
39 | webpage, 'description', fatal=False) | |
5d9b7505 | 40 | |
3a407e70 S |
41 | duration = float_or_none( |
42 | get_element_by_class('duration', webpage), scale=1000) | |
ed06da4e | 43 | |
3a407e70 S |
44 | upload_date = unified_strdate(get_element_by_id('sound_date', webpage)) |
45 | uploader = self._og_search_property( | |
46 | 'audio:artist', webpage, 'uploader', fatal=False) | |
ed06da4e | 47 | |
3a407e70 S |
48 | channels = self._html_search_regex( |
49 | r'Channels</dt><dd>(.+?)</dd>', webpage, | |
50 | 'channels info', fatal=False) | |
ed06da4e | 51 | |
3a407e70 S |
52 | tags_str = get_element_by_class('tags', webpage) |
53 | tags = re.findall(r'<a[^>]+>([^<]+)', tags_str) if tags_str else None | |
ed06da4e | 54 | |
3a407e70 S |
55 | audio_urls = [audio_url] |
56 | ||
57 | LQ_FORMAT = '-lq.mp3' | |
58 | if LQ_FORMAT in audio_url: | |
59 | audio_urls.append(audio_url.replace(LQ_FORMAT, '-hq.mp3')) | |
ed06da4e | 60 | |
61 | formats = [{ | |
3a407e70 S |
62 | 'url': format_url, |
63 | 'format_note': channels, | |
64 | 'quality': quality, | |
65 | } for quality, format_url in enumerate(audio_urls)] | |
66 | self._sort_formats(formats) | |
ed06da4e | 67 | |
34bd9878 | 68 | return { |
3a407e70 | 69 | 'id': audio_id, |
34bd9878 | 70 | 'title': title, |
67de24e4 | 71 | 'description': description, |
ed06da4e | 72 | 'duration': duration, |
3a407e70 S |
73 | 'uploader': uploader, |
74 | 'upload_date': upload_date, | |
75 | 'tags': tags, | |
ed06da4e | 76 | 'formats': formats, |
34bd9878 | 77 | } |