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.

54 lines
2.0 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. _TESTS = [
  10. {
  11. u'url': u'http://ex.fm/song/eh359',
  12. u'file': u'44216187.mp3',
  13. u'md5': u'e45513df5631e6d760970b14cc0c11e7',
  14. u'info_dict': {
  15. u"title": u"Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive",
  16. u"uploader": u"deadjournalist",
  17. u'upload_date': u'20120424',
  18. u'description': u'Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive',
  19. },
  20. u'note': u'Soundcloud song',
  21. },
  22. {
  23. u'url': u'http://ex.fm/song/wddt8',
  24. u'file': u'wddt8.mp3',
  25. u'md5': u'966bd70741ac5b8570d8e45bfaed3643',
  26. u'info_dict': {
  27. u'title': u'Safe and Sound',
  28. u'uploader': u'Capital Cities',
  29. },
  30. },
  31. ]
  32. def _real_extract(self, url):
  33. mobj = re.match(self._VALID_URL, url)
  34. song_id = mobj.group(1)
  35. info_url = "http://ex.fm/api/v3/song/%s" %(song_id)
  36. webpage = self._download_webpage(info_url, song_id)
  37. info = json.loads(webpage)
  38. song_url = info['song']['url']
  39. if re.match(self._SOUNDCLOUD_URL, song_url) is not None:
  40. self.to_screen('Soundcloud song detected')
  41. return self.url_result(song_url.replace('/stream',''), 'Soundcloud')
  42. return [{
  43. 'id': song_id,
  44. 'url': song_url,
  45. 'ext': 'mp3',
  46. 'title': info['song']['title'],
  47. 'thumbnail': info['song']['image']['large'],
  48. 'uploader': info['song']['artist'],
  49. 'view_count': info['song']['loved_count'],
  50. }]