]>
Commit | Line | Data |
---|---|---|
904fffff PH |
1 | import itertools |
2 | import time | |
3 | ||
67500bf9 | 4 | from .common import InfoExtractor |
9e9bc793 | 5 | from .soundcloud import SoundcloudIE |
904fffff PH |
6 | from ..utils import ( |
7 | ExtractorError, | |
8 | url_basename, | |
9 | ) | |
67500bf9 | 10 | |
11 | ||
12 | class AudiomackIE(InfoExtractor): | |
2aae2c91 | 13 | _VALID_URL = r'https?://(?:www\.)?audiomack\.com/(?:song/|(?=.+/song/))(?P<id>[\w/-]+)' |
9e9bc793 | 14 | IE_NAME = 'audiomack' |
15 | _TESTS = [ | |
ff081331 | 16 | # hosted on audiomack |
9e9bc793 | 17 | { |
18 | 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary', | |
9e9bc793 | 19 | 'info_dict': |
20 | { | |
defaf19f | 21 | 'id': '310086', |
ff081331 | 22 | 'ext': 'mp3', |
904fffff | 23 | 'uploader': 'Roosh Williams', |
add96eb9 | 24 | 'title': 'Extraordinary', |
25 | }, | |
9e9bc793 | 26 | }, |
ff081331 | 27 | # audiomack wrapper around soundcloud song |
50e93e03 | 28 | # Needs new test URL. |
9e9bc793 | 29 | { |
9095aa38 | 30 | 'add_ie': ['Soundcloud'], |
6ad2ef8b | 31 | 'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle', |
810fb84d | 32 | 'info_dict': { |
6ad2ef8b | 33 | 'id': '258901379', |
810fb84d | 34 | 'ext': 'mp3', |
6ad2ef8b YCH |
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', | |
2aae2c91 AIF |
39 | }, |
40 | 'skip': 'Song has been removed from the site', | |
9095aa38 | 41 | }, |
9e9bc793 | 42 | ] |
67500bf9 | 43 | |
44 | def _real_extract(self, url): | |
2aae2c91 | 45 | # URLs end with [uploader name]/song/[uploader title] |
defaf19f YN |
46 | # this title is whatever the user types in, and is rarely |
47 | # the proper song title. Real metadata is in the api response | |
2aae2c91 | 48 | album_url_tag = self._match_id(url).replace('/song/', '/') |
67500bf9 | 49 | |
defaf19f | 50 | # Request the extended version of the api for extra fields like artist and title |
d3c72db8 | 51 | api_response = self._download_json( |
ff081331 | 52 | 'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % ( |
defaf19f YN |
53 | album_url_tag, time.time()), |
54 | album_url_tag) | |
fdfefa1b | 55 | |
defaf19f | 56 | # API is inconsistent with errors |
ff081331 | 57 | if 'url' not in api_response or not api_response['url'] or 'error' in api_response: |
add96eb9 | 58 | raise ExtractorError(f'Invalid url {url}') |
9e9bc793 | 59 | |
5f6a1245 | 60 | # Audiomack wraps a lot of soundcloud tracks in their branded wrapper |
defaf19f | 61 | # if so, pass the work off to the soundcloud extractor |
ff081331 | 62 | if SoundcloudIE.suitable(api_response['url']): |
d226c560 | 63 | return self.url_result(api_response['url'], SoundcloudIE.ie_key()) |
d3c72db8 | 64 | |
904fffff | 65 | return { |
add96eb9 | 66 | 'id': str(api_response.get('id', album_url_tag)), |
904fffff PH |
67 | 'uploader': api_response.get('artist'), |
68 | 'title': api_response.get('title'), | |
69 | 'url': api_response['url'], | |
70 | } | |
d3c72db8 | 71 | |
defaf19f YN |
72 | |
73 | class AudiomackAlbumIE(InfoExtractor): | |
2aae2c91 | 74 | _VALID_URL = r'https?://(?:www\.)?audiomack\.com/(?:album/|(?=.+/album/))(?P<id>[\w/-]+)' |
defaf19f YN |
75 | IE_NAME = 'audiomack:album' |
76 | _TESTS = [ | |
77 | # Standard album playlist | |
78 | { | |
79 | 'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape', | |
2aae2c91 | 80 | 'playlist_count': 11, |
defaf19f YN |
81 | 'info_dict': |
82 | { | |
ff081331 | 83 | 'id': '812251', |
add96eb9 | 84 | 'title': 'Tha Tour: Part 2 (Official Mixtape)', |
85 | }, | |
defaf19f YN |
86 | }, |
87 | # Album playlist ripped from fakeshoredrive with no metadata | |
88 | { | |
ff081331 | 89 | 'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project', |
7d346331 PH |
90 | 'info_dict': { |
91 | 'title': 'PPP (Pistol P Project)', | |
92 | 'id': '837572', | |
93 | }, | |
904fffff PH |
94 | 'playlist': [{ |
95 | 'info_dict': { | |
2aae2c91 AIF |
96 | 'title': 'PPP (Pistol P Project) - 8. Real (prod by SYK SENSE )', |
97 | 'id': '837576', | |
98 | 'ext': 'mp3', | |
99 | 'uploader': 'Lil Herb a.k.a. G Herbo', | |
add96eb9 | 100 | }, |
2aae2c91 AIF |
101 | }, { |
102 | 'info_dict': { | |
103 | 'title': 'PPP (Pistol P Project) - 10. 4 Minutes Of Hell Part 4 (prod by DY OF 808 MAFIA)', | |
104 | 'id': '837580', | |
904fffff | 105 | 'ext': 'mp3', |
7d346331 | 106 | 'uploader': 'Lil Herb a.k.a. G Herbo', |
add96eb9 | 107 | }, |
904fffff | 108 | }], |
add96eb9 | 109 | }, |
defaf19f YN |
110 | ] |
111 | ||
112 | def _real_extract(self, url): | |
2aae2c91 | 113 | # URLs end with [uploader name]/album/[uploader title] |
defaf19f YN |
114 | # this title is whatever the user types in, and is rarely |
115 | # the proper song title. Real metadata is in the api response | |
2aae2c91 | 116 | album_url_tag = self._match_id(url).replace('/album/', '/') |
ff081331 | 117 | result = {'_type': 'playlist', 'entries': []} |
defaf19f YN |
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 | |
904fffff | 120 | for track_no in itertools.count(): |
defaf19f | 121 | # Get song's metadata |
904fffff PH |
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, | |
add96eb9 | 125 | note=f'Querying song information ({track_no + 1})') |
defaf19f YN |
126 | |
127 | # Total failure, only occurs when url is totally wrong | |
128 | # Won't happen in middle of valid playlist (next case) | |
ff081331 | 129 | if 'url' not in api_response or 'error' in api_response: |
add96eb9 | 130 | raise ExtractorError(f'Invalid url for track {track_no} of album url {url}') |
defaf19f | 131 | # URL is good but song id doesn't exist - usually means end of playlist |
ff081331 | 132 | elif not api_response['url']: |
defaf19f YN |
133 | break |
134 | else: | |
135 | # Pull out the album metadata and add to result (if it exists) | |
ff081331 | 136 | for resultkey, apikey in [('id', 'album_id'), ('title', 'album_title')]: |
defaf19f | 137 | if apikey in api_response and resultkey not in result: |
add96eb9 | 138 | result[resultkey] = str(api_response[apikey]) |
904fffff PH |
139 | song_id = url_basename(api_response['url']).rpartition('.')[0] |
140 | result['entries'].append({ | |
add96eb9 | 141 | 'id': str(api_response.get('id', song_id)), |
904fffff PH |
142 | 'uploader': api_response.get('artist'), |
143 | 'title': api_response.get('title', song_id), | |
144 | 'url': api_response['url'], | |
145 | }) | |
defaf19f | 146 | return result |