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.

56 lines
2.1 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. u'skip': u'The site is down too often',
  22. },
  23. {
  24. u'url': u'http://ex.fm/song/wddt8',
  25. u'file': u'wddt8.mp3',
  26. u'md5': u'966bd70741ac5b8570d8e45bfaed3643',
  27. u'info_dict': {
  28. u'title': u'Safe and Sound',
  29. u'uploader': u'Capital Cities',
  30. },
  31. u'skip': u'The site is down too often',
  32. },
  33. ]
  34. def _real_extract(self, url):
  35. mobj = re.match(self._VALID_URL, url)
  36. song_id = mobj.group(1)
  37. info_url = "http://ex.fm/api/v3/song/%s" %(song_id)
  38. webpage = self._download_webpage(info_url, song_id)
  39. info = json.loads(webpage)
  40. song_url = info['song']['url']
  41. if re.match(self._SOUNDCLOUD_URL, song_url) is not None:
  42. self.to_screen('Soundcloud song detected')
  43. return self.url_result(song_url.replace('/stream',''), 'Soundcloud')
  44. return [{
  45. 'id': song_id,
  46. 'url': song_url,
  47. 'ext': 'mp3',
  48. 'title': info['song']['title'],
  49. 'thumbnail': info['song']['image']['large'],
  50. 'uploader': info['song']['artist'],
  51. 'view_count': info['song']['loved_count'],
  52. }]