+ ]
+
+ def _real_extract(self, 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)
+ result = {"_type": "playlist", "entries": []}
+ # 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
+ track_no = 0
+ while True:
+ # Get song's metadata
+ api_response = self._download_json("http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d"
+ % (album_url_tag, track_no, time.time()), album_url_tag)
+
+ # Total failure, only occurs when url is totally wrong
+ # Won't happen in middle of valid playlist (next case)
+ if "url" not in api_response or "error" in api_response:
+ raise ExtractorError("Invalid url for track %d of album url %s" % (track_no, url))
+ # URL is good but song id doesn't exist - usually means end of playlist
+ elif not api_response["url"]:
+ break
+ else:
+ # Pull out the album metadata and add to result (if it exists)
+ for resultkey, apikey in [("id", "album_id"), ("title", "album_title")]:
+ if apikey in api_response and resultkey not in result:
+ result[resultkey] = api_response[apikey]
+ result["entries"].append(AudiomackIE.create_song_dictionary(api_response, album_url_tag, track_no))
+ track_no += 1
+ return result