]>
Commit | Line | Data |
---|---|---|
af6ba6a1 JMF |
1 | from __future__ import unicode_literals |
2 | ||
b6ef4029 | 3 | import re |
b6ef4029 YK |
4 | |
5 | from .common import InfoExtractor | |
6 | ||
7 | ||
8 | class ExfmIE(InfoExtractor): | |
af6ba6a1 JMF |
9 | IE_NAME = 'exfm' |
10 | IE_DESC = 'ex.fm' | |
5886b38d | 11 | _VALID_URL = r'https?://(?:www\.)?ex\.fm/song/(?P<id>[^/]+)' |
af6ba6a1 | 12 | _SOUNDCLOUD_URL = r'http://(?:www\.)?api\.soundcloud\.com/tracks/([^/]+)/stream' |
eb6a41ba JMF |
13 | _TESTS = [ |
14 | { | |
af6ba6a1 JMF |
15 | 'url': 'http://ex.fm/song/eh359', |
16 | 'md5': 'e45513df5631e6d760970b14cc0c11e7', | |
17 | 'info_dict': { | |
18 | 'id': '44216187', | |
19 | 'ext': 'mp3', | |
20 | 'title': 'Test House "Love Is Not Enough" (Extended Mix) DeadJournalist Exclusive', | |
21 | 'uploader': 'deadjournalist', | |
22 | 'upload_date': '20120424', | |
23 | 'description': 'Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive', | |
eb6a41ba | 24 | }, |
af6ba6a1 JMF |
25 | 'note': 'Soundcloud song', |
26 | 'skip': 'The site is down too often', | |
eb6a41ba JMF |
27 | }, |
28 | { | |
af6ba6a1 JMF |
29 | 'url': 'http://ex.fm/song/wddt8', |
30 | 'md5': '966bd70741ac5b8570d8e45bfaed3643', | |
31 | 'info_dict': { | |
32 | 'id': 'wddt8', | |
33 | 'ext': 'mp3', | |
34 | 'title': 'Safe and Sound', | |
35 | 'uploader': 'Capital Cities', | |
eb6a41ba | 36 | }, |
af6ba6a1 | 37 | 'skip': 'The site is down too often', |
eb6a41ba JMF |
38 | }, |
39 | ] | |
b6ef4029 YK |
40 | |
41 | def _real_extract(self, url): | |
42 | mobj = re.match(self._VALID_URL, url) | |
af6ba6a1 | 43 | song_id = mobj.group('id') |
611c1dd9 | 44 | info_url = 'http://ex.fm/api/v3/song/%s' % song_id |
af6ba6a1 JMF |
45 | info = self._download_json(info_url, song_id)['song'] |
46 | song_url = info['url'] | |
eb6a41ba JMF |
47 | if re.match(self._SOUNDCLOUD_URL, song_url) is not None: |
48 | self.to_screen('Soundcloud song detected') | |
af6ba6a1 JMF |
49 | return self.url_result(song_url.replace('/stream', ''), 'Soundcloud') |
50 | return { | |
51 | 'id': song_id, | |
52 | 'url': song_url, | |
53 | 'ext': 'mp3', | |
54 | 'title': info['title'], | |
55 | 'thumbnail': info['image']['large'], | |
56 | 'uploader': info['artist'], | |
57 | 'view_count': info['loved_count'], | |
58 | } |