You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.5 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. class ExfmIE(InfoExtractor):
  5. IE_NAME = u'exfm'
  6. IE_DESC = u'ex.fm'
  7. _VALID_URL = r'(?:http://)?(?:www\.)?ex\.fm/song/([^/]+)'
  8. _SOUNDCLOUD_URL_ = r'(?:http://)?(?:www\.)?api\.soundcloud.com/tracks/([^/]+)/stream'
  9. _TEST = {
  10. u'url': u'http://ex.fm/song/1bgtzg',
  11. u'file': u'1bgtzg.mp3',
  12. u'md5': u'8a7967a3fef10e59a1d6f86240fd41cf',
  13. u'info_dict': {
  14. u"title": u"We Can't Stop",
  15. u"uploader": u"Miley Cyrus",
  16. u'thumbnail': u'http://i1.sndcdn.com/artworks-000049666230-w9i7ef-t500x500.jpg?9d68d37'
  17. }
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. song_id = mobj.group(1)
  22. info_url = "http://ex.fm/api/v3/song/%s" %(song_id)
  23. webpage = self._download_webpage(info_url, song_id)
  24. info = json.loads(webpage)
  25. song_url = re.match(self._SOUNDCLOUD_URL_,info['song']['url'])
  26. if song_url is not None:
  27. song_url = song_url.group() + "?client_id=b45b1aa10f1ac2941910a7f0d10f8e28"
  28. else:
  29. song_url = info['song']['url']
  30. return [{
  31. 'id': song_id,
  32. 'url': song_url,
  33. 'ext': 'mp3',
  34. 'title': info['song']['title'],
  35. 'thumbnail': info['song']['image']['large'],
  36. 'uploader': info['song']['artist'],
  37. 'view_count': info['song']['loved_count'],
  38. }]