2 from __future__
import unicode_literals
7 from .common
import InfoExtractor
8 from .soundcloud
import SoundcloudIE
9 from ..compat
import compat_str
16 class AudiomackIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:song/|(?=.+/song/))(?P<id>[\w/-]+)'
22 'url': 'http://www.audiomack.com/song/roosh-williams/extraordinary',
27 'uploader': 'Roosh Williams',
28 'title': 'Extraordinary'
31 # audiomack wrapper around soundcloud song
33 'add_ie': ['Soundcloud'],
34 'url': 'http://www.audiomack.com/song/hip-hop-daily/black-mamba-freestyle',
38 'description': 'mamba day freestyle for the legend Kobe Bryant ',
39 'title': 'Black Mamba Freestyle [Prod. By Danny Wolf]',
40 'uploader': 'ILOVEMAKONNEN',
41 'upload_date': '20160414',
43 'skip': 'Song has been removed from the site',
47 def _real_extract(self
, url
):
48 # URLs end with [uploader name]/song/[uploader title]
49 # this title is whatever the user types in, and is rarely
50 # the proper song title. Real metadata is in the api response
51 album_url_tag
= self
._match
_id
(url
).replace('/song/', '/')
53 # Request the extended version of the api for extra fields like artist and title
54 api_response
= self
._download
_json
(
55 'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % (
56 album_url_tag
, time
.time()),
59 # API is inconsistent with errors
60 if 'url' not in api_response
or not api_response
['url'] or 'error' in api_response
:
61 raise ExtractorError('Invalid url %s' % url
)
63 # Audiomack wraps a lot of soundcloud tracks in their branded wrapper
64 # if so, pass the work off to the soundcloud extractor
65 if SoundcloudIE
.suitable(api_response
['url']):
66 return self
.url_result(api_response
['url'], SoundcloudIE
.ie_key())
69 'id': compat_str(api_response
.get('id', album_url_tag
)),
70 'uploader': api_response
.get('artist'),
71 'title': api_response
.get('title'),
72 'url': api_response
['url'],
76 class AudiomackAlbumIE(InfoExtractor
):
77 _VALID_URL
= r
'https?://(?:www\.)?audiomack\.com/(?:album/|(?=.+/album/))(?P<id>[\w/-]+)'
78 IE_NAME
= 'audiomack:album'
80 # Standard album playlist
82 'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape',
87 'title': 'Tha Tour: Part 2 (Official Mixtape)'
90 # Album playlist ripped from fakeshoredrive with no metadata
92 'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project',
94 'title': 'PPP (Pistol P Project)',
99 'title': 'PPP (Pistol P Project) - 8. Real (prod by SYK SENSE )',
102 'uploader': 'Lil Herb a.k.a. G Herbo',
106 'title': 'PPP (Pistol P Project) - 10. 4 Minutes Of Hell Part 4 (prod by DY OF 808 MAFIA)',
109 'uploader': 'Lil Herb a.k.a. G Herbo',
115 def _real_extract(self
, url
):
116 # URLs end with [uploader name]/album/[uploader title]
117 # this title is whatever the user types in, and is rarely
118 # the proper song title. Real metadata is in the api response
119 album_url_tag
= self
._match
_id
(url
).replace('/album/', '/')
120 result
= {'_type': 'playlist', 'entries': []}
121 # There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata
122 # Therefore we don't know how many songs the album has and must infi-loop until failure
123 for track_no
in itertools
.count():
124 # Get song's metadata
125 api_response
= self
._download
_json
(
126 'http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d'
127 % (album_url_tag
, track_no
, time
.time()), album_url_tag
,
128 note
='Querying song information (%d)' % (track_no
+ 1))
130 # Total failure, only occurs when url is totally wrong
131 # Won't happen in middle of valid playlist (next case)
132 if 'url' not in api_response
or 'error' in api_response
:
133 raise ExtractorError('Invalid url for track %d of album url %s' % (track_no
, url
))
134 # URL is good but song id doesn't exist - usually means end of playlist
135 elif not api_response
['url']:
138 # Pull out the album metadata and add to result (if it exists)
139 for resultkey
, apikey
in [('id', 'album_id'), ('title', 'album_title')]:
140 if apikey
in api_response
and resultkey
not in result
:
141 result
[resultkey
] = compat_str(api_response
[apikey
])
142 song_id
= url_basename(api_response
['url']).rpartition('.')[0]
143 result
['entries'].append({
144 'id': compat_str(api_response
.get('id', song_id
)),
145 'uploader': api_response
.get('artist'),
146 'title': api_response
.get('title', song_id
),
147 'url': api_response
['url'],