Fix Configurazione Videoteca

This commit is contained in:
Alhaziel01
2021-07-02 18:15:35 +02:00
parent c86cdab9da
commit f9a4d0dbbb
5 changed files with 76 additions and 277 deletions
+1 -2
View File
@@ -3,7 +3,6 @@
# Common Library Tools # Common Library Tools
# ------------------------------------------------------------ # ------------------------------------------------------------
from platformcode.xbmc_videolibrary import execute_sql_kodi
import sys import sys
PY3 = False PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
@@ -19,7 +18,6 @@ from lib import generictools
from platformcode import config, logger, platformtools from platformcode import config, logger, platformtools
from platformcode.autorenumber import RENUMBER from platformcode.autorenumber import RENUMBER
from core.videolibrarydb import videolibrarydb from core.videolibrarydb import videolibrarydb
from platformcode.dbconverter import add_video
FOLDER_MOVIES = config.get_setting("folder_movies") FOLDER_MOVIES = config.get_setting("folder_movies")
FOLDER_TVSHOWS = config.get_setting("folder_tvshows") FOLDER_TVSHOWS = config.get_setting("folder_tvshows")
@@ -899,6 +897,7 @@ def get_fanart_tv(item, set='', ret={}):
def get_local_files(path, item): def get_local_files(path, item):
from platformcode.xbmc_videolibrary import execute_sql_kodi
# check if movie or season already exist in path or db # check if movie or season already exist in path or db
excluded_extensions = subtitle_extensions + image_extensions + library_extension excluded_extensions = subtitle_extensions + image_extensions + library_extension
+58 -22
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import xbmc import xbmc
from core import filetools, support from core import filetools, support, videolibrarytools
from core.videolibrarydb import videolibrarydb from core.videolibrarydb import videolibrarydb
from platformcode import config, logger, platformtools from platformcode import config, logger, platformtools
from platformcode.xbmc_videolibrary import execute_sql_kodi, get_data, get_file_db from platformcode.xbmc_videolibrary import execute_sql_kodi, get_data, get_file_db
@@ -10,6 +10,40 @@ import sqlite3
conn = sqlite3.connect(get_file_db()) conn = sqlite3.connect(get_file_db())
date = strftime('%Y-%m-%d %H:%M:%S', localtime(float(time()))) date = strftime('%Y-%m-%d %H:%M:%S', localtime(float(time())))
def save_all():
movies = dict(videolibrarydb['movie'])
tvshows = dict(videolibrarydb['tvshow'])
videolibrarydb.close()
for movie in movies.values():
item = movie['item']
item.no_reload = True
add_video(item)
for tvshow in tvshows.values():
item = tvshow['item']
item.no_reload = True
add_video(item)
conn.close()
_id = get_id('idShow', 'tvshow') + get_id('idMovie', 'movie')
if _id == 1:
payload = {
"jsonrpc": "2.0",
"method": "VideoLibrary.Scan",
"directory": videolibrarytools.FOLDER_MOVIES,
"id": 1
}
get_data(payload)
payload = {
"jsonrpc": "2.0",
"method": "VideoLibrary.Scan",
"directory": videolibrarytools.FOLDER_TVSHOWS,
"id": 1
}
get_data(payload)
else:
xbmc.executebuiltin('ReloadSkin()')
def add_video(item): def add_video(item):
progress = platformtools.dialog_progress_bg('Sincronizzazione Libreria', item.title) progress = platformtools.dialog_progress_bg('Sincronizzazione Libreria', item.title)
progress.update(0) progress.update(0)
@@ -173,16 +207,17 @@ class addMovie(object):
execute_sql(self.sql_actions) execute_sql(self.sql_actions)
# need if no movie in kodi library # need if no movie in kodi library
if self.VideoId == 1: if not self.item.no_reload:
payload = { if self.VideoId == 1:
"jsonrpc": "2.0", payload = {
"method": "VideoLibrary.Scan", "jsonrpc": "2.0",
"directory": self.strPath, "method": "VideoLibrary.Scan",
"id": 1 "directory": self.strPath,
} "id": 1
get_data(payload) }
else: get_data(payload)
xbmc.executebuiltin('ReloadSkin()') else:
xbmc.executebuiltin('ReloadSkin()')
conn.close() conn.close()
def get_id(self): def get_id(self):
@@ -434,17 +469,18 @@ class addTvShow(object):
execute_sql(self.sql_actions) execute_sql(self.sql_actions)
# need if no movie in kodi library # need if no movie in kodi library
if self.idShow == 1: if not self.item.no_reload:
payload = { if self.idShow == 1:
"jsonrpc": "2.0", payload = {
"method": "VideoLibrary.Scan", "jsonrpc": "2.0",
"directory": self.strPath, "method": "VideoLibrary.Scan",
"id": 1 "directory": self.strPath,
} "id": 1
get_data(payload) }
else: get_data(payload)
xbmc.executebuiltin('ReloadSkin()') else:
conn.close() xbmc.executebuiltin('ReloadSkin()')
conn.close()
def get_idShow(self): def get_idShow(self):
sql = 'select idShow from tvshow_view where uniqueid_value = {} and uniqueid_type = "kod"'.format(self.info['tmdb_id']) sql = 'select idShow from tvshow_view where uniqueid_value = {} and uniqueid_type = "kod"'.format(self.info['tmdb_id'])
+15 -251
View File
@@ -5,6 +5,8 @@
# from future import standard_library # from future import standard_library
# standard_library.install_aliases() # standard_library.install_aliases()
#from builtins import str #from builtins import str
from specials import videolibrary
from platformcode.contextmenu.update_tv_show import join
from core.item import Item from core.item import Item
import sys, os, threading, time, re, math, xbmc, xbmcgui, sqlite3 import sys, os, threading, time, re, math, xbmc, xbmcgui, sqlite3
PY3 = False PY3 = False
@@ -561,260 +563,22 @@ def search_local_path(item):
return '' return ''
def set_content(content_type, silent=False, custom=False): def set_content(silent=False):
"""
Procedure to auto-configure the kodi video library with the default values
@type content_type: str ('movie' o 'tvshow')
@param content_type: content type to configure, series or movies
"""
logger.debug() logger.debug()
continuar = True
msg_text = ""
videolibrarypath = config.get_setting("videolibrarypath") videolibrarypath = config.get_setting("videolibrarypath")
sep = '/' if '/' in videolibrarypath else '\\'
if content_type == 'movie': paths = {'movie': filetools.join(videolibrarypath, config.get_setting('folder_movies')) + sep,
scraper = [config.get_localized_string(70093), config.get_localized_string(70096)] 'tvshow': filetools.join(videolibrarypath, config.get_setting('folder_tvshows')) + sep}
if not custom: for k, v in paths.items():
seleccion = 0 # tmdb sql = 'SELECT idPath, strPath FROM path where strPath= "{}"'.format(v)
n, records = execute_sql_kodi(sql)
if records:
sql = 'update path set strScraper="metadata.local" where idPath={}'.format(records[0][0])
n, records = execute_sql_kodi(sql)
else: else:
seleccion = platformtools.dialog_select(config.get_localized_string(70094), scraper) sql ='INSERT OR IGNORE INTO path (strPath, strContent, strScraper, scanRecursive, useFolderNames, strSettings, noUpdate) VALUES ("{}", "{}", "metadata.local", 0, 0, 0, 0)'.format(v, k)
n, records = execute_sql_kodi(sql)
from platformcode.dbconverter import save_all; save_all()
# Instalar The Movie Database
if seleccion == -1 or seleccion == 0:
if not xbmc.getCondVisibility('System.HasAddon(metadata.themoviedb.org)'):
if not silent:
# Ask if we want to install metadata.themoviedb.org
install = platformtools.dialog_yesno(config.get_localized_string(60046),'')
else:
install = True
if install:
try:
# Install metadata.themoviedb.org
xbmc.executebuiltin('InstallAddon(metadata.themoviedb.org)', True)
logger.debug("Instalado el Scraper de películas de TheMovieDB")
except:
pass
continuar = (install and xbmc.getCondVisibility('System.HasAddon(metadata.themoviedb.org)'))
if not continuar:
msg_text = config.get_localized_string(60047)
if continuar:
xbmc.executebuiltin('Addon.OpenSettings(metadata.themoviedb.org)', True)
# Instalar Universal Movie Scraper
elif seleccion == 1:
if continuar and not xbmc.getCondVisibility('System.HasAddon(metadata.universal)'):
continuar = False
if not silent:
# Ask if we want to install metadata.universal
install = platformtools.dialog_yesno(config.get_localized_string(70095),'')
else:
install = True
if install:
try:
xbmc.executebuiltin('InstallAddon(metadata.universal)', True)
if xbmc.getCondVisibility('System.HasAddon(metadata.universal)'):
continuar = True
except:
pass
continuar = (install and continuar)
if not continuar:
msg_text = config.get_localized_string(70097)
if continuar:
xbmc.executebuiltin('Addon.OpenSettings(metadata.universal)', True)
else: # SERIES
scraper = [config.get_localized_string(70093), config.get_localized_string(70098)]
if not custom:
seleccion = 0 # tmdb
else:
seleccion = platformtools.dialog_select(config.get_localized_string(70107), scraper)
# Instalar The Movie Database
if seleccion == -1 or seleccion == 0:
if continuar and not xbmc.getCondVisibility('System.HasAddon(metadata.tvshows.themoviedb.org)'):
continuar = False
if not silent:
# Ask if we want to install metadata.tvshows.themoviedb.org
install = platformtools.dialog_yesno(config.get_localized_string(60050),'')
else:
install = True
if install:
try:
# Install metadata.tvshows.themoviedb.org
xbmc.executebuiltin('InstallAddon(metadata.tvshows.themoviedb.org)', True)
if xbmc.getCondVisibility('System.HasAddon(metadata.tvshows.themoviedb.org)'):
continuar = True
except:
pass
continuar = (install and continuar)
if not continuar:
msg_text = config.get_localized_string(60051)
if continuar:
xbmc.executebuiltin('Addon.OpenSettings(metadata.tvshows.themoviedb.org)', True)
# Instalar The TVDB
elif seleccion == 1:
if not xbmc.getCondVisibility('System.HasAddon(metadata.tvdb.com)'):
if not silent:
#Ask if we want to install metadata.tvdb.com
install = platformtools.dialog_yesno(config.get_localized_string(60048),'')
else:
install = True
if install:
try:
# Install metadata.tvdb.com
xbmc.executebuiltin('InstallAddon(metadata.tvdb.com)', True)
logger.debug("The TVDB series Scraper installed ")
except:
pass
continuar = (install and xbmc.getCondVisibility('System.HasAddon(metadata.tvdb.com)'))
if not continuar:
msg_text = config.get_localized_string(60049)
if continuar:
xbmc.executebuiltin('Addon.OpenSettings(metadata.tvdb.com)', True)
idPath = 0
idParentPath = 0
if continuar:
continuar = False
# We look for the idPath
sql = 'SELECT MAX(idPath) FROM path'
nun_records, records = execute_sql_kodi(sql)
if nun_records == 1:
idPath = records[0][0] + 1
sql_videolibrarypath = videolibrarypath
if sql_videolibrarypath.startswith("special://"):
sql_videolibrarypath = sql_videolibrarypath.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
elif scrapertools.find_single_match(sql_videolibrarypath, r'(^\w+:\/\/)'):
sep = '/'
else:
sep = os.sep
if not sql_videolibrarypath.endswith(sep):
sql_videolibrarypath += sep
# We are looking for the idParentPath
sql = 'SELECT idPath, strPath FROM path where strPath LIKE "%s"' % sql_videolibrarypath
nun_records, records = execute_sql_kodi(sql)
if nun_records == 1:
idParentPath = records[0][0]
videolibrarypath = records[0][1][:-1]
continuar = True
else:
# There is no videolibrarypath in the DB: we insert it
sql_videolibrarypath = videolibrarypath
if not sql_videolibrarypath.endswith(sep):
sql_videolibrarypath += sep
sql = 'INSERT INTO path (idPath, strPath, scanRecursive, useFolderNames, noUpdate, exclude) VALUES ' \
'(%s, "%s", 0, 0, 0, 0)' % (idPath, sql_videolibrarypath)
nun_records, records = execute_sql_kodi(sql)
if nun_records == 1:
continuar = True
idParentPath = idPath
idPath += 1
else:
msg_text = config.get_localized_string(70101)
if continuar:
continuar = False
# We set strContent, strScraper, scanRecursive and strSettings
if content_type == 'movie':
strContent = 'movies'
scanRecursive = 2147483647
if seleccion == -1 or seleccion == 0:
strScraper = 'metadata.themoviedb.org'
path_settings = xbmc.translatePath("special://profile/addon_data/metadata.themoviedb.org/settings.xml")
elif seleccion == 1:
strScraper = 'metadata.universal'
path_settings = xbmc.translatePath("special://profile/addon_data/metadata.universal/settings.xml")
if not os.path.exists(path_settings):
logger.debug("%s: %s" % (content_type, path_settings + " doesn't exist"))
return continuar
settings_data = filetools.read(path_settings)
strSettings = ' '.join(settings_data.split()).replace("> <", "><")
strSettings = strSettings.replace("\"","\'")
strActualizar = "Do you want to set this Scraper in Spanish as the default option for movies?"
if not videolibrarypath.endswith(sep):
videolibrarypath += sep
strPath = videolibrarypath + config.get_setting("folder_movies") + sep
else:
strContent = 'tvshows'
scanRecursive = 0
if seleccion == -1 or seleccion == 0:
strScraper = 'metadata.tvshows.themoviedb.org'
path_settings = xbmc.translatePath("special://profile/addon_data/metadata.tvshows.themoviedb.org/settings.xml")
elif seleccion == 1:
strScraper = 'metadata.tvdb.com'
path_settings = xbmc.translatePath("special://profile/addon_data/metadata.tvdb.com/settings.xml")
if not os.path.exists(path_settings):
logger.debug("%s: %s" % (content_type, path_settings + " doesn't exist"))
return continuar
settings_data = filetools.read(path_settings)
strSettings = ' '.join(settings_data.split()).replace("> <", "><")
strSettings = strSettings.replace("\"","\'")
strActualizar = "Do you want to configure this Scraper in Spanish as a default option for series?"
if not videolibrarypath.endswith(sep):
videolibrarypath += sep
strPath = videolibrarypath + config.get_setting("folder_tvshows") + sep
logger.debug("%s: %s" % (content_type, strPath))
# We check if strPath already exists in the DB to avoid duplicates
sql = 'SELECT idPath FROM path where strPath="%s"' % strPath
nun_records, records = execute_sql_kodi(sql)
sql = ""
if nun_records == 0:
# Insertamos el scraper
sql = 'INSERT INTO path (idPath, strPath, strContent, strScraper, scanRecursive, useFolderNames, ' \
'strSettings, noUpdate, exclude, idParentPath) VALUES (%s, "%s", "%s", "%s", %s, 0, ' \
'"%s", 0, 0, %s)' % (
idPath, strPath, strContent, strScraper, scanRecursive, strSettings, idParentPath)
else:
if not silent:
# Preguntar si queremos configurar themoviedb.org como opcion por defecto
actualizar = platformtools.dialog_yesno(config.get_localized_string(70098), strActualizar)
else:
actualizar = True
if actualizar:
# Actualizamos el scraper
idPath = records[0][0]
sql = 'UPDATE path SET strContent="%s", strScraper="%s", scanRecursive=%s, strSettings="%s" ' \
'WHERE idPath=%s' % (strContent, strScraper, scanRecursive, strSettings, idPath)
if sql:
nun_records, records = execute_sql_kodi(sql)
if nun_records == 1:
continuar = True
if not continuar:
msg_text = config.get_localized_string(60055)
if not continuar:
heading = config.get_localized_string(70102) % content_type
elif content_type == 'tvshow' and not xbmc.getCondVisibility(
'System.HasAddon(metadata.tvshows.themoviedb.org)'):
heading = config.get_localized_string(70103) % content_type
msg_text = config.get_localized_string(60058)
else:
heading = config.get_localized_string(70103) % content_type
msg_text = config.get_localized_string(70104)
logger.debug("%s: %s" % (heading, msg_text))
return continuar
def update_db(old_path, new_path, old_movies_folder, new_movies_folder, old_tvshows_folder, new_tvshows_folder, progress): def update_db(old_path, new_path, old_movies_folder, new_movies_folder, old_tvshows_folder, new_tvshows_folder, progress):
+1 -1
View File
@@ -112,7 +112,7 @@ class AddonMonitor(xbmc.Monitor):
# if you want to autoconfigure and the video library directory had been created # if you want to autoconfigure and the video library directory had been created
if not self.settings_pre.get("videolibrary_kodi", None) and settings_post.get("videolibrary_kodi", None): if not self.settings_pre.get("videolibrary_kodi", None) and settings_post.get("videolibrary_kodi", None):
xbmc_videolibrary.ask_set_content(silent=True) xbmc_videolibrary.set_content(silent=True)
elif self.settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None): elif self.settings_pre.get("videolibrary_kodi", None) and not settings_post.get("videolibrary_kodi", None):
xbmc_videolibrary.clean() xbmc_videolibrary.clean()
+1 -1
View File
@@ -791,7 +791,7 @@ class SearchWindow(xbmcgui.WindowXML):
def play(self, server=None): def play(self, server=None):
platformtools.prevent_platformtools.dialog_busy(server) platformtools.prevent_busy(server)
server.window = True server.window = True
server.globalsearch = True server.globalsearch = True
return run(server) return run(server)