def cleanDB(): if config.use_database: logger.info(u"Cleaning database...") db.checkDB() myDB = db.DBConnection() if config.clean_uncomplete_only: reslut = myDB.select("SELECT * from scrobble where process < {0}".format(config.min_progress)) else: reslut = myDB.select("SELECT * from scrobble") if reslut: counter=0 for item in reslut: filename = os.path.split(item["thepath"])[1] thedate = datetime.datetime.fromtimestamp(float(item["lastviewed"])) timedelta = thedate + datetime.timedelta(weeks=8) if timedelta < datetime.datetime.now(): counter=counter+1 logger.debug(u"Deleting {0} from database because lastviewed more than 8 weeks ago".format(filename)) myDB.action("DELETE from scrobble where id = {0}".format(item["id"])) logger.info(u"removed {0} old entrys from databse".format(counter)) else: logger.info(u"no need to clean database for now")
def FileInDB(theid): db.checkDB() myDB = db.DBConnection() response = myDB.select("SELECT scrobbled from scrobble WHERE id = {0}".format(theid)) try: return response[0]["scrobbled"] except: return None
def mediaelementToDatabase(mediaelement): #create db if not exist... db.checkDB() myDB = db.DBConnection() myDB.upsert("scrobble",{'id': mediaelement["id"], 'lastviewed': mediaelement["lastviewedstamp"], 'process': mediaelement["process"], 'name':mediaelement["name"], 'thepath': mediaelement["thepath"], 'viewed':mediaelement["viewed"], 'duration':mediaelement["duration"], 'directory':mediaelement["directory"], 'type':mediaelement["type"]},{'id': mediaelement["id"]}) if mediaelement["type"] == "series": myDB.upsert("scrobble",{'season': mediaelement["season"], 'episode': mediaelement["episode"], 'tvdb_id': mediaelement["tvdb_id"]},{'id': mediaelement["id"]}) if mediaelement["type"] == "movie": myDB.upsert("scrobble",{'imdb_id': mediaelement["imdb_id"], 'year':mediaelement["year"]},{'id': mediaelement["id"]})
def mediaelementFromDatabase(theid): db.checkDB() myDB = db.DBConnection() response = myDB.select("SELECT * from scrobble WHERE id = {0}".format(theid)) return response[0]
def markScrobbled(theid): db.checkDB() myDB = db.DBConnection() myDB.upsert("scrobble",{'scrobbled': 1},{'id': theid})