4 from .common
import InfoExtractor
5 from .soundcloud
import SoundcloudIE
12 class AudiomackIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:song/|(?=.+/song/))(?P<id>[\w/-]+)'
18 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
23 'uploader': 'Roosh Williams',
24 'title': 'Extraordinary',
27 # audiomack wrapper around soundcloud song
30 'add_ie': ['Soundcloud'],
31 'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle',
35 'description': 'mamba day freestyle for the legend Kobe Bryant ',
36 'title': 'Black Mamba Freestyle [Prod. By Danny Wolf]',
37 'uploader': 'ILOVEMAKONNEN',
38 'upload_date': '20160414',
40 'skip': 'Song has been removed from the site',
44 def _real_extract(self
, url
):
45 # URLs end with [uploader name]/song/[uploader title]
46 # this title is whatever the user types in, and is rarely
47 # the proper song title. Real metadata is in the api response
48 album_url_tag
= self
._match
_id
(url
).replace('/song/', '/')
50 # Request the extended version of the api for extra fields like artist and title
51 api_response
= self
._download
_json
(
52 'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % (
53 album_url_tag
, time
.time()),
56 # API is inconsistent with errors
57 if 'url' not in api_response
or not api_response
['url'] or 'error' in api_response
:
58 raise ExtractorError(f
'Invalid url {url}')
60 # Audiomack wraps a lot of soundcloud tracks in their branded wrapper
61 # if so, pass the work off to the soundcloud extractor
62 if SoundcloudIE
.suitable(api_response
['url']):
63 return self
.url_result(api_response
['url'], SoundcloudIE
.ie_key())
66 'id': str(api_response
.get('id', album_url_tag
)),
67 'uploader': api_response
.get('artist'),
68 'title': api_response
.get('title'),
69 'url': api_response
['url'],
73 class AudiomackAlbumIE(InfoExtractor
):
74 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:album/|(?=.+/album/))(?P<id>[\w/-]+)'
75 IE_NAME
= 'audiomack:album'
77 # Standard album playlist
79 'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
84 'title': 'Tha Tour: Part 2 (Official Mixtape)',
87 # Album playlist ripped from fakeshoredrive with no metadata
89 'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project',
91 'title': 'PPP (Pistol P Project)',
96 'title': 'PPP (Pistol P Project) - 8. Real (prod by SYK SENSE )',
99 'uploader': 'Lil Herb a.k.a. G Herbo',
103 'title': 'PPP (Pistol P Project) - 10. 4 Minutes Of Hell Part 4 (prod by DY OF 808 MAFIA)',
106 'uploader': 'Lil Herb a.k.a. G Herbo',
112 def _real_extract(self
, url
):
113 # URLs end with [uploader name]/album/[uploader title]
114 # this title is whatever the user types in, and is rarely
115 # the proper song title. Real metadata is in the api response
116 album_url_tag
= self
._match
_id
(url
).replace('/album/', '/')
117 result
= {'_type': 'playlist', 'entries': []}
118 # There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata
119 # Therefore we don't know how many songs the album has and must infi-loop until failure
120 for track_no
in itertools
.count():
121 # Get song's metadata
122 api_response
= self
._download
_json
(
123 'http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d'
124 % (album_url_tag
, track_no
, time
.time()), album_url_tag
,
125 note
=f
'Querying song information ({track_no + 1})')
127 # Total failure, only occurs when url is totally wrong
128 # Won't happen in middle of valid playlist (next case)
129 if 'url' not in api_response
or 'error' in api_response
:
130 raise ExtractorError(f
'Invalid url for track {track_no} of album url {url}')
131 # URL is good but song id doesn't exist - usually means end of playlist
132 elif not api_response
['url']:
135 # Pull out the album metadata and add to result (if it exists)
136 for resultkey
, apikey
in [('id', 'album_id'), ('title', 'album_title')]:
137 if apikey
in api_response
and resultkey
not in result
:
138 result
[resultkey
] = str(api_response
[apikey
])
139 song_id
= url_basename(api_response
['url']).rpartition('.')[0]
140 result
['entries'].append({
141 'id': str(api_response
.get('id', song_id
)),
142 'uploader': api_response
.get('artist'),
143 'title': api_response
.get('title', song_id
),
144 'url': api_response
['url'],