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