mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-20 03:54:01 +00:00
Minor style changes
This commit is contained in:
parent
defaf19f5d
commit
ff0813313a
@ -9,21 +9,21 @@ import time
|
|||||||
|
|
||||||
|
|
||||||
class AudiomackIE(InfoExtractor):
|
class AudiomackIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?audiomack\.com/(song)/(?P<id>[\w/-]+)'
|
_VALID_URL = r'https?://(?:www\.)?audiomack\.com/song/(?P<id>[\w/-]+)'
|
||||||
IE_NAME = 'audiomack'
|
IE_NAME = 'audiomack'
|
||||||
_TESTS = [
|
_TESTS = [
|
||||||
# audiomack
|
# hosted on audiomack
|
||||||
{
|
{
|
||||||
'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
|
'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
|
||||||
'info_dict':
|
'info_dict':
|
||||||
{
|
{
|
||||||
'id': '310086',
|
'id': '310086',
|
||||||
"ext": "mp3",
|
'ext': 'mp3',
|
||||||
"artist": "Roosh Williams",
|
'artist': 'Roosh Williams',
|
||||||
'title': 'Extraordinary'
|
'title': 'Extraordinary'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
# audiomack through soundcloud
|
# audiomack wrapper around soundcloud song
|
||||||
{
|
{
|
||||||
'add_ie': ['Soundcloud'],
|
'add_ie': ['Soundcloud'],
|
||||||
'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare',
|
'url': 'http://www.audiomack.com/song/xclusiveszone/take-kare',
|
||||||
@ -41,12 +41,12 @@ class AudiomackIE(InfoExtractor):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def create_song_dictionary(api_response, album_url_tag, track_no=0):
|
def create_song_dictionary(api_response, album_url_tag, track_no=0):
|
||||||
# All keys are the same in audiomack api and InfoExtractor format
|
# All keys are the same in audiomack api and InfoExtractor format
|
||||||
entry = {key: api_response[key] for key in ["title", "artist", "id", "url"] if key in api_response}
|
entry = {key: api_response[key] for key in ['title', 'artist', 'id', 'url'] if key in api_response}
|
||||||
# Fudge values in the face of missing metadata
|
# Fudge values in the face of missing metadata
|
||||||
if "id" not in entry:
|
if 'id' not in entry:
|
||||||
entry["id"] = track_no
|
entry['id'] = track_no
|
||||||
if "title" not in entry:
|
if 'title' not in entry:
|
||||||
entry["title"] = album_url_tag
|
entry['title'] = album_url_tag
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
@ -57,18 +57,18 @@ class AudiomackIE(InfoExtractor):
|
|||||||
|
|
||||||
# Request the extended version of the api for extra fields like artist and title
|
# Request the extended version of the api for extra fields like artist and title
|
||||||
api_response = self._download_json(
|
api_response = self._download_json(
|
||||||
"http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d" % (
|
'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % (
|
||||||
album_url_tag, time.time()),
|
album_url_tag, time.time()),
|
||||||
album_url_tag)
|
album_url_tag)
|
||||||
|
|
||||||
# API is inconsistent with errors
|
# API is inconsistent with errors
|
||||||
if "url" not in api_response or not api_response["url"] or "error" in api_response:
|
if 'url' not in api_response or not api_response['url'] or 'error' in api_response:
|
||||||
raise ExtractorError("Invalid url %s", url)
|
raise ExtractorError('Invalid url %s', url)
|
||||||
|
|
||||||
# Audiomack wraps a lot of soundcloud tracks in their branded wrapper
|
# Audiomack wraps a lot of soundcloud tracks in their branded wrapper
|
||||||
# if so, pass the work off to the soundcloud extractor
|
# if so, pass the work off to the soundcloud extractor
|
||||||
if SoundcloudIE.suitable(api_response["url"]):
|
if SoundcloudIE.suitable(api_response['url']):
|
||||||
return {'_type': 'url', 'url': api_response["url"], 'ie_key': 'Soundcloud'}
|
return {'_type': 'url', 'url': api_response['url'], 'ie_key': 'Soundcloud'}
|
||||||
|
|
||||||
return self.create_song_dictionary(api_response, album_url_tag)
|
return self.create_song_dictionary(api_response, album_url_tag)
|
||||||
|
|
||||||
@ -80,17 +80,17 @@ class AudiomackAlbumIE(InfoExtractor):
|
|||||||
# Standard album playlist
|
# Standard album playlist
|
||||||
{
|
{
|
||||||
'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
|
'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
|
||||||
"playlist_count": 15,
|
'playlist_count': 15,
|
||||||
'info_dict':
|
'info_dict':
|
||||||
{
|
{
|
||||||
'id': "812251",
|
'id': '812251',
|
||||||
'title': "Tha Tour: Part 2 (Official Mixtape)"
|
'title': 'Tha Tour: Part 2 (Official Mixtape)'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
# Album playlist ripped from fakeshoredrive with no metadata
|
# Album playlist ripped from fakeshoredrive with no metadata
|
||||||
{
|
{
|
||||||
"url": "http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project",
|
'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project',
|
||||||
"playlist_count": 10
|
'playlist_count': 10
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -99,27 +99,27 @@ class AudiomackAlbumIE(InfoExtractor):
|
|||||||
# this title is whatever the user types in, and is rarely
|
# this title is whatever the user types in, and is rarely
|
||||||
# the proper song title. Real metadata is in the api response
|
# the proper song title. Real metadata is in the api response
|
||||||
album_url_tag = self._match_id(url)
|
album_url_tag = self._match_id(url)
|
||||||
result = {"_type": "playlist", "entries": []}
|
result = {'_type': 'playlist', 'entries': []}
|
||||||
# There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata
|
# 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
|
# Therefore we don't know how many songs the album has and must infi-loop until failure
|
||||||
track_no = 0
|
track_no = 0
|
||||||
while True:
|
while True:
|
||||||
# Get song's metadata
|
# Get song's metadata
|
||||||
api_response = self._download_json("http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d"
|
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)
|
% (album_url_tag, track_no, time.time()), album_url_tag)
|
||||||
|
|
||||||
# Total failure, only occurs when url is totally wrong
|
# Total failure, only occurs when url is totally wrong
|
||||||
# Won't happen in middle of valid playlist (next case)
|
# Won't happen in middle of valid playlist (next case)
|
||||||
if "url" not in api_response or "error" in api_response:
|
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))
|
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
|
# URL is good but song id doesn't exist - usually means end of playlist
|
||||||
elif not api_response["url"]:
|
elif not api_response['url']:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# Pull out the album metadata and add to result (if it exists)
|
# Pull out the album metadata and add to result (if it exists)
|
||||||
for resultkey, apikey in [("id", "album_id"), ("title", "album_title")]:
|
for resultkey, apikey in [('id', 'album_id'), ('title', 'album_title')]:
|
||||||
if apikey in api_response and resultkey not in result:
|
if apikey in api_response and resultkey not in result:
|
||||||
result[resultkey] = api_response[apikey]
|
result[resultkey] = api_response[apikey]
|
||||||
result["entries"].append(AudiomackIE.create_song_dictionary(api_response, album_url_tag, track_no))
|
result['entries'].append(AudiomackIE.create_song_dictionary(api_response, album_url_tag, track_no))
|
||||||
track_no += 1
|
track_no += 1
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user