server = song[4]
stream = [id, duration, url, key, server]
if __debugging__ :
- xbmc.log("Found " + str(id) + " in cache")
+ xbmc.log("Found " + str(id) + " in stream cache")
break;
f.close()
except:
key = stream['StreamKey']
server = stream['StreamServerID']
stream = [id, duration, url, key, server]
- self._addSongStream(stream, streams)
+ self._addSongStream(stream)
return stream
- def _addSongStream(self, stream, streams):
+ def _addSongStream(self, stream):
+ streams = self._getStreams()
+ streams.append(stream)
+ path = os.path.join(cacheDir, 'streams.dmp')
try:
- streams.append(stream)
- # Create the cache directory if it doesn't exist.
- if not os.path.exists(cacheDir):
- os.makedirs(cacheDir)
- path = os.path.join(cacheDir, 'streams.dmp')
f = open(path, 'wb')
pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
f.close()
+ if __debugging__ :
+ xbmc.log("Added " + str(stream[0]) + " to stream cache")
except:
- xbmc.log("An error occurred adding stream")
- pass
+ xbmc.log("An error occurred adding to stream")
def _setSongStream(self, stream):
id = int(stream[0])
stream[1] = self._setDuration(stream[1])
- streams = []
+ streams = self._getStreams()
path = os.path.join(cacheDir, 'streams.dmp')
- try:
- f = open(path, 'wb')
- streams = pickle.load(f)
- i = 0
- for song in streams:
- if song[0] == id:
- streams[i] = stream
- if __debugging__ :
- xbmc.log("Added " + str(id) + " to cache")
+ i = 0
+
+ for song in streams:
+ if song[0] == id:
+ streams[i] = stream
+ try:
+ f = open(path, 'wb')
pickle.dump(streams, f, protocol=pickle.HIGHEST_PROTOCOL)
+ f.close()
+ if __debugging__ :
+ xbmc.log("Updated " + str(id) + " in stream cache")
break;
- i = i + 1
+ except:
+ xbmc.log("An error occurred setting stream")
+ i = i + 1
+
+ def _getStreams(self):
+ path = os.path.join(cacheDir, 'streams.dmp')
+ try:
+ f = open(path, 'rb')
+ streams = pickle.load(f)
f.close()
except:
- xbmc.log("An error occurred setting stream")
-
+ streams = []
+ pass
+ return streams
+
# Parse URL parameters
def get_params():