]>
Commit | Line | Data |
---|---|---|
1 | from __future__ import unicode_literals | |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
6 | ||
7 | ||
8 | class ExfmIE(InfoExtractor): | |
9 | IE_NAME = 'exfm' | |
10 | IE_DESC = 'ex.fm' | |
11 | _VALID_URL = r'https?://(?:www\.)?ex\.fm/song/(?P<id>[^/]+)' | |
12 | _SOUNDCLOUD_URL = r'http://(?:www\.)?api\.soundcloud\.com/tracks/([^/]+)/stream' | |
13 | _TESTS = [ | |
14 | { | |
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', | |
24 | }, | |
25 | 'note': 'Soundcloud song', | |
26 | 'skip': 'The site is down too often', | |
27 | }, | |
28 | { | |
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', | |
36 | }, | |
37 | 'skip': 'The site is down too often', | |
38 | }, | |
39 | ] | |
40 | ||
41 | def _real_extract(self, url): | |
42 | mobj = re.match(self._VALID_URL, url) | |
43 | song_id = mobj.group('id') | |
44 | info_url = 'http://ex.fm/api/v3/song/%s' % song_id | |
45 | info = self._download_json(info_url, song_id)['song'] | |
46 | song_url = info['url'] | |
47 | if re.match(self._SOUNDCLOUD_URL, song_url) is not None: | |
48 | self.to_screen('Soundcloud song detected') | |
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 | } |