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