X-Git-Url: https://git.rapsys.eu/youtubedl/blobdiff_plain/0cf0312991a54458a07e903da2e47e9f3c8855ae..647c9744516f7b5be3611b67e02201fb0146a638:/youtube_dl/extractor/audiomack.py?ds=sidebyside diff --git a/youtube_dl/extractor/audiomack.py b/youtube_dl/extractor/audiomack.py index eeeec76..cc77713 100644 --- a/youtube_dl/extractor/audiomack.py +++ b/youtube_dl/extractor/audiomack.py @@ -1,11 +1,16 @@ # coding: utf-8 from __future__ import unicode_literals +import itertools +import time + from .common import InfoExtractor from .soundcloud import SoundcloudIE -from ..utils import ExtractorError - -import time +from ..compat import compat_str +from ..utils import ( + ExtractorError, + url_basename, +) class AudiomackIE(InfoExtractor): @@ -17,53 +22,124 @@ class AudiomackIE(InfoExtractor): 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary', 'info_dict': { - 'id': 'roosh-williams/extraordinary', + 'id': '310086', 'ext': 'mp3', - 'title': 'Roosh Williams - Extraordinary' + 'uploader': 'Roosh Williams', + 'title': 'Extraordinary' } }, - # hosted on soundcloud via audiomack + # audiomack wrapper around soundcloud song { - 'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare', - 'file': '172419696.mp3', - 'info_dict': - { + 'add_ie': ['Soundcloud'], + 'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle', + 'info_dict': { + 'id': '258901379', 'ext': 'mp3', - 'title': 'Young Thug ft Lil Wayne - Take Kare', - "upload_date": "20141016", - "description": "New track produced by London On Da Track called âTake Kare\"\n\nhttp://instagram.com/theyoungthugworld\nhttps://www.facebook.com/ThuggerThuggerCashMoney\n", - "uploader": "Young Thug World" + 'description': 'mamba day freestyle for the legend Kobe Bryant ', + 'title': 'Black Mamba Freestyle [Prod. By Danny Wolf]', + 'uploader': 'ILOVEMAKONNEN', + 'upload_date': '20160414', } - } + }, ] def _real_extract(self, url): - video_id = self._match_id(url) + # URLs end with [uploader name]/[uploader title] + # this title is whatever the user types in, and is rarely + # the proper song title. Real metadata is in the api response + album_url_tag = self._match_id(url) + # Request the extended version of the api for extra fields like artist and title api_response = self._download_json( - "http://www.audiomack.com/api/music/url/song/%s?_=%d" % ( - video_id, time.time()), - video_id) + 'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % ( + album_url_tag, time.time()), + album_url_tag) - if "url" not in api_response: - raise ExtractorError("Unable to deduce api url of song") - realurl = api_response["url"] + # API is inconsistent with errors + if 'url' not in api_response or not api_response['url'] or 'error' in api_response: + raise ExtractorError('Invalid url %s' % url) # Audiomack wraps a lot of soundcloud tracks in their branded wrapper - # - if so, pass the work off to the soundcloud extractor - if SoundcloudIE.suitable(realurl): - return {'_type': 'url', 'url': realurl, 'ie_key': 'Soundcloud'} - - webpage = self._download_webpage(url, video_id) - artist = self._html_search_regex( - r'(.*?)', webpage, "artist") - songtitle = self._html_search_regex( - r'