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.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  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. 'id': '172419696',
  27. 'ext': 'mp3',
  28. 'description': 'md5:1fc3272ed7a635cce5be1568c2822997',
  29. 'title': 'Young Thug ft Lil Wayne - Take Kare',
  30. 'uploader': 'Young Thug World',
  31. 'upload_date': '20141016',
  32. }
  33. },
  34. ]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. api_response = self._download_json(
  38. "http://www.audiomack.com/api/music/url/song/%s?_=%d" % (
  39. video_id, time.time()),
  40. video_id)
  41. if "url" not in api_response:
  42. raise ExtractorError("Unable to deduce api url of song")
  43. realurl = api_response["url"]
  44. # Audiomack wraps a lot of soundcloud tracks in their branded wrapper
  45. # - if so, pass the work off to the soundcloud extractor
  46. if SoundcloudIE.suitable(realurl):
  47. return {'_type': 'url', 'url': realurl, 'ie_key': 'Soundcloud'}
  48. webpage = self._download_webpage(url, video_id)
  49. artist = self._html_search_regex(
  50. r'<span class="artist">(.*?)</span>', webpage, "artist")
  51. songtitle = self._html_search_regex(
  52. r'<h1 class="profile-title song-title"><span class="artist">.*?</span>(.*?)</h1>',
  53. webpage, "title")
  54. title = artist + " - " + songtitle
  55. return {
  56. 'id': video_id,
  57. 'title': title,
  58. 'url': realurl,
  59. }