]>
Commit | Line | Data |
---|---|---|
67500bf9 | 1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | from .common import InfoExtractor | |
9e9bc793 | 5 | from .soundcloud import SoundcloudIE |
fdfefa1b | 6 | from ..utils import ExtractorError |
c9f08154 | 7 | |
67500bf9 | 8 | import time |
67500bf9 | 9 | |
10 | ||
11 | class AudiomackIE(InfoExtractor): | |
12 | _VALID_URL = r'https?://(?:www\.)?audiomack\.com/song/(?P<id>[\w/-]+)' | |
9e9bc793 | 13 | IE_NAME = 'audiomack' |
14 | _TESTS = [ | |
5f6a1245 | 15 | # hosted on audiomack |
9e9bc793 | 16 | { |
17 | 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary', | |
9e9bc793 | 18 | 'info_dict': |
19 | { | |
5f6a1245 | 20 | 'id': 'roosh-williams/extraordinary', |
9e9bc793 | 21 | 'ext': 'mp3', |
22 | 'title': 'Roosh Williams - Extraordinary' | |
23 | } | |
24 | }, | |
5f6a1245 | 25 | # hosted on soundcloud via audiomack |
9e9bc793 | 26 | { |
9095aa38 | 27 | 'add_ie': ['Soundcloud'], |
9e9bc793 | 28 | 'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare', |
810fb84d PH |
29 | 'info_dict': { |
30 | 'id': '172419696', | |
31 | 'ext': 'mp3', | |
9095aa38 | 32 | 'description': 'md5:1fc3272ed7a635cce5be1568c2822997', |
9e9bc793 | 33 | 'title': 'Young Thug ft Lil Wayne - Take Kare', |
810fb84d PH |
34 | 'uploader': 'Young Thug World', |
35 | 'upload_date': '20141016', | |
9e9bc793 | 36 | } |
9095aa38 | 37 | }, |
9e9bc793 | 38 | ] |
67500bf9 | 39 | |
40 | def _real_extract(self, url): | |
d3c72db8 | 41 | video_id = self._match_id(url) |
67500bf9 | 42 | |
d3c72db8 PH |
43 | api_response = self._download_json( |
44 | "http://www.audiomack.com/api/music/url/song/%s?_=%d" % ( | |
45 | video_id, time.time()), | |
46 | video_id) | |
fdfefa1b | 47 | |
d3c72db8 | 48 | if "url" not in api_response: |
fdfefa1b | 49 | raise ExtractorError("Unable to deduce api url of song") |
d3c72db8 | 50 | realurl = api_response["url"] |
9e9bc793 | 51 | |
5f6a1245 | 52 | # Audiomack wraps a lot of soundcloud tracks in their branded wrapper |
9e9bc793 | 53 | # - if so, pass the work off to the soundcloud extractor |
54 | if SoundcloudIE.suitable(realurl): | |
d36cae46 | 55 | return {'_type': 'url', 'url': realurl, 'ie_key': 'Soundcloud'} |
d3c72db8 PH |
56 | |
57 | webpage = self._download_webpage(url, video_id) | |
58 | artist = self._html_search_regex( | |
59 | r'<span class="artist">(.*?)</span>', webpage, "artist") | |
60 | songtitle = self._html_search_regex( | |
61 | r'<h1 class="profile-title song-title"><span class="artist">.*?</span>(.*?)</h1>', | |
62 | webpage, "title") | |
63 | title = artist + " - " + songtitle | |
64 | ||
65 | return { | |
66 | 'id': video_id, | |
67 | 'title': title, | |
68 | 'url': realurl, | |
69 | } |