Correzioni videoteca

This commit is contained in:
Alhaziel01
2021-05-21 17:35:03 +02:00
parent 6b8305f7ae
commit 529e24e4c1
7 changed files with 206 additions and 370 deletions
+3 -169
View File
@@ -115,175 +115,9 @@ def update(path, p_dialog, i, t, serie, overwrite):
return insertados_total > 0
def check_for_update(overwrite=True):
logger.debug("Update Series...")
p_dialog = None
serie_actualizada = False
update_when_finished = False
hoy = datetime.date.today()
estado_verify_playcount_series = False
try:
if config.get_setting("update", "videolibrary") != 0 or overwrite:
config.set_setting("updatelibrary_last_check", hoy.strftime('%Y-%m-%d'), "videolibrary")
heading = config.get_localized_string(60389)
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), heading)
p_dialog.update(0, '')
show_list = []
# show_ep_num = []
for path, folders, files in filetools.walk(videolibrarytools.TVSHOWS_PATH):
if 'tvshow.nfo' in files:
show_list.extend([filetools.join(path, f) for f in files if f == "tvshow.nfo"])
# show_ep_num.append(len([f for f in files if f.endswith('.nfo') and f != 'tvshow.nfo']))
if show_list:
t = float(100) / len(show_list)
for i, tvshow_file in enumerate(show_list):
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file)
# ep_count = show_ep_num[i] + (len(serie.local_episodes_list) if serie.local_episodes_path else 0)
# if serie.infoLabels['status'].lower() == 'ended' and \
# ep_count >= serie.infoLabels['number_of_episodes']:
# serie.active = 0
# filetools.write(tvshow_file, head_nfo + serie.tojson())
path = filetools.dirname(tvshow_file)
logger.debug("serie=" + serie.contentSerieName)
# Check the status of the series.library_playcounts of the Series in case it is incomplete
try:
estado = False
# If we have not done the verification or do not have a playcount, we enter
estado = config.get_setting("verify_playcount", "videolibrary")
if not estado or estado == False or not serie.library_playcounts: # If it hasn't happened before, we do it now
serie, estado = videolibrary.verify_playcount_series(serie, path) # Also happens if a PlayCount is missing completely
except:
logger.error(traceback.format_exc())
else:
if estado: # If the update was successful ...
estado_verify_playcount_series = True # ... is checked to change the Video Library option
try:
interval = int(serie.active) # Could be the bool type
except:
interval = 1
if not serie.active:
# if the series is not active discard
if not overwrite:
# Synchronize the episodes seen from the Kodi video library with that of Alpha, even if the series is deactivated
try:
if config.is_xbmc(): # If it's Kodi, we do it
from platformcode import xbmc_videolibrary
xbmc_videolibrary.mark_content_as_watched_on_kod(filetools.join(path,'tvshow.nfo'))
except:
logger.error(traceback.format_exc())
continue
p_dialog.update(int(math.ceil((i + 1) * t)), heading, serie.contentSerieName)
# Obtain the update date and the next scheduled for this series
update_next = serie.update_next
if update_next:
y, m, d = update_next.split('-')
update_next = datetime.date(int(y), int(m), int(d))
else:
update_next = hoy
update_last = serie.update_last
if update_last:
y, m, d = update_last.split('-')
update_last = datetime.date(int(y), int(m), int(d))
else:
update_last = hoy
# if the series is active ...
if overwrite or config.get_setting("updatetvshows_interval", "videolibrary") == 0:
# ... force update regardless of interval
serie_actualizada = update(path, p_dialog, i, t, serie, overwrite)
if not serie_actualizada:
update_next = hoy + datetime.timedelta(days=interval)
elif interval == 1 and update_next <= hoy:
# ...daily update
serie_actualizada = update(path, p_dialog, i, t, serie, overwrite)
if not serie_actualizada and update_last <= hoy - datetime.timedelta(days=7):
# if it hasn't been updated for a week, change the interval to weekly
interval = 7
update_next = hoy + datetime.timedelta(days=interval)
elif interval == 7 and update_next <= hoy:
# ... weekly update
serie_actualizada = update(path, p_dialog, i, t, serie, overwrite)
if not serie_actualizada:
if update_last <= hoy - datetime.timedelta(days=14):
# if it has not been updated for 2 weeks, change the interval to monthly
interval = 30
update_next += datetime.timedelta(days=interval)
elif interval == 30 and update_next <= hoy:
# ... monthly update
serie_actualizada = update(path, p_dialog, i, t, serie, overwrite)
if not serie_actualizada:
update_next += datetime.timedelta(days=interval)
if serie_actualizada:
update_last = hoy
update_next = hoy + datetime.timedelta(days=interval)
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file) # Reread the .nfo, which has been modified
if interval != int(serie.active) or update_next.strftime('%Y-%m-%d') != serie.update_next or update_last.strftime('%Y-%m-%d') != serie.update_last:
serie.update_last = update_last.strftime('%Y-%m-%d')
if update_next > hoy:
serie.update_next = update_next.strftime('%Y-%m-%d')
serie.active = interval
serie.channel = "videolibrary"
serie.action = "get_seasons"
filetools.write(tvshow_file, head_nfo + serie.tojson())
if serie_actualizada:
if config.get_setting("search_new_content", "videolibrary") == 0:
# We update the Kodi video library: Find content in the series folder
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
from platformcode import xbmc_videolibrary
xbmc_videolibrary.update(folder=filetools.basename(path))
else:
update_when_finished = True
if estado_verify_playcount_series: # If any playcount has been changed, ...
estado = config.set_setting("verify_playcount", True, "videolibrary") # ... we update the Videolibrary option
if config.get_setting("search_new_content", "videolibrary") == 1 and update_when_finished:
# We update the Kodi video library: Find content in all series
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
from platformcode import xbmc_videolibrary
xbmc_videolibrary.update()
p_dialog.close()
else:
logger.debug("Not update the video library, it is disabled")
except Exception as ex:
logger.error("An error occurred while updating the series")
template = "An exception of type %s occured. Arguments:\n%r"
message = template % (type(ex).__name__, ex.args)
logger.error(message)
if p_dialog:
p_dialog.close()
from core.item import Item
item_dummy = Item()
videolibrary.list_movies(item_dummy, silent=True)
if config.get_setting('trakt_sync'):
from core import trakt_tools
trakt_tools.update_all()
def check_for_update():
if config.get_setting("update", "videolibrary"):
videolibrary.update_videolibrary()
def updaterCheck():