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.

69 lines
2.4 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. video_id = self._match_id(url)
  38. api_response = self._download_json(
  39. "http://www.audiomack.com/api/music/url/song/%s?_=%d" % (
  40. video_id, time.time()),
  41. video_id)
  42. if "url" not in api_response:
  43. raise ExtractorError("Unable to deduce api url of song")
  44. realurl = api_response["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. webpage = self._download_webpage(url, video_id)
  50. artist = self._html_search_regex(
  51. r'<span class="artist">(.*?)</span>', webpage, "artist")
  52. songtitle = self._html_search_regex(
  53. r'<h1 class="profile-title song-title"><span class="artist">.*?</span>(.*?)</h1>',
  54. webpage, "title")
  55. title = artist + " - " + songtitle
  56. return {
  57. 'id': video_id,
  58. 'title': title,
  59. 'url': realurl,
  60. }