- def _get_favorites(self):
- favorites = []
- # if the cache does not exist or is older than x hours then reload
- if (os.path.isfile(favoritesCache) == False) or (time.time() - os.path.getmtime(favoritesCache) > 3*60*60):
- xbmc.log("Refresh favorites cache")
- userid = self._get_login()
- if (userid != 0):
- favorites = groovesharkApi.userGetFavoriteSongs(userid)
- f = open(favoritesCache, 'wb')
- pickle.dump(favorites, f, protocol=pickle.HIGHEST_PROTOCOL)
- f.close()
- xbmc.log("Refreshed favorites cache")
- # if not old then read from cache
- elif os.path.isfile(favoritesCache):
- xbmc.log("Existing favorites cache")
- f = open(favoritesCache, 'rb')
- favorites = pickle.load(f)
- f.close()
-
- return favorites
-