]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/exfm.py
[veehd] Send requests twice (Fixes #2102)
[yt-dlp.git] / youtube_dl / extractor / exfm.py
CommitLineData
b6ef4029 1import re
8e5e059d 2import json
b6ef4029
YK
3
4from .common import InfoExtractor
5
6
7class ExfmIE(InfoExtractor):
03824359
PH
8 IE_NAME = u'exfm'
9 IE_DESC = u'ex.fm'
b6ef4029 10 _VALID_URL = r'(?:http://)?(?:www\.)?ex\.fm/song/([^/]+)'
c0ade33e 11 _SOUNDCLOUD_URL = r'(?:http://)?(?:www\.)?api\.soundcloud\.com/tracks/([^/]+)/stream'
eb6a41ba
JMF
12 _TESTS = [
13 {
7d8c2e07
FV
14 u'url': u'http://ex.fm/song/eh359',
15 u'file': u'44216187.mp3',
16 u'md5': u'e45513df5631e6d760970b14cc0c11e7',
eb6a41ba 17 u'info_dict': {
7d8c2e07
FV
18 u"title": u"Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive",
19 u"uploader": u"deadjournalist",
20 u'upload_date': u'20120424',
21 u'description': u'Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive',
eb6a41ba
JMF
22 },
23 u'note': u'Soundcloud song',
98d7efb5 24 u'skip': u'The site is down too often',
eb6a41ba
JMF
25 },
26 {
27 u'url': u'http://ex.fm/song/wddt8',
28 u'file': u'wddt8.mp3',
29 u'md5': u'966bd70741ac5b8570d8e45bfaed3643',
30 u'info_dict': {
31 u'title': u'Safe and Sound',
32 u'uploader': u'Capital Cities',
33 },
98d7efb5 34 u'skip': u'The site is down too often',
eb6a41ba
JMF
35 },
36 ]
b6ef4029
YK
37
38 def _real_extract(self, url):
39 mobj = re.match(self._VALID_URL, url)
233ad24e
YK
40 song_id = mobj.group(1)
41 info_url = "http://ex.fm/api/v3/song/%s" %(song_id)
42 webpage = self._download_webpage(info_url, song_id)
b6ef4029 43 info = json.loads(webpage)
eb6a41ba
JMF
44 song_url = info['song']['url']
45 if re.match(self._SOUNDCLOUD_URL, song_url) is not None:
46 self.to_screen('Soundcloud song detected')
47 return self.url_result(song_url.replace('/stream',''), 'Soundcloud')
b6ef4029 48 return [{
233ad24e 49 'id': song_id,
b6ef4029
YK
50 'url': song_url,
51 'ext': 'mp3',
52 'title': info['song']['title'],
53 'thumbnail': info['song']['image']['large'],
54 'uploader': info['song']['artist'],
55 'view_count': info['song']['loved_count'],
56 }]