2015-01-10 01:24:46 +00:00
|
|
|
import itertools
|
|
|
|
import time
|
|
|
|
|
2014-10-23 21:55:39 +00:00
|
|
|
from .common import InfoExtractor
|
2014-10-24 04:54:59 +00:00
|
|
|
from .soundcloud import SoundcloudIE
|
2015-01-10 01:24:46 +00:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
url_basename,
|
|
|
|
)
|
2014-10-23 21:55:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AudiomackIE(InfoExtractor):
|
2021-12-20 01:53:42 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?audiomack\.com/(?:song/|(?=.+/song/))(?P<id>[\w/-]+)'
|
2014-10-24 04:54:59 +00:00
|
|
|
IE_NAME = 'audiomack'
|
|
|
|
_TESTS = [
|
2015-01-09 00:35:33 +00:00
|
|
|
# hosted on audiomack
|
2014-10-24 04:54:59 +00:00
|
|
|
{
|
|
|
|
'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
|
|
|
|
'info_dict':
|
|
|
|
{
|
2015-01-02 08:20:04 +00:00
|
|
|
'id': '310086',
|
2015-01-09 00:35:33 +00:00
|
|
|
'ext': 'mp3',
|
2015-01-10 01:24:46 +00:00
|
|
|
'uploader': 'Roosh Williams',
|
2024-06-11 23:09:58 +00:00
|
|
|
'title': 'Extraordinary',
|
|
|
|
},
|
2014-10-24 04:54:59 +00:00
|
|
|
},
|
2015-01-09 00:35:33 +00:00
|
|
|
# audiomack wrapper around soundcloud song
|
2022-03-04 17:01:04 +00:00
|
|
|
# Needs new test URL.
|
2014-10-24 04:54:59 +00:00
|
|
|
{
|
2014-12-03 13:53:12 +00:00
|
|
|
'add_ie': ['Soundcloud'],
|
2016-04-16 09:54:39 +00:00
|
|
|
'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle',
|
2014-12-04 07:27:40 +00:00
|
|
|
'info_dict': {
|
2016-04-16 09:54:39 +00:00
|
|
|
'id': '258901379',
|
2014-12-04 07:27:40 +00:00
|
|
|
'ext': 'mp3',
|
2016-04-16 09:54:39 +00:00
|
|
|
'description': 'mamba day freestyle for the legend Kobe Bryant ',
|
|
|
|
'title': 'Black Mamba Freestyle [Prod. By Danny Wolf]',
|
|
|
|
'uploader': 'ILOVEMAKONNEN',
|
|
|
|
'upload_date': '20160414',
|
2021-12-20 01:53:42 +00:00
|
|
|
},
|
|
|
|
'skip': 'Song has been removed from the site',
|
2014-12-03 13:53:12 +00:00
|
|
|
},
|
2014-10-24 04:54:59 +00:00
|
|
|
]
|
2014-10-23 21:55:39 +00:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-12-20 01:53:42 +00:00
|
|
|
# URLs end with [uploader name]/song/[uploader title]
|
2015-01-02 08:20:04 +00:00
|
|
|
# this title is whatever the user types in, and is rarely
|
|
|
|
# the proper song title. Real metadata is in the api response
|
2021-12-20 01:53:42 +00:00
|
|
|
album_url_tag = self._match_id(url).replace('/song/', '/')
|
2014-10-23 21:55:39 +00:00
|
|
|
|
2015-01-02 08:20:04 +00:00
|
|
|
# Request the extended version of the api for extra fields like artist and title
|
2014-10-25 06:58:03 +00:00
|
|
|
api_response = self._download_json(
|
2024-11-22 22:11:00 +00:00
|
|
|
f'http://www.audiomack.com/api/music/url/song/{album_url_tag}?extended=1&_={int(time.time())}',
|
2015-01-02 08:20:04 +00:00
|
|
|
album_url_tag)
|
2014-10-25 02:07:01 +00:00
|
|
|
|
2015-01-02 08:20:04 +00:00
|
|
|
# API is inconsistent with errors
|
2015-01-09 00:35:33 +00:00
|
|
|
if 'url' not in api_response or not api_response['url'] or 'error' in api_response:
|
2024-06-11 23:09:58 +00:00
|
|
|
raise ExtractorError(f'Invalid url {url}')
|
2014-10-24 04:54:59 +00:00
|
|
|
|
2014-11-23 19:41:03 +00:00
|
|
|
# Audiomack wraps a lot of soundcloud tracks in their branded wrapper
|
2015-01-02 08:20:04 +00:00
|
|
|
# if so, pass the work off to the soundcloud extractor
|
2015-01-09 00:35:33 +00:00
|
|
|
if SoundcloudIE.suitable(api_response['url']):
|
2019-01-01 16:56:05 +00:00
|
|
|
return self.url_result(api_response['url'], SoundcloudIE.ie_key())
|
2014-10-25 06:58:03 +00:00
|
|
|
|
2015-01-10 01:24:46 +00:00
|
|
|
return {
|
2024-06-11 23:09:58 +00:00
|
|
|
'id': str(api_response.get('id', album_url_tag)),
|
2015-01-10 01:24:46 +00:00
|
|
|
'uploader': api_response.get('artist'),
|
|
|
|
'title': api_response.get('title'),
|
|
|
|
'url': api_response['url'],
|
|
|
|
}
|
2014-10-25 06:58:03 +00:00
|
|
|
|
2015-01-02 08:20:04 +00:00
|
|
|
|
|
|
|
class AudiomackAlbumIE(InfoExtractor):
|
2021-12-20 01:53:42 +00:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?audiomack\.com/(?:album/|(?=.+/album/))(?P<id>[\w/-]+)'
|
2015-01-02 08:20:04 +00:00
|
|
|
IE_NAME = 'audiomack:album'
|
|
|
|
_TESTS = [
|
|
|
|
# Standard album playlist
|
|
|
|
{
|
|
|
|
'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
|
2021-12-20 01:53:42 +00:00
|
|
|
'playlist_count': 11,
|
2015-01-02 08:20:04 +00:00
|
|
|
'info_dict':
|
|
|
|
{
|
2015-01-09 00:35:33 +00:00
|
|
|
'id': '812251',
|
2024-06-11 23:09:58 +00:00
|
|
|
'title': 'Tha Tour: Part 2 (Official Mixtape)',
|
|
|
|
},
|
2015-01-02 08:20:04 +00:00
|
|
|
},
|
|
|
|
# Album playlist ripped from fakeshoredrive with no metadata
|
|
|
|
{
|
2015-01-09 00:35:33 +00:00
|
|
|
'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project',
|
2015-01-25 04:15:47 +00:00
|
|
|
'info_dict': {
|
|
|
|
'title': 'PPP (Pistol P Project)',
|
|
|
|
'id': '837572',
|
|
|
|
},
|
2015-01-10 01:24:46 +00:00
|
|
|
'playlist': [{
|
|
|
|
'info_dict': {
|
2021-12-20 01:53:42 +00:00
|
|
|
'title': 'PPP (Pistol P Project) - 8. Real (prod by SYK SENSE )',
|
|
|
|
'id': '837576',
|
|
|
|
'ext': 'mp3',
|
|
|
|
'uploader': 'Lil Herb a.k.a. G Herbo',
|
2024-06-11 23:09:58 +00:00
|
|
|
},
|
2021-12-20 01:53:42 +00:00
|
|
|
}, {
|
|
|
|
'info_dict': {
|
|
|
|
'title': 'PPP (Pistol P Project) - 10. 4 Minutes Of Hell Part 4 (prod by DY OF 808 MAFIA)',
|
|
|
|
'id': '837580',
|
2015-01-10 01:24:46 +00:00
|
|
|
'ext': 'mp3',
|
2015-01-25 04:15:47 +00:00
|
|
|
'uploader': 'Lil Herb a.k.a. G Herbo',
|
2024-06-11 23:09:58 +00:00
|
|
|
},
|
2015-01-10 01:24:46 +00:00
|
|
|
}],
|
2024-06-11 23:09:58 +00:00
|
|
|
},
|
2015-01-02 08:20:04 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-12-20 01:53:42 +00:00
|
|
|
# URLs end with [uploader name]/album/[uploader title]
|
2015-01-02 08:20:04 +00:00
|
|
|
# this title is whatever the user types in, and is rarely
|
|
|
|
# the proper song title. Real metadata is in the api response
|
2021-12-20 01:53:42 +00:00
|
|
|
album_url_tag = self._match_id(url).replace('/album/', '/')
|
2015-01-09 00:35:33 +00:00
|
|
|
result = {'_type': 'playlist', 'entries': []}
|
2015-01-02 08:20:04 +00:00
|
|
|
# There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata
|
|
|
|
# Therefore we don't know how many songs the album has and must infi-loop until failure
|
2015-01-10 01:24:46 +00:00
|
|
|
for track_no in itertools.count():
|
2015-01-02 08:20:04 +00:00
|
|
|
# Get song's metadata
|
2015-01-10 01:24:46 +00:00
|
|
|
api_response = self._download_json(
|
2024-11-22 22:11:00 +00:00
|
|
|
f'http://www.audiomack.com/api/music/url/album/{album_url_tag}/{track_no}?extended=1&_={int(time.time())}',
|
|
|
|
album_url_tag, note=f'Querying song information ({track_no + 1})')
|
2015-01-02 08:20:04 +00:00
|
|
|
|
|
|
|
# Total failure, only occurs when url is totally wrong
|
|
|
|
# Won't happen in middle of valid playlist (next case)
|
2015-01-09 00:35:33 +00:00
|
|
|
if 'url' not in api_response or 'error' in api_response:
|
2024-06-11 23:09:58 +00:00
|
|
|
raise ExtractorError(f'Invalid url for track {track_no} of album url {url}')
|
2015-01-02 08:20:04 +00:00
|
|
|
# URL is good but song id doesn't exist - usually means end of playlist
|
2015-01-09 00:35:33 +00:00
|
|
|
elif not api_response['url']:
|
2015-01-02 08:20:04 +00:00
|
|
|
break
|
|
|
|
else:
|
|
|
|
# Pull out the album metadata and add to result (if it exists)
|
2015-01-09 00:35:33 +00:00
|
|
|
for resultkey, apikey in [('id', 'album_id'), ('title', 'album_title')]:
|
2015-01-02 08:20:04 +00:00
|
|
|
if apikey in api_response and resultkey not in result:
|
2024-06-11 23:09:58 +00:00
|
|
|
result[resultkey] = str(api_response[apikey])
|
2015-01-10 01:24:46 +00:00
|
|
|
song_id = url_basename(api_response['url']).rpartition('.')[0]
|
|
|
|
result['entries'].append({
|
2024-06-11 23:09:58 +00:00
|
|
|
'id': str(api_response.get('id', song_id)),
|
2015-01-10 01:24:46 +00:00
|
|
|
'uploader': api_response.get('artist'),
|
|
|
|
'title': api_response.get('title', song_id),
|
|
|
|
'url': api_response['url'],
|
|
|
|
})
|
2015-01-02 08:20:04 +00:00
|
|
|
return result
|