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.

67 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .soundcloud import SoundcloudIE
  5. from ..utils import ExtractorError
  6. import datetime
  7. import time
  8. class AudiomackIE(InfoExtractor):
  9. _VALID_URL = r'https?://(?:www\.)?audiomack\.com/song/(?P<id>[\w/-]+)'
  10. IE_NAME = 'audiomack'
  11. _TESTS = [
  12. #hosted on audiomack
  13. {
  14. 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
  15. 'info_dict':
  16. {
  17. 'id' : 'roosh-williams/extraordinary',
  18. 'ext': 'mp3',
  19. 'title': 'Roosh Williams - Extraordinary'
  20. }
  21. },
  22. #hosted on soundcloud via audiomack
  23. {
  24. 'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare',
  25. 'file': '172419696.mp3',
  26. 'info_dict':
  27. {
  28. 'ext': 'mp3',
  29. 'title': 'Young Thug ft Lil Wayne - Take Kare',
  30. "upload_date": "20141016",
  31. "description": "New track produced by London On Da Track called “Take Kare\"\n\nhttp://instagram.com/theyoungthugworld\nhttps://www.facebook.com/ThuggerThuggerCashMoney\n",
  32. "uploader": "Young Thug World"
  33. }
  34. }
  35. ]
  36. def _real_extract(self, url):
  37. #id is what follows /song/ in url, usually the uploader name + title
  38. id = self._match_id(url)
  39. #Call the api, which gives us a json doc with the real url inside
  40. rightnow = int(time.time())
  41. apiresponse = self._download_json("http://www.audiomack.com/api/music/url/song/"+id+"?_="+str(rightnow), id)
  42. if "url" not in apiresponse:
  43. raise ExtractorError("Unable to deduce api url of song")
  44. realurl = apiresponse["url"]
  45. #Audiomack wraps a lot of soundcloud tracks in their branded wrapper
  46. # - if so, pass the work off to the soundcloud extractor
  47. if SoundcloudIE.suitable(realurl):
  48. return {'_type': 'url', 'url': realurl, 'ie_key': 'Soundcloud'}
  49. else:
  50. #Pull out metadata
  51. page = self._download_webpage(url, id)
  52. artist = self._html_search_regex(r'<span class="artist">(.*)</span>', page, "artist")
  53. songtitle = self._html_search_regex(r'<h1 class="profile-title song-title"><span class="artist">.*</span>(.*)</h1>', page, "title")
  54. title = artist+" - "+songtitle
  55. return {
  56. 'id': id, # ignore id, which is not useful in song name
  57. 'title': title,
  58. 'url': realurl,
  59. 'ext': 'mp3'
  60. }