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))
|
caption=config.get_localized_string(60598))
|
||||||
|
|
||||||
|
|
||||||
def list_movies(item):
|
def list_movies(item, silent=False):
|
||||||
logger.info()
|
logger.info()
|
||||||
itemlist = []
|
itemlist = []
|
||||||
|
from platformcode import xbmc_videolibrary
|
||||||
|
from lib import generictools
|
||||||
|
|
||||||
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.MOVIES_PATH):
|
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.MOVIES_PATH):
|
||||||
for f in ficheros:
|
for f in ficheros:
|
||||||
if f.endswith(".nfo"):
|
if f.endswith(".nfo"):
|
||||||
nfo_path = filetools.join(raiz, f)
|
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)
|
head_nfo, new_item = videolibrarytools.read_nfo(nfo_path)
|
||||||
|
|
||||||
new_item.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
|
# Si se ha eliminado el strm desde la bilbioteca de kodi, no mostrarlo
|
||||||
continue
|
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
|
# Menu contextual: Marcar como visto/no visto
|
||||||
visto = new_item.library_playcounts.get(os.path.splitext(f)[0], 0)
|
visto = new_item.library_playcounts.get(os.path.splitext(f)[0], 0)
|
||||||
new_item.infoLabels["playcount"] = visto
|
new_item.infoLabels["playcount"] = visto
|
||||||
@@ -85,12 +100,16 @@ def list_movies(item):
|
|||||||
# logger.debug("new_item: " + new_item.tostring('\n'))
|
# logger.debug("new_item: " + new_item.tostring('\n'))
|
||||||
itemlist.append(new_item)
|
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):
|
def list_tvshows(item):
|
||||||
logger.info()
|
logger.info()
|
||||||
itemlist = []
|
itemlist = []
|
||||||
|
from platformcode import xbmc_videolibrary
|
||||||
|
|
||||||
# Obtenemos todos los tvshow.nfo de la videoteca de SERIES recursivamente
|
# Obtenemos todos los tvshow.nfo de la videoteca de SERIES recursivamente
|
||||||
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.TVSHOWS_PATH):
|
for raiz, subcarpetas, ficheros in filetools.walk(videolibrarytools.TVSHOWS_PATH):
|
||||||
@@ -98,6 +117,13 @@ def list_tvshows(item):
|
|||||||
if f == "tvshow.nfo":
|
if f == "tvshow.nfo":
|
||||||
tvshow_path = filetools.join(raiz, f)
|
tvshow_path = filetools.join(raiz, f)
|
||||||
# logger.debug(tvshow_path)
|
# 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)
|
head_nfo, item_tvshow = videolibrarytools.read_nfo(tvshow_path)
|
||||||
item_tvshow.title = item_tvshow.contentTitle
|
item_tvshow.title = item_tvshow.contentTitle
|
||||||
item_tvshow.path = raiz
|
item_tvshow.path = raiz
|
||||||
@@ -552,7 +578,7 @@ def mark_content_as_watched2(item):
|
|||||||
# Guardamos los cambios en item.nfo
|
# Guardamos los cambios en item.nfo
|
||||||
if filetools.write(item.nfo, head_nfo + it.tojson()):
|
if filetools.write(item.nfo, head_nfo + it.tojson()):
|
||||||
item.infoLabels['playcount'] = item.playcount
|
item.infoLabels['playcount'] = item.playcount
|
||||||
logger.debug(item.playcount)
|
#logger.debug(item.playcount)
|
||||||
|
|
||||||
# if item.contentType == 'episodesss':
|
# if item.contentType == 'episodesss':
|
||||||
# Actualizar toda la serie
|
# Actualizar toda la serie
|
||||||
@@ -569,7 +595,7 @@ def mark_content_as_watched2(item):
|
|||||||
|
|
||||||
def mark_content_as_watched(item):
|
def mark_content_as_watched(item):
|
||||||
logger.info()
|
logger.info()
|
||||||
logger.debug("item:\n" + item.tostring('\n'))
|
#logger.debug("item:\n" + item.tostring('\n'))
|
||||||
|
|
||||||
if filetools.exists(item.nfo):
|
if filetools.exists(item.nfo):
|
||||||
head_nfo, it = videolibrarytools.read_nfo(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)
|
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):
|
def get_data(payload):
|
||||||
"""
|
"""
|
||||||
obtiene la información de la llamada JSON-RPC con la información pasada en 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):
|
def update(path, p_dialog, i, t, serie, overwrite):
|
||||||
logger.info("Actualizando " + path)
|
logger.info("Actualizando " + path)
|
||||||
from lib import generictools
|
from lib import generictools
|
||||||
|
from platformcode import xbmc_videolibrary
|
||||||
insertados_total = 0
|
insertados_total = 0
|
||||||
|
|
||||||
head_nfo, it = videolibrarytools.read_nfo(path + '/tvshow.nfo')
|
head_nfo, it = videolibrarytools.read_nfo(path + '/tvshow.nfo')
|
||||||
|
|
||||||
# logger.debug("%s: %s" %(serie.contentSerieName,str(list_canales) ))
|
# 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
|
###### Redirección al canal NewPct1.py si es un clone, o a otro canal y url si ha intervención judicial
|
||||||
try:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -46,8 +47,6 @@ def update(path, p_dialog, i, t, serie, overwrite):
|
|||||||
|
|
||||||
obj = imp.load_source(serie.channel, pathchannels)
|
obj = imp.load_source(serie.channel, pathchannels)
|
||||||
itemlist = obj.episodios(serie)
|
itemlist = obj.episodios(serie)
|
||||||
|
|
||||||
serie.channel = channel #Restauramos el valor incial del clone de NewPct1
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if int(overwrite) == 3:
|
if int(overwrite) == 3:
|
||||||
@@ -80,11 +79,19 @@ def update(path, p_dialog, i, t, serie, overwrite):
|
|||||||
else:
|
else:
|
||||||
logger.debug("Canal %s no activo no se actualiza" % serie.channel)
|
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
|
return insertados_total > 0
|
||||||
|
|
||||||
|
|
||||||
def check_for_update(overwrite=True):
|
def check_for_update(overwrite=True):
|
||||||
logger.info("Actualizando series...")
|
logger.info("Actualizando series...")
|
||||||
|
from lib import generictools
|
||||||
|
from platformcode import xbmc_videolibrary
|
||||||
p_dialog = None
|
p_dialog = None
|
||||||
serie_actualizada = False
|
serie_actualizada = False
|
||||||
update_when_finished = False
|
update_when_finished = False
|
||||||
@@ -108,7 +115,17 @@ def check_for_update(overwrite=True):
|
|||||||
for i, tvshow_file in enumerate(show_list):
|
for i, tvshow_file in enumerate(show_list):
|
||||||
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file)
|
head_nfo, serie = videolibrarytools.read_nfo(tvshow_file)
|
||||||
path = filetools.dirname(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)
|
logger.info("serie=" + serie.contentSerieName)
|
||||||
p_dialog.update(int(math.ceil((i + 1) * t)), heading, 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:
|
if not serie.active:
|
||||||
# si la serie no esta activa descartar
|
# 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
|
# obtenemos las fecha de actualizacion y de la proxima programada para esta serie
|
||||||
update_next = serie.update_next
|
update_next = serie.update_next
|
||||||
@@ -162,6 +186,7 @@ def check_for_update(overwrite=True):
|
|||||||
if not serie_actualizada:
|
if not serie_actualizada:
|
||||||
update_next += datetime.timedelta(days=interval)
|
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:
|
if interval != int(serie.active) or update_next.strftime('%Y-%m-%d') != serie.update_next:
|
||||||
serie.active = interval
|
serie.active = interval
|
||||||
serie.update_next = update_next.strftime('%Y-%m-%d')
|
serie.update_next = update_next.strftime('%Y-%m-%d')
|
||||||
@@ -197,6 +222,10 @@ def check_for_update(overwrite=True):
|
|||||||
|
|
||||||
if p_dialog:
|
if p_dialog:
|
||||||
p_dialog.close()
|
p_dialog.close()
|
||||||
|
|
||||||
|
from core.item import Item
|
||||||
|
item_dummy = Item()
|
||||||
|
videolibrary.list_movies(item_dummy, silent=True)
|
||||||
|
|
||||||
|
|
||||||
def start(thread=True):
|
def start(thread=True):
|
||||||
|
|||||||
Reference in New Issue
Block a user