def run(): threads = [ threading.Thread(target=movies_thread), threading.Thread(target=series_thread), ] for t in threads: t.daemon = True t.start() # XBMC loop while not xbmc.abortRequested: xbmc.sleep(1000) log.info("libra: exiting libra services")
def thread(self): try: import xbmc from resources.lib.indexers import ktuvit update_rate = common.get_setting("movie_update_rate") update_rate_hours = 24 # every day if update_rate == 1: update_rate_hours *= 7 # once a week elif update_rate == 2: update_rate_hours *= 30 # once a month # Check last run for each service last_run = self.last_run() try: common.window.setProperty(self.property, last_run) except: return service_property = common.window.getProperty(self.property) import datetime t1 = datetime.timedelta(hours=update_rate_hours) t2 = datetime.datetime.strptime(service_property, '%Y-%m-%d %H:%M:%S.%f') t3 = datetime.datetime.now() check = abs(t3 - t2) > t1 if check is not False: log.info("libra: starting movies service") service_property = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') common.window.setProperty(self.property, service_property) try: dbcon = database.connect(common.libraDbFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS service (""setting TEXT, ""value TEXT, ""UNIQUE(setting)"");") dbcur.execute("DELETE FROM service WHERE setting = 'last_run__movies'") dbcur.execute("INSERT INTO service Values (?, ?)", ('last_run__movies', service_property)) dbcon.commit() dbcon.close() except: try: dbcon.close() except: pass ktuvit = ktuvit.Ktuvit() page = 1 added = 0 while page <= ktuvit.ktuvit_total_pages or added < 32: # need to be replace with setting if xbmc.abortRequested: return sys.exit() movies = ktuvit.get_movies(page=page) if movies: for movie in movies: if not self.is_valid_year(movie['year']): continue if not self.is_valid_genre(movie['genres']): continue if not self.is_valid_rating(movie['rating']): continue success = Movies().add(re.sub("#039;", "", movie['name']), movie['title'], movie['year'], movie['imdbid']) if success is True: added += 1 if added > 32 or page > 32: break; page += 1 common.execute('UpdateLibrary(video)') except: return