STREAM_TIMEOUT = 30
# Retry URL
STREAM_TIMEOUT = 30
# Retry URL
-STREAM_RETRY = STREAM_TIMEOUT/2
songMarkTime = 0
player = xbmc.Player()
songMarkTime = 0
player = xbmc.Player()
sys.exit(-1)
# Mark song as playing or played
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:
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
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
else:
playTimer.cancel()
songMarkTime = 0
if playTimer != None:
playTimer.cancel()
songMarkTime = 0
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
playTimer.start()
break
except: pass
seconds = seconds + 1
# If not playing after a few seconds try to refresh the URL
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)
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 + ')')
else:
xbmc.executebuiltin('XBMC.Notification(' + __language__(30008) + ', ' + __language__(30044) + ', 1000, ' + thumbDef + ')')
songid = item.getProperty('songid')
if url == '':
stream = groovesharkApi.getSubscriberStreamKey(songid)
songid = item.getProperty('songid')
if url == '':
stream = groovesharkApi.getSubscriberStreamKey(songid)
+ 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__:
item.setPath(url)
xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=item)
if __debuggui__:
if song[0] == id:
duration = song[1]
url = song[2]
if song[0] == id:
duration = song[1]
url = song[2]
+ streamKey = song[3]
+ streamServerID = song[4]
# Not in cache but exists
if duration < 0 and groovesharkApi.getDoesSongExist(songid):
stream = groovesharkApi.getSubscriberStreamKey(songid)
# Not in cache but exists
if duration < 0 and groovesharkApi.getDoesSongExist(songid):
stream = groovesharkApi.getSubscriberStreamKey(songid)
- 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)
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:
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()
self._setSongStreams(streams)
break;
f.close()
xbmc.log("An error occurred saving streams")
pass
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():
# Parse URL parameters
def get_params():
_sessionID = ''
_userID = 0
_lastSessionTime = 0
_sessionID = ''
_userID = 0
_lastSessionTime = 0
- _lastStreamKey = ''
- _lastStreamServerID = ''
_key = md5.new(os.path.basename("GroovesharkAPI.py")).hexdigest()
_apiDebug = False
_key = md5.new(os.path.basename("GroovesharkAPI.py")).hexdigest()
_apiDebug = False
params = { "songID": songID, "country": self._country }
response = self._callRemote("getSubscriberStreamKey", params)
try:
params = { "songID": songID, "country": self._country }
response = self._callRemote("getSubscriberStreamKey", params)
try:
- self._lastStreamKey = response["result"]["StreamKey"]
- self._lastStreamServerID = response["result"]["StreamServerID"]
res = response["result"]
return res
except:
res = response["result"]
return res
except:
return False
# After 30s play time
return False
# After 30s play time
- def markStreamKeyOver30Secs(self):
- params = { "streamKey" : self._lastStreamKey, "streamServerID" : self._lastStreamServerID }
+ def markStreamKeyOver30Secs(self, lastStreamKey, lastStreamServerID):
+ params = { "streamKey" : lastStreamKey, "streamServerID" : lastStreamServerID }
self._callRemote("markStreamKeyOver30Secs", params)
# Song complete
self._callRemote("markStreamKeyOver30Secs", params)
# Song complete
- def markSongComplete(self, songid):
- params = { "songID" : songid, "streamKey" : self._lastStreamKey, "streamServerID" : self._lastStreamServerID }
+ def markSongComplete(self, songid, lastStreamKey, lastStreamServerID):
+ params = { "songID" : songid, "streamKey" : lastStreamKey, "streamServerID" : lastStreamServerID }
self._callRemote("markSongComplete", params)
# Debug on off
self._callRemote("markSongComplete", params)
# Debug on off