+ def radioSetAlreadyListenedSong(self, name = None, songId = ''):
+ radio = self.getSavedRadio(name = name)
+ if radio != None and songId != '':
+ radio['songIDsAlreadySeen'].append(songId)
+ while len(radio['songIDsAlreadySeen']) > 20:
+ radio['songIDsAlreadySeen'].pop(0) # Trim
+ return self.saveRadio(radio = radio)
+ else:
+ return 0
+
+ def getSavedRadio(self, name = None):
+ if name == None:
+ path = os.path.join(self.confDir, 'radio', 'default.txt')
+ else:
+ path = os.path.join(self.confDir, 'radio', 'saved', name)
+ try:
+ f = open(path, 'rb')
+ radio = pickle.load(f)
+ f.close()
+ except:
+ radio = None
+ return radio
+
+ def saveRadio(self, name = None, radio = {}): #blaher
+ try:
+ dir = os.path.join(self.confDir, 'radio')
+ # Create the 'data' directory if it doesn't exist.
+ if not os.path.exists(dir):
+ os.mkdir(dir)
+ os.mkdir(os.path.join(dir, 'saved'))
+ if name == None:
+ path = os.path.join(dir, 'default.txt')
+ else:
+ path = os.path.join(dir, 'saved', name)
+ f = open(path, 'wb')
+ pickle.dump(radio, f, protocol=pickle.HIGHEST_PROTOCOL)
+ f.close()
+ return 1
+ except IOError, e:
+ print 'There was an error while saving the radio pickle (%s)' % e
+ return 0
+ except:
+ print "An unknown error occured during save radio: " + str(sys.exc_info()[0])
+ return 0
+