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.

58 lines
2.0 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. class ExfmIE(InfoExtractor):
  5. IE_NAME = 'exfm'
  6. IE_DESC = 'ex.fm'
  7. _VALID_URL = r'http://(?:www\.)?ex\.fm/song/(?P<id>[^/]+)'
  8. _SOUNDCLOUD_URL = r'http://(?:www\.)?api\.soundcloud\.com/tracks/([^/]+)/stream'
  9. _TESTS = [
  10. {
  11. 'url': 'http://ex.fm/song/eh359',
  12. 'md5': 'e45513df5631e6d760970b14cc0c11e7',
  13. 'info_dict': {
  14. 'id': '44216187',
  15. 'ext': 'mp3',
  16. 'title': 'Test House "Love Is Not Enough" (Extended Mix) DeadJournalist Exclusive',
  17. 'uploader': 'deadjournalist',
  18. 'upload_date': '20120424',
  19. 'description': 'Test House \"Love Is Not Enough\" (Extended Mix) DeadJournalist Exclusive',
  20. },
  21. 'note': 'Soundcloud song',
  22. 'skip': 'The site is down too often',
  23. },
  24. {
  25. 'url': 'http://ex.fm/song/wddt8',
  26. 'md5': '966bd70741ac5b8570d8e45bfaed3643',
  27. 'info_dict': {
  28. 'id': 'wddt8',
  29. 'ext': 'mp3',
  30. 'title': 'Safe and Sound',
  31. 'uploader': 'Capital Cities',
  32. },
  33. 'skip': 'The site is down too often',
  34. },
  35. ]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. song_id = mobj.group('id')
  39. info_url = "http://ex.fm/api/v3/song/%s" % song_id
  40. info = self._download_json(info_url, song_id)['song']
  41. song_url = info['url']
  42. if re.match(self._SOUNDCLOUD_URL, song_url) is not None:
  43. self.to_screen('Soundcloud song detected')
  44. return self.url_result(song_url.replace('/stream', ''), 'Soundcloud')
  45. return {
  46. 'id': song_id,
  47. 'url': song_url,
  48. 'ext': 'mp3',
  49. 'title': info['title'],
  50. 'thumbnail': info['image']['large'],
  51. 'uploader': info['artist'],
  52. 'view_count': info['loved_count'],
  53. }