]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/audiomack.py
   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/(?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', 
  46     def _real_extract(self
, url
): 
  47         # URLs end with [uploader name]/[uploader title] 
  48         # this title is whatever the user types in, and is rarely 
  49         # the proper song title.  Real metadata is in the api response 
  50         album_url_tag 
= self
._match
_id
(url
) 
  52         # Request the extended version of the api for extra fields like artist and title 
  53         api_response 
= self
._download
_json
( 
  54             'http://www.audiomack.com/api/music/url/song/%s?extended=1&_=%d' % ( 
  55                 album_url_tag
, time
.time()), 
  58         # API is inconsistent with errors 
  59         if 'url' not in api_response 
or not api_response
['url'] or 'error' in api_response
: 
  60             raise ExtractorError('Invalid url %s' % url
) 
  62         # Audiomack wraps a lot of soundcloud tracks in their branded wrapper 
  63         # if so, pass the work off to the soundcloud extractor 
  64         if SoundcloudIE
.suitable(api_response
['url']): 
  65             return self
.url_result(api_response
['url'], SoundcloudIE
.ie_key()) 
  68             'id': compat_str(api_response
.get('id', album_url_tag
)), 
  69             'uploader': api_response
.get('artist'), 
  70             'title': api_response
.get('title'), 
  71             'url': api_response
['url'], 
  75 class AudiomackAlbumIE(InfoExtractor
): 
  76     _VALID_URL 
= r
'https?://(?:www\.)?audiomack\.com/album/(?P<id>[\w/-]+)' 
  77     IE_NAME 
= 'audiomack:album' 
  79         # Standard album playlist 
  81             'url': 'http://www.audiomack.com/album/flytunezcom/tha-tour-part-2-mixtape', 
  86                 'title': 'Tha Tour: Part 2 (Official Mixtape)' 
  89         # Album playlist ripped from fakeshoredrive with no metadata 
  91             'url': 'http://www.audiomack.com/album/fakeshoredrive/ppp-pistol-p-project', 
  93                 'title': 'PPP (Pistol P Project)', 
  98                     'title': 'PPP (Pistol P Project) - 9. Heaven or Hell (CHIMACA) ft Zuse (prod by DJ FU)', 
 101                     'uploader': 'Lil Herb a.k.a. G Herbo', 
 111     def _real_extract(self
, url
): 
 112         # URLs end with [uploader name]/[uploader title] 
 113         # this title is whatever the user types in, and is rarely 
 114         # the proper song title.  Real metadata is in the api response 
 115         album_url_tag 
= self
._match
_id
(url
) 
 116         result 
= {'_type': 'playlist', 'entries': []} 
 117         # There is no one endpoint for album metadata - instead it is included/repeated in each song's metadata 
 118         # Therefore we don't know how many songs the album has and must infi-loop until failure 
 119         for track_no 
in itertools
.count(): 
 120             # Get song's metadata 
 121             api_response 
= self
._download
_json
( 
 122                 'http://www.audiomack.com/api/music/url/album/%s/%d?extended=1&_=%d' 
 123                 % (album_url_tag
, track_no
, time
.time()), album_url_tag
, 
 124                 note
='Querying song information (%d)' % (track_no 
+ 1)) 
 126             # Total failure, only occurs when url is totally wrong 
 127             # Won't happen in middle of valid playlist (next case) 
 128             if 'url' not in api_response 
or 'error' in api_response
: 
 129                 raise ExtractorError('Invalid url for track %d of album url %s' % (track_no
, url
)) 
 130             # URL is good but song id doesn't exist - usually means end of playlist 
 131             elif not api_response
['url']: 
 134                 # Pull out the album metadata and add to result (if it exists) 
 135                 for resultkey
, apikey 
in [('id', 'album_id'), ('title', 'album_title')]: 
 136                     if apikey 
in api_response 
and resultkey 
not in result
: 
 137                         result
[resultkey
] = api_response
[apikey
] 
 138                 song_id 
= url_basename(api_response
['url']).rpartition('.')[0] 
 139                 result
['entries'].append({ 
 140                     'id': compat_str(api_response
.get('id', song_id
)), 
 141                     'uploader': api_response
.get('artist'), 
 142                     'title': api_response
.get('title', song_id
), 
 143                     'url': api_response
['url'],