X-Git-Url: https://git.hcoop.net/clinton/xbmc-groove.git/blobdiff_plain/cd937deaa3f7846f8a2b9249cb2cebc25c633ce2..cfad720224c023b751d50c0a5592da5dfaf29a68:/default.py diff --git a/default.py b/default.py index 8f68fa5..5dd94c2 100644 --- a/default.py +++ b/default.py @@ -68,7 +68,7 @@ STREAM_MARKING_TIME = 30 STREAM_TIMEOUT = 30 # Retry URL -STREAM_RETRY = STREAM_TIMEOUT/2 +STREAM_RETRY = 15 songMarkTime = 0 player = xbmc.Player() @@ -107,19 +107,19 @@ except: sys.exit(-1) # Mark song as playing or played -def markSong(songid, duration): +def markSong(songid, duration, streamKey, streamServerID): global songMarkTime global playTimer global player if player.isPlayingAudio(): tNow = player.getTime() if tNow >= STREAM_MARKING_TIME and songMarkTime == 0: - groovesharkApi.markStreamKeyOver30Secs() + groovesharkApi.markStreamKeyOver30Secs(streamKey, streamServerID) songMarkTime = tNow elif duration > tNow and duration - tNow < 2 and songMarkTime >= STREAM_MARKING_TIME: playTimer.cancel() songMarkTime = 0 - groovesharkApi.markSongComplete(songid) + groovesharkApi.markSongComplete(songid, streamKey, streamServerID) else: playTimer.cancel() songMarkTime = 0 @@ -489,8 +489,9 @@ class Grooveshark: if playTimer != None: playTimer.cancel() songMarkTime = 0 - duration = int(item.getProperty('duration')) - playTimer = PlayTimer(1, markSong, duration, [songid, duration]) + stream = self._getSongStream(songid) + duration = stream['duration'] + playTimer = PlayTimer(1, markSong, duration, [songid, duration, stream['streamKey'], stream['streamServerID']]) playTimer.start() break except: pass @@ -498,10 +499,11 @@ class Grooveshark: seconds = seconds + 1 # If not playing after a few seconds try to refresh the URL - if (seconds == STREAM_RETRY): + if (player.isPlayingAudio() == False and seconds == STREAM_RETRY): + if __debug__: + xbmc.log("Refreshing URL") item.setProperty('url', '') self._setItem(item) - self._setSongStream(songid, item.getProperty('duration'), item.getProperty('url')) else: xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ', ' + __language__(30044) + ', 1000, ' + thumbDef + ')') @@ -723,7 +725,9 @@ class Grooveshark: songid = item.getProperty('songid') if url == '': stream = groovesharkApi.getSubscriberStreamKey(songid) - url = stream['url'] + if stream != False: + url = stream['url'] + self._setSongStream(songid, stream) item.setPath(url) xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item) if __debuggui__: @@ -925,6 +929,8 @@ class Grooveshark: if song[0] == id: duration = song[1] url = song[2] + streamKey = song[3] + streamServerID = song[4] break; f.close() except: @@ -933,26 +939,29 @@ class Grooveshark: # Not in cache but exists if duration < 0 and groovesharkApi.getDoesSongExist(songid): stream = groovesharkApi.getSubscriberStreamKey(songid) - url = stream['url'] usecs = stream['uSecs'] - if usecs < 60000000: - usecs = usecs * 10 # Some durations are 10x to small - duration = usecs / 1000000 - song = [id, duration, url] + url = stream['url'] + streamKey = stream['StreamKey'] + streamServerID = stream['StreamServerID'] + + duration = self._setDuration(usecs) + song = [id, duration, url, streamKey, streamServerID] streams.append(song) self._setSongStreams(streams) - return {'duration':duration, 'url':url} + return {'duration':duration, 'url':url, 'streamKey':streamKey, 'streamServerID':streamServerID} - def _setSongStream(self, songid, duration, url): + def _setSongStream(self, songid, stream): path = os.path.join(cacheDir, 'streams.dmp') try: f = open(path, 'rb') streams = pickle.load(f) for song in streams: if song[0] == songid: - song[1] = duration - song[2] = url + song[1] = self._setDuration(stream['uSecs']) + song[2] = stream['url'] + song[3] = stream['streamKey'] + song[4] = stream['streamServerID'] self._setSongStreams(streams) break; f.close() @@ -973,6 +982,10 @@ class Grooveshark: xbmc.log("An error occurred saving streams") pass + def _setDuration(self, usecs): + if usecs < 60000000: + usecs = usecs * 10 # Some durations are 10x to small + return usecs / 1000000 # Parse URL parameters def get_params():