Merge pull request #1050 from yasoob/master
[youtube-dl] / youtube_dl / extractor / freesound.py
1 # -*- coding: utf-8 -*-
2 import re
3
4 from .common import InfoExtractor
5
6 class FreeSoundIE(InfoExtractor):
7     _VALID_URL = r'(?:http://)?(?:www\.)?freesound\.org/people/([^/]+)/sounds/([^/]+)'
8     _TEST = {
9         u'url': u'http://www.freesound.org/people/miklovan/sounds/194503/',
10         u'file': u'194503.mp3',
11         u'md5': u'12280ceb42c81f19a515c745eae07650',
12         u'info_dict': {
13             u"title": u"gulls in the city.wav by miklovan",
14             u"uploader" : u"miklovan"
15         }
16     }
17
18     def _real_extract(self, url):
19         mobj = re.match(self._VALID_URL, url)
20         music_id = mobj.group(2)
21         webpage = self._download_webpage(url, music_id)
22         title = self._html_search_regex(r'<meta property="og:title" content="([^"]*)"',
23                                 webpage, 'music title')
24         music_url = self._html_search_regex(r'<meta property="og:audio" content="([^"]*)"',
25                                 webpage, 'music url')       
26         uploader = self._html_search_regex(r'<meta property="og:audio:artist" content="([^"]*)"',
27                                 webpage, 'music uploader')                                                                        
28         ext = music_url.split('.')[-1]
29
30         return [{
31             'id':       music_id,
32             'title':    title,            
33             'url':      music_url,
34             'uploader': uploader,
35             'ext':      ext,
36         }]