4 from .common
import InfoExtractor
5 from .soundcloud
import SoundcloudIE
6 from ..compat
import compat_str
13 class AudiomackIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:song/|(?=.+/song/))(?P<id>[\w/-]+)'
19 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
24 'uploader': 'Roosh Williams',
25 'title': 'Extraordinary'
28 # audiomack wrapper around soundcloud song
31 'add_ie': ['Soundcloud'],
32 'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle',
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',
41 'skip': 'Song has been removed from the site',
45 def _real_extract(self
, url
):
46 # URLs end with [uploader name]/song/[uploader title]
47 # this title is whatever the user types in, and is rarely
48 # the proper song title. Real metadata is in the api response
49 album_url_tag
= self
._match
_id
(url
).replace('/song/', '/')
51 # Request the extended version of the api for extra fields like artist and title
52 api_response
= self
._download
_json
(
53 'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % (
54 album_url_tag
, time
.time()),
57 # API is inconsistent with errors
58 if 'url' not in api_response
or not api_response
['url'] or 'error' in api_response
:
59 raise ExtractorError('Invalid url %s' % url
)
61 # Audiomack wraps a lot of soundcloud tracks in their branded wrapper
62 # if so, pass the work off to the soundcloud extractor
63 if SoundcloudIE
.suitable(api_response
['url']):
64 return self
.url_result(api_response
['url'], SoundcloudIE
.ie_key())
67 'id': compat_str(api_response
.get('id', album_url_tag
)),
68 'uploader': api_response
.get('artist'),
69 'title': api_response
.get('title'),
70 'url': api_response
['url'],
74 class AudiomackAlbumIE(InfoExtractor
):
75 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:album/|(?=.+/album/))(?P<id>[\w/-]+)'
76 IE_NAME
= 'audiomack:album'
78 # Standard album playlist
80 'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
85 'title': 'Tha Tour: Part 2 (Official Mixtape)'
88 # Album playlist ripped from fakeshoredrive with no metadata
90 'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project',
92 'title': 'PPP (Pistol P Project)',
97 'title': 'PPP (Pistol P Project) - 8. Real (prod by SYK SENSE )',
100 'uploader': 'Lil Herb a.k.a. G Herbo',
104 'title': 'PPP (Pistol P Project) - 10. 4 Minutes Of Hell Part 4 (prod by DY OF 808 MAFIA)',
107 'uploader': 'Lil Herb a.k.a. G Herbo',
113 def _real_extract(self
, url
):
114 # URLs end with [uploader name]/album/[uploader title]
115 # this title is whatever the user types in, and is rarely
116 # the proper song title. Real metadata is in the api response
117 album_url_tag
= self
._match
_id
(url
).replace('/album/', '/')
118 result
= {'_type': 'playlist', 'entries': []}
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
121 for track_no
in itertools
.count():
122 # Get song's metadata
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))
128 # Total failure, only occurs when url is totally wrong
129 # Won't happen in middle of valid playlist (next case)
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
))
132 # URL is good but song id doesn't exist - usually means end of playlist
133 elif not api_response
['url']:
136 # Pull out the album metadata and add to result (if it exists)
137 for resultkey
, apikey
in [('id', 'album_id'), ('title', 'album_title')]:
138 if apikey
in api_response
and resultkey
not in result
:
139 result
[resultkey
] = compat_str(api_response
[apikey
])
140 song_id
= url_basename(api_response
['url']).rpartition('.')[0]
141 result
['entries'].append({
142 'id': compat_str(api_response
.get('id', song_id
)),
143 'uploader': api_response
.get('artist'),
144 'title': api_response
.get('title', song_id
),
145 'url': api_response
['url'],