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