def _getSongStream(self, songid):
idSong = int(songid)
stream = None
- streams = []
+ streams = {}
path = os.path.join(cacheDir, 'streams.dmp')
try:
f = open(path, 'rb')
streams = pickle.load(f)
- for song in streams:
- if song[0] == idSong:
- duration = song[1]
- url = song[2]
- key = song[3]
- server = song[4]
- stream = [idSong, duration, url, key, server]
- if __debugging__ :
- xbmc.log("Found " + str(idSong) + " in stream cache")
- break;
+ song = streams[songid]
+
+ duration = song[1]
+ url = song[2]
+ key = song[3]
+ server = song[4]
+ stream = [idSong, duration, url, key, server]
+
+ if __debugging__ :
+ xbmc.log("Found " + str(idSong) + " in stream cache")
+
f.close()
except:
pass
def _addSongStream(self, stream):
streams = self._getStreams()
- streams.append(stream)
+ streams[int(stream[0])] = stream
path = os.path.join(cacheDir, 'streams.dmp')
try:
f = open(path, 'wb')
stream[1] = self._setDuration(stream[1])
streams = self._getStreams()
path = os.path.join(cacheDir, 'streams.dmp')
- i = 0
- for song in streams:
- if song[0] == idStream:
- streams[i] = stream
- try:
- f = open(path, 'wb')
- pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
- f.close()
- if __debugging__ :
- xbmc.log("Updated " + str(idStream) + " in stream cache")
- break;
- except:
- xbmc.log("An error occurred setting stream")
- i = i + 1
+ try:
+ streams[idStream] = stream
+ f = open(path, 'wb')
+ pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
+ f.close()
+ if __debugging__ :
+ xbmc.log("Updated " + str(idStream) + " in stream cache")
+
+ except:
+ xbmc.log("An error occurred setting stream")
def _getStreams(self):
path = os.path.join(cacheDir, 'streams.dmp')
streams = pickle.load(f)
f.close()
except:
- streams = []
+ streams = {}
pass
return streams