grooveshark: force mp3 extension, many code style fixes
This commit is contained in:
parent
bfe3ac6bcd
commit
8d501ed1e4
1 changed files with 21 additions and 15 deletions
|
|
@ -31,9 +31,16 @@ import datetime
|
||||||
__all__ = ['GroovesharkBrowser']
|
__all__ = ['GroovesharkBrowser']
|
||||||
|
|
||||||
|
|
||||||
|
class GroovesharkVideo(BaseVideo):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
BaseVideo.__init__(self, *args, **kwargs)
|
||||||
|
self.ext = u'mp3'
|
||||||
|
|
||||||
|
|
||||||
class APIError(Exception):
|
class APIError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class GroovesharkBrowser(BaseBrowser):
|
class GroovesharkBrowser(BaseBrowser):
|
||||||
PROTOCOL = 'http'
|
PROTOCOL = 'http'
|
||||||
DOMAIN = 'html5.grooveshark.com'
|
DOMAIN = 'html5.grooveshark.com'
|
||||||
|
|
@ -69,7 +76,7 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
|
|
||||||
parameters = {}
|
parameters = {}
|
||||||
parameters['query'] = pattern.encode(self.ENCODING)
|
parameters['query'] = pattern.encode(self.ENCODING)
|
||||||
parameters['type'] = ['Songs']#['Songs','Playlists','Albums']
|
parameters['type'] = ['Songs'] # ['Songs','Playlists','Albums']
|
||||||
parameters['guts'] = 0
|
parameters['guts'] = 0
|
||||||
parameters['ppOverr'] = ''
|
parameters['ppOverr'] = ''
|
||||||
|
|
||||||
|
|
@ -85,10 +92,10 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
self.VIDEOS_FROM_SONG_RESULTS = []
|
self.VIDEOS_FROM_SONG_RESULTS = []
|
||||||
|
|
||||||
for song in songs:
|
for song in songs:
|
||||||
video = BaseVideo(song['SongID'])
|
video = GroovesharkVideo(song['SongID'])
|
||||||
video.title = u'Song - %s' % song['SongName'].encode('ascii', 'replace')
|
video.title = u'Song - %s' % song['SongName'].encode('ascii', 'replace')
|
||||||
video.author = u'%s' % song['ArtistName'].encode('ascii', 'replace')
|
video.author = u'%s' % song['ArtistName'].encode('ascii', 'replace')
|
||||||
video.description = u'%s - %s - %s'%(video.author, song['AlbumName'].encode('ascii', 'replace'), song['Year'].encode('ascii', 'replace'))
|
video.description = u'%s - %s - %s' % (video.author, song['AlbumName'].encode('ascii', 'replace'), song['Year'].encode('ascii', 'replace'))
|
||||||
video.thumbnail = Thumbnail(u'http://images.gs-cdn.net/static/albums/40_' + song['CoverArtFilename'])
|
video.thumbnail = Thumbnail(u'http://images.gs-cdn.net/static/albums/40_' + song['CoverArtFilename'])
|
||||||
video.duration = datetime.timedelta(seconds=int(float(song['EstimateDuration'])))
|
video.duration = datetime.timedelta(seconds=int(float(song['EstimateDuration'])))
|
||||||
video.rating = float(song['AvgRating'])
|
video.rating = float(song['AvgRating'])
|
||||||
|
|
@ -103,8 +110,8 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
def create_video_from_playlist_result(self, playlists):
|
def create_video_from_playlist_result(self, playlists):
|
||||||
videos = []
|
videos = []
|
||||||
for playlist in playlists:
|
for playlist in playlists:
|
||||||
video = BaseVideo(playlist['PlaylistID'])
|
video = GroovesharkVideo(playlist['PlaylistID'])
|
||||||
video.title = u'Playlist - %s' %(playlist['Name'])
|
video.title = u'Playlist - %s' % (playlist['Name'])
|
||||||
video.description = playlist['Artists']
|
video.description = playlist['Artists']
|
||||||
videos.append(video)
|
videos.append(video)
|
||||||
return videos
|
return videos
|
||||||
|
|
@ -112,13 +119,12 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
def create_video_from_albums_result(self, albums):
|
def create_video_from_albums_result(self, albums):
|
||||||
videos = []
|
videos = []
|
||||||
for album in albums:
|
for album in albums:
|
||||||
video = BaseVideo(album['AlbumID'])
|
video = GroovesharkVideo(album['AlbumID'])
|
||||||
video.title = u'Album - %s' %(album['Name'])
|
video.title = u'Album - %s' % (album['Name'])
|
||||||
video.description = album['Year']
|
video.description = album['Year']
|
||||||
videos.append(video)
|
videos.append(video)
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
|
|
||||||
def get_communication_token(self):
|
def get_communication_token(self):
|
||||||
parameters = {'secretKey': hashlib.md5(self.HEADER["session"]).hexdigest()}
|
parameters = {'secretKey': hashlib.md5(self.HEADER["session"]).hexdigest()}
|
||||||
result = self.API_post('getCommunicationToken', parameters)
|
result = self.API_post('getCommunicationToken', parameters)
|
||||||
|
|
@ -151,7 +157,7 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
|
|
||||||
self.mark_song_downloaded_ex(response['result'])
|
self.mark_song_downloaded_ex(response['result'])
|
||||||
|
|
||||||
return u'http://%s/stream.php?streamKey=%s' %(response['result']['ip'], response['result']['streamKey'])
|
return u'http://%s/stream.php?streamKey=%s' % (response['result']['ip'], response['result']['streamKey'])
|
||||||
|
|
||||||
# in order to simulate a real browser
|
# in order to simulate a real browser
|
||||||
def mark_song_downloaded_ex(self, response):
|
def mark_song_downloaded_ex(self, response):
|
||||||
|
|
@ -192,7 +198,7 @@ class GroovesharkBrowser(BaseBrowser):
|
||||||
return simplejson.dumps(data)
|
return simplejson.dumps(data)
|
||||||
|
|
||||||
def create_request(self, method):
|
def create_request(self, method):
|
||||||
req = self.request_class('%s?%s' %(self.API_URL, method))
|
req = self.request_class('%s?%s' % (self.API_URL, method))
|
||||||
req.add_header('Content-Type', 'application/json')
|
req.add_header('Content-Type', 'application/json')
|
||||||
return req
|
return req
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue