Sincronizado de marcado de vídeos visto desde Kodi a Alfa
This commit is contained in:
@@ -31,14 +31,23 @@ def channel_config(item):
|
||||
caption=config.get_localized_string(60598))
|
||||
|
||||
|
||||
def list_movies(item):
|
||||
def list_movies(item, silent=False):
|
||||
logger.info()
|
||||
itemlist = []
|
||||
from platformcode import xbmc_videolibrary
|
||||
from lib import generictools
|
||||
|
||||
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.MOVIES_PATH):
|
||||
for f in ficheros:
|
||||
if f.endswith(".nfo"):
|
||||
nfo_path = filetools.join(raiz, f)
|
||||
|
||||
#Sincronizamos las películas vistas desde la videoteca de Kodi con la de Alfa
|
||||
try:
|
||||
xbmc_videolibrary.mark_content_as_watched_on_alfa(nfo_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
head_nfo, new_item = videolibrarytools.read_nfo(nfo_path)
|
||||
|
||||
new_item.nfo = nfo_path
|
||||
@@ -50,6 +59,12 @@ def list_movies(item):
|
||||
# Si se ha eliminado el strm desde la bilbioteca de kodi, no mostrarlo
|
||||
continue
|
||||
|
||||
###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial
|
||||
try:
|
||||
new_item, new_item, overwrite = generictools.redirect_clone_newpct1(new_item, head_nfo, new_item, raiz)
|
||||
except:
|
||||
pass
|
||||
|
||||
# Menu contextual: Marcar como visto/no visto
|
||||
visto = new_item.library_playcounts.get(os.path.splitext(f)[0], 0)
|
||||
new_item.infoLabels["playcount"] = visto
|
||||
@@ -85,12 +100,16 @@ def list_movies(item):
|
||||
# logger.debug("new_item: " + new_item.tostring('\n'))
|
||||
itemlist.append(new_item)
|
||||
|
||||
return sorted(itemlist, key=lambda it: it.title.lower())
|
||||
if silent == False:
|
||||
return sorted(itemlist, key=lambda it: it.title.lower())
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
def list_tvshows(item):
|
||||
logger.info()
|
||||
itemlist = []
|
||||
from platformcode import xbmc_videolibrary
|
||||
|
||||
# Obtenemos todos los tvshow.nfo de la videoteca de SERIES recursivamente
|
||||
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.TVSHOWS_PATH):
|
||||
@@ -98,6 +117,13 @@ def list_tvshows(item):
|
||||
if f == "tvshow.nfo":
|
||||
tvshow_path = filetools.join(raiz, f)
|
||||
# logger.debug(tvshow_path)
|
||||
|
||||
#Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa
|
||||
try:
|
||||
xbmc_videolibrary.mark_content_as_watched_on_alfa(tvshow_path)
|
||||
except:
|
||||
pass
|
||||
|
||||
head_nfo, item_tvshow = videolibrarytools.read_nfo(tvshow_path)
|
||||
item_tvshow.title = item_tvshow.contentTitle
|
||||
item_tvshow.path = raiz
|
||||
@@ -552,7 +578,7 @@ def mark_content_as_watched2(item):
|
||||
# Guardamos los cambios en item.nfo
|
||||
if filetools.write(item.nfo, head_nfo + it.tojson()):
|
||||
item.infoLabels['playcount'] = item.playcount
|
||||
logger.debug(item.playcount)
|
||||
#logger.debug(item.playcount)
|
||||
|
||||
# if item.contentType == 'episodesss':
|
||||
# Actualizar toda la serie
|
||||
@@ -569,7 +595,7 @@ def mark_content_as_watched2(item):
|
||||
|
||||
def mark_content_as_watched(item):
|
||||
logger.info()
|
||||
logger.debug("item:\n" + item.tostring('\n'))
|
||||
#logger.debug("item:\n" + item.tostring('\n'))
|
||||
|
||||
if filetools.exists(item.nfo):
|
||||
head_nfo, it = videolibrarytools.read_nfo(item.nfo)
|
||||
|
||||
@@ -325,6 +325,89 @@ def mark_season_as_watched_on_kodi(item, value=1):
|
||||
execute_sql_kodi(sql)
|
||||
|
||||
|
||||
def mark_content_as_watched_on_alfa(path):
|
||||
from channels import videolibrary
|
||||
from core import videolibrarytools
|
||||
from core import scrapertools
|
||||
import re
|
||||
"""
|
||||
marca toda la serie o película como vista o no vista en la Videoteca de Alfa basado en su estado en la Videoteca de Kodi
|
||||
@type str: path
|
||||
@param path: carpeta de contenido a marcar
|
||||
"""
|
||||
logger.info()
|
||||
#logger.debug("path: " + path)
|
||||
|
||||
FOLDER_MOVIES = config.get_setting("folder_movies")
|
||||
FOLDER_TVSHOWS = config.get_setting("folder_tvshows")
|
||||
VIDEOLIBRARY_PATH = config.get_videolibrary_config_path()
|
||||
|
||||
# Solo podemos marcar el contenido como vista en la BBDD de Kodi si la BBDD es local,
|
||||
# en caso de compartir BBDD esta funcionalidad no funcionara
|
||||
#if config.get_setting("db_mode", "videolibrary"):
|
||||
# return
|
||||
|
||||
path2 = ''
|
||||
if "special://" in VIDEOLIBRARY_PATH:
|
||||
if FOLDER_TVSHOWS in path:
|
||||
path2 = re. sub(r'.*?%s' % FOLDER_TVSHOWS, VIDEOLIBRARY_PATH + "/" + FOLDER_TVSHOWS, path).replace("\\", "/")
|
||||
if FOLDER_MOVIES in path:
|
||||
path2 = re. sub(r'.*?%s' % FOLDER_MOVIES, VIDEOLIBRARY_PATH + "/" + FOLDER_MOVIES, path).replace("\\", "/")
|
||||
|
||||
if "\\" in path:
|
||||
path = path.replace("/", "\\")
|
||||
head_nfo, item = videolibrarytools.read_nfo(path) #Leo el .nfo del contenido
|
||||
|
||||
if FOLDER_TVSHOWS in path: #Compruebo si es CINE o SERIE
|
||||
contentType = "episode_view" #Marco la tabla de BBDD de Kodi Video
|
||||
nfo_name = "tvshow.nfo" #Construyo el nombre del .nfo
|
||||
path1 = path.replace("\\\\", "\\").replace(nfo_name, '') #para la SQL solo necesito la carpeta
|
||||
if not path2:
|
||||
path2 = path1.replace("\\", "/") #Formato no Windows
|
||||
else:
|
||||
path2 = path2.replace(nfo_name, '')
|
||||
|
||||
else:
|
||||
contentType = "movie_view" #Marco la tabla de BBDD de Kodi Video
|
||||
path1 = path.replace("\\\\", "\\") #Formato Windows
|
||||
if not path2:
|
||||
path2 = path1.replace("\\", "/") #Formato no Windows
|
||||
nfo_name = scrapertools.find_single_match(path2, '\]\/(.*?)$') #Construyo el nombre del .nfo
|
||||
path1 = path1.replace(nfo_name, '') #para la SQL solo necesito la carpeta
|
||||
path2 = path2.replace(nfo_name, '') #para la SQL solo necesito la carpeta
|
||||
|
||||
#Ejecutmos la sentencia SQL
|
||||
sql = 'select strFileName, playCount from %s where (strPath like "%s" or strPath like "%s")' % (contentType, path1, path2)
|
||||
nun_records = 0
|
||||
records = None
|
||||
nun_records, records = execute_sql_kodi(sql) #ejecución de la SQL
|
||||
if nun_records == 0: #hay error?
|
||||
logger.error("Error en la SQL: " + sql + ": 0 registros")
|
||||
return #salimos: o no está catalogado en Kodi, o hay un error en la SQL
|
||||
|
||||
for title, playCount in records: #Ahora recorremos todos los registros obtenidos
|
||||
if contentType == "episode_view":
|
||||
title_plain = title.replace('.strm', '') #Si es Serie, quitamos el sufijo .strm
|
||||
else:
|
||||
title_plain = scrapertools.find_single_match(item.strm_path, '.(.*?\s\[.*?\])') #si es peli, quitamos el título
|
||||
if playCount is None or playCount == 0: #todavía no se ha visto, lo ponemos a 0
|
||||
playCount_final = 0
|
||||
elif playCount >= 1:
|
||||
playCount_final = 1
|
||||
title_plain = title_plain.decode("utf-8").encode("utf-8") #Hacemos esto porque si no genera esto: u'title_plain'
|
||||
item.library_playcounts.update({title_plain: playCount_final}) #actualizamos el playCount del .nfo
|
||||
|
||||
if item.infoLabels['mediatype'] == "tvshow": #Actualizamos los playCounts de temporadas y Serie
|
||||
for season in item.library_playcounts:
|
||||
if "season" in season: #buscamos las etiquetas "season" dentro de playCounts
|
||||
season_num = int(scrapertools.find_single_match(season, 'season (\d+)')) #salvamos el núm, de Temporada
|
||||
item = videolibrary.check_season_playcount(item, season_num) #llamamos al método que actualiza Temps. y Series
|
||||
|
||||
filetools.write(path, head_nfo + item.tojson())
|
||||
|
||||
#logger.debug(item)
|
||||
|
||||
|
||||
def get_data(payload):
|
||||
"""
|
||||
obtiene la información de la llamada JSON-RPC con la información pasada en payload
|
||||
|
||||
@@ -14,8 +14,9 @@ from channels import videolibrary
|
||||
def update(path, p_dialog, i, t, serie, overwrite):
|
||||
logger.info("Actualizando " + path)
|
||||
from lib import generictools
|
||||
from platformcode import xbmc_videolibrary
|
||||
insertados_total = 0
|
||||
|
||||
|
||||
head_nfo, it = videolibrarytools.read_nfo(path + '/tvshow.nfo')
|
||||
|
||||
# logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) ))
|
||||
@@ -25,7 +26,7 @@ def update(path, p_dialog, i, t, serie, overwrite):
|
||||
|
||||
###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial
|
||||
try:
|
||||
serie, it, overwrite = generictools.redirect_clone_newpct1(serie, head_nfo, it, overwrite, path)
|
||||
serie, it, overwrite = generictools.redirect_clone_newpct1(serie, head_nfo, it, path, overwrite)
|
||||
except:
|
||||
pass
|
||||
|
||||
@@ -46,8 +47,6 @@ def update(path, p_dialog, i, t, serie, overwrite):
|
||||
|
||||
obj = imp.load_source(serie.channel, pathchannels)
|
||||
itemlist = obj.episodios(serie)
|
||||
|
||||
serie.channel = channel #Restauramos el valor incial del clone de NewPct1
|
||||
|
||||
try:
|
||||
if int(overwrite) == 3:
|
||||
@@ -80,11 +79,19 @@ def update(path, p_dialog, i, t, serie, overwrite):
|
||||
else:
|
||||
logger.debug("Canal %s no activo no se actualiza" % serie.channel)
|
||||
|
||||
#Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa
|
||||
try:
|
||||
xbmc_videolibrary.mark_content_as_watched_on_alfa(path + '/tvshow.nfo')
|
||||
except:
|
||||
pass
|
||||
|
||||
return insertados_total > 0
|
||||
|
||||
|
||||
def check_for_update(overwrite=True):
|
||||
logger.info("Actualizando series...")
|
||||
from lib import generictools
|
||||
from platformcode import xbmc_videolibrary
|
||||
p_dialog = None
|
||||
serie_actualizada = False
|
||||
update_when_finished = False
|
||||
@@ -108,7 +115,17 @@ def check_for_update(overwrite=True):
|
||||
for i, tvshow_file in enumerate(show_list):
|
||||
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file)
|
||||
path = filetools.dirname(tvshow_file)
|
||||
|
||||
|
||||
###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial
|
||||
overwrite_forced = False
|
||||
try:
|
||||
serie, serie, overwrite_forced = generictools.redirect_clone_newpct1(serie, head_nfo, serie, path, overwrite, lookup=True)
|
||||
except:
|
||||
pass
|
||||
if overwrite_forced == True:
|
||||
overwrite = True
|
||||
serie.update_next = ''
|
||||
|
||||
logger.info("serie=" + serie.contentSerieName)
|
||||
p_dialog.update(int(math.ceil((i + 1) * t)), heading, serie.contentSerieName)
|
||||
|
||||
@@ -116,7 +133,14 @@ def check_for_update(overwrite=True):
|
||||
|
||||
if not serie.active:
|
||||
# si la serie no esta activa descartar
|
||||
continue
|
||||
if overwrite_forced == False:
|
||||
#Sincronizamos los episodios vistos desde la videoteca de Kodi con la de Alfa, aunque la serie esté desactivada
|
||||
try:
|
||||
xbmc_videolibrary.mark_content_as_watched_on_alfa(path + '/tvshow.nfo')
|
||||
except:
|
||||
pass
|
||||
|
||||
continue
|
||||
|
||||
# obtenemos las fecha de actualizacion y de la proxima programada para esta serie
|
||||
update_next = serie.update_next
|
||||
@@ -162,6 +186,7 @@ def check_for_update(overwrite=True):
|
||||
if not serie_actualizada:
|
||||
update_next += datetime.timedelta(days=interval)
|
||||
|
||||
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file) #Vuelve a leer el.nfo, que ha sido modificado
|
||||
if interval != int(serie.active) or update_next.strftime('%Y-%m-%d') != serie.update_next:
|
||||
serie.active = interval
|
||||
serie.update_next = update_next.strftime('%Y-%m-%d')
|
||||
@@ -197,6 +222,10 @@ def check_for_update(overwrite=True):
|
||||
|
||||
if p_dialog:
|
||||
p_dialog.close()
|
||||
|
||||
from core.item import Item
|
||||
item_dummy = Item()
|
||||
videolibrary.list_movies(item_dummy, silent=True)
|
||||
|
||||
|
||||
def start(thread=True):
|
||||
|
||||
Reference in New Issue
Block a user