audiomack.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 time
  7. class AudiomackIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?audiomack\.com/song/(?P<id>[\w/-]+)'
  9. IE_NAME = 'audiomack'
  10. _TESTS = [
  11. # hosted on audiomack
  12. {
  13. 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
  14. 'info_dict':
  15. {
  16. 'id': 'roosh-williams/extraordinary',
  17. 'ext': 'mp3',
  18. 'title': 'Roosh Williams - Extraordinary'
  19. }
  20. },
  21. # hosted on soundcloud via audiomack
  22. {
  23. 'add_ie': ['Soundcloud'],
  24. 'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare',
  25. 'info_dict':
  26. {
  27. 'id': '172419696',
  28. 'ext': 'mp3',
  29. 'description': 'md5:1fc3272ed7a635cce5be1568c2822997',
  30. 'title': 'Young Thug ft Lil Wayne - Take Kare',
  31. 'uploader':'Young Thug World',
  32. 'upload_date':'20141016',
  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. }