- Fix Videoteca

- Aggiunti server VOE e HighLoad
 - dbg spostato in logger
 - altre migliorie
This commit is contained in:
Alhaziel01
2021-09-29 10:35:21 +02:00
parent 4046014220
commit fee7a27758
52 changed files with 492 additions and 392 deletions
+3 -3
View File
@@ -7,7 +7,7 @@
import xbmc, xbmcgui, re, base64, sys
from core import jsontools, tmdb, filetools
from core.item import Item
from core.support import typo, dbg, Item
from core.support import typo, Item
from platformcode import config, platformtools, logger
PY3 = True if sys.version_info[0] >= 3 else False
if PY3:
@@ -70,7 +70,7 @@ def b64(json, mode = 'encode'):
def find_episodes(item):
logger.debug()
ch = __import__('channels.' + item.channel, fromlist=["channels.{}".format(item.channel)])
ch = platformtools.channel_import(item.channel)
itemlist = getattr(ch, item.action)(item)
return itemlist
@@ -187,7 +187,7 @@ class autorenumber():
item.contentSeason = int(self.episodes[number].split('x')[0])
item.contentEpisodeNumber = int(self.episodes[number].split('x')[1])
# dbg()
# logger.dbg()
# for i in self.itemlist:
# sub_thread(i)
+1 -1
View File
@@ -121,7 +121,7 @@ def get_id():
return dbid
def check_condition():
# support.dbg()
# logger.dbg()
global path
path = search_paths(get_id())
return path
+22 -10
View File
@@ -10,9 +10,9 @@ import sqlite3
# conn = sqlite3.connect(get_file_db())
date = strftime('%Y-%m-%d %H:%M:%S', localtime(float(time())))
def save_all():
movies = dict(videolibrarydb['movie'])
tvshows = dict(videolibrarydb['tvshow'])
def save_all(_type=''):
movies = dict(videolibrarydb['movie']) if _type == 'movie' or not _type else {}
tvshows = dict(videolibrarydb['tvshow']) if _type == 'tvshow' or not _type else {}
videolibrarydb.close()
for movie in movies.values():
@@ -93,6 +93,12 @@ def get_id(column, table):
else: _id = 1
return _id
def exist(value, column, table):
statement = False
sql = 'SELECT * FROM {} WHERE {} = {}'.format(table, column, value)
nun_records, records = execute_sql_kodi(sql, conn=conn)
if nun_records: statement = True
return statement
def get_images(item):
@@ -292,13 +298,19 @@ class addMovie(object):
def set_files(self):
self.idFile = get_id('idFile', 'files')
if self.info.get('playcount', None):
sql = 'INSERT OR IGNORE INTO files (idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) VALUES ( ?, ?, ?, ?, ?, ?)'
params = (self.idFile, self.idPath, self.strFilename, self.info.get('playcount', None), self.item.lastplayed, date)
if exist(self.idPath, 'idpath', 'files'):
if self.info.get('playcount', None):
sql = 'UPDATE path SET playCount=? WHERE idPath=?'
params = (self.info.get('playcount', None), self.idPath)
self.sql_actions.append([sql, params])
else:
sql = 'INSERT OR IGNORE INTO files (idFile, idPath, strFilename, dateAdded) VALUES ( ?, ?, ?, ?)'
params = (self.idFile, self.idPath, self.strFilename, date)
self.sql_actions.append([sql, params])
if self.info.get('playcount', None):
sql = 'INSERT OR IGNORE INTO files (idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) VALUES ( ?, ?, ?, ?, ?, ?)'
params = (self.idFile, self.idPath, self.strFilename, self.info.get('playcount', None), self.item.lastplayed, date)
else:
sql = 'INSERT OR IGNORE INTO files (idFile, idPath, strFilename, dateAdded) VALUES ( ?, ?, ?, ?)'
params = (self.idFile, self.idPath, self.strFilename, date)
self.sql_actions.append([sql, params])
def set_rating(self):
self.rating_id = get_id('rating_id', 'rating')
@@ -595,7 +607,7 @@ class addTvShow(object):
files = {r[1].replace('.strm',''):r[0] for r in records}
self.idFiles = {}
idFile = get_id('idFile', 'files')
# support.dbg()
# logger.dbg()
for episode in self.idEpisodes.keys():
if episode in files.keys():
self.idFiles[episode] = files[episode]
+1 -1
View File
@@ -60,7 +60,7 @@ def extract():
def setting():
# support.dbg()
# logger.dbg()
xbmc.executebuiltin('UpdateLocalAddons')
xbmc.sleep(1000)
if filetools.isfile(elementum_setting_file):
+1 -1
View File
@@ -8,7 +8,7 @@ from core import httptools, tmdb
from core.item import Item
from platformcode import config, platformtools, logger
from core.support import match, typo, dbg
from core.support import match, typo
info_list = []
+1 -1
View File
@@ -186,7 +186,7 @@ class Main(xbmcgui.WindowXMLDialog):
import channelselector
itemlist = self.menulist(channelselector.getchanneltypes())
elif channel_name not in ['downloads', 'setting', 'help']:
channel = __import__('specials.%s' % channel_name, fromlist=["specials.%s" % channel_name])
channel = platformtools.channel_import(channel_name)
itemlist = self.menulist(channel.mainlist(Item().fromurl(self.MENU.getSelectedItem().getProperty('run'))))
self.SUBMENU.reset()
self.SUBMENU.addItems(itemlist)
+22 -45
View File
@@ -46,6 +46,8 @@ def run(item=None):
if len(sp) > 1:
for e in sp[1:]:
key, val = e.split('=')
if val.lower() == 'false': val = False
elif val.lower() == 'true': val = True
item.__setattr__(key, val)
# If no item, this is mainlist
else:
@@ -66,7 +68,6 @@ def run(item=None):
config.set_setting('show_once', True)
logger.info(item.tostring())
# from core.support import dbg;dbg()
try:
if not config.get_setting('tmdb_active'):
@@ -113,8 +114,7 @@ def run(item=None):
elif item.channel == "infoplus":
from platformcode import infoplus
action = getattr(infoplus, item.action)
return action(item)
return getattr(infoplus, item.action)(item)
elif item.channel == 'trakt_tools':
from core import trakt_tools
@@ -156,7 +156,6 @@ def run(item=None):
else:
platformtools.dialog_ok(config.get_localized_string(20000), config.get_localized_string(70740) % "\n".join([item.url[j:j+57] for j in range(0, len(item.url), 57)]))
elif item.action == "gotopage":
# from core.support import dbg;dbg()
from core import scrapertools
head = config.get_localized_string(70511)
scraped_page = scrapertools.find_single_match(item.url,'[=/]([0-9]+)')
@@ -184,23 +183,9 @@ def run(item=None):
item.nextSeason = season
xbmc.executebuiltin("Container.Update(%s?%s)" % (sys.argv[0], item.tourl()))
else:
# Checks if channel exists
if os.path.isfile(os.path.join(config.get_runtime_path(), 'channels', item.channel + ".py")):
CHANNELS = 'channels'
else:
CHANNELS = 'specials'
channel_file = os.path.join(config.get_runtime_path(), CHANNELS, item.channel + ".py")
logger.debug("channel_file= " + channel_file + ' - ' + CHANNELS + ' - ' + item.channel)
channel = None
if os.path.exists(channel_file):
try:
channel = __import__('%s.%s' % (CHANNELS, item.channel), None, None, ['%s.%s' % (CHANNELS, item.channel)])
except ImportError:
exec("import " + CHANNELS + "." + item.channel + " as channel")
channel = platformtools.channel_import(item.channel)
if not channel:
return
logger.info("Running channel %s | %s" % (channel.__name__, channel.__file__))
@@ -244,7 +229,8 @@ def run(item=None):
# Special action for findvideos, where the plugin looks for known urls
elif item.action == "findvideos":
from core import servertools
if item.window and item.channel != 'videolibrary':
p_dialog = None
if item.window:
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(60683))
p_dialog.update(0)
@@ -260,7 +246,7 @@ def run(item=None):
if config.get_setting("max_links", "videolibrary") != 0:
itemlist = limit_itemlist(itemlist)
if item.window and item.channel not in ['videolibrary', 'local']:
if p_dialog:
p_dialog.update(100)
p_dialog.close()
platformtools.serverwindow(item, itemlist)
@@ -291,7 +277,6 @@ def run(item=None):
# Special action for searching, first asks for the words then call the "search" function
elif item.action == "search":
# from core.support import dbg;dbg()
if filetools.isfile(temp_search_file) and config.get_setting('videolibrary_kodi'):
itemlist = []
f = filetools.read(temp_search_file)
@@ -474,27 +459,19 @@ def play_from_library(item):
@param item: item with information
"""
# def get_played_time(item):
# if item.contentType == 'movie': nfo_path = item.nfo
# else: nfo_path = item.strm_path.replace('strm','nfo')
# if nfo_path and filetools.isfile(nfo_path):
# from core import videolibrarytools
# head_nfo, item_nfo = videolibrarytools.read_nfo(nfo_path)
# sleep(1)
# played_time = platformtools.get_played_time(item_nfo)
# else: played_time = 0
# return played_time
# from time import sleep
# logger.debug("item: \n" + item.tostring('\n'))
# from core.support import dbg; dbg()
import xbmc, xbmcgui, xbmcplugin
item.window_type = config.get_setting("window_type") if config.get_setting('next_ep') < 3 and item.contentType != 'movie' else 0
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path=os.path.join(config.get_runtime_path(), "resources", "kod.mp4")))
xbmc.Player().stop()
if xbmc.getCondVisibility('Window.IsMedia') and not item.window_type == 0:
platformtools.window_type(item)
platformtools.prevent_busy(item)
item.action = item.next_action if item.next_action else 'findvideos'
if not item.videolibrary_id:
if item.window and item.action == 'findvideos':
return run(item)
else:
xbmc.executebuiltin("Container.Update(" + sys.argv[0] + "?" + item.tourl() + ")")
elif xbmc.getCondVisibility('Window.IsMedia') and not item.window:
if item.contentType == 'episode':
it = videolibrarydb[item.contentType][item.videolibrary_id]['{}x{:02d}'.format(item.infoLabels['season'], item.infoLabels['episode'])]['item']
else:
@@ -504,4 +481,4 @@ def play_from_library(item):
videolibrarydb.close()
else:
item.window = True
return videolibrary.findvideos(item)
return run(item)
+11
View File
@@ -51,6 +51,17 @@ def log(*args, **kwargs):
function=frame.f_code.co_name,
message=msg), kwargs.get('level', DEF_LEVEL))
def dbg(open=True):
if config.dev_mode():
try:
import web_pdb
if not web_pdb.WebPdb.active_instance and open:
import webbrowser
webbrowser.open('http://127.0.0.1:5555')
web_pdb.set_trace()
except:
pass
class WebErrorException(Exception):
def __init__(self, url, channel, *args, **kwargs):
+27 -15
View File
@@ -18,7 +18,7 @@ else:
import os, xbmc, xbmcgui, xbmcplugin
from past.utils import old_div
from core import scrapertools
from core import filetools, scrapertools
from core.item import Item
from platformcode import logger, config
@@ -425,7 +425,7 @@ def render_items(itemlist, parent_item):
return item, item_url, listitem
# For Debug
# from core.support import dbg;dbg()
# logger.dbg()
# r_list = [set_item(i, item, parent_item) for i, item in enumerate(itemlist)]
r_list = []
@@ -674,7 +674,6 @@ def set_context_commands(item, item_url, parent_item, **kwargs):
# context_commands.append((config.get_localized_string(60348), "Action(Info)"))
# InfoPlus
# from core.support import dbg;dbg()
# if config.get_setting("infoplus"):
#if item.infoLabels['tmdb_id'] or item.infoLabels['imdb_id'] or item.infoLabels['tvdb_id'] or \
# (item.contentTitle and item.infoLabels["year"]) or item.contentSerieName:
@@ -1054,7 +1053,7 @@ def play_video(item, strm=False, force_direct=False, autoplay=False):
if not mediaurl: return
# video information is obtained.
xlistitem = xbmcgui.ListItem(item.title, path=item.url)
xlistitem = xbmcgui.ListItem(item.contentTitle, path=item.url)
xlistitem.setArt({"thumb": item.contentThumbnail if item.contentThumbnail else item.thumbnail})
set_infolabels(xlistitem, item, True)
@@ -1771,7 +1770,6 @@ def get_platform():
def get_played_time(item):
logger.debug()
from core import db
# from core.support import dbg;dbg()
played_time = 0
if not item.infoLabels:
@@ -1801,7 +1799,6 @@ def get_played_time(item):
def set_played_time(item):
logger.debug()
from core import db
# from core.support import dbg;dbg()
played_time = item.played_time
if not item.infoLabels:
@@ -1815,6 +1812,7 @@ def set_played_time(item):
e = item.infoLabels.get('episode')
try:
# logger.dbg()
if e:
newDict = db['viewed'].get(ID, {})
newDict['{}x{}'.format(s, e)] = played_time
@@ -1828,16 +1826,9 @@ def set_played_time(item):
del db['viewed'][ID]
# def prevent_busy(item):
# logger.debug()
# if not item.autoplay and not item.window:
# xbmc.Player().play(os.path.join(config.get_runtime_path(), "resources", "kod.mp4"))
# xbmc.sleep(200)
# xbmc.Player().stop()
def prevent_busy(item):
logger.debug()
if not item.autoplay and not item.window:
if item.action == 'play_from_library' or (not item.autoplay and not item.window):
if item.globalsearch: xbmc.Player().play(os.path.join(config.get_runtime_path(), "resources", "kod.mp4"))
else: xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xbmcgui.ListItem(path=os.path.join(config.get_runtime_path(), "resources", "kod.mp4")))
xbmc.sleep(200)
@@ -1909,4 +1900,25 @@ def serverwindow(item, itemlist):
else:
from platformcode.launcher import run
run(selection)
reopen = True
reopen = True
def window_type(item):
if type(item.window) == bool:
pass
elif config.get_setting('window_type') == 0 or (config.get_setting('next_ep') == 3 and item.contentType != 'movie'):
item.window = True
else:
item.window = False
return item
def channel_import(channel_id):
if filetools.exists(filetools.join(config.get_runtime_path(), 'channels', channel_id + ".py")):
channel = __import__('channels.'+ channel_id, None, None, ["channels." + channel_id])
elif filetools.exists(filetools.join(config.get_runtime_path(), 'specials', channel_id + ".py")):
channel = __import__('specials.' + channel_id, None, None, ["specials." + channel_id])
else:
logger.info('Channel {} not Exist')
channel = None
return channel
-2
View File
@@ -102,7 +102,6 @@ def channels_menu(item):
def check_channels(item):
from specials import setting
from platformcode import config, platformtools
# from core.support import dbg; dbg()
item.channel = 'setting'
item.extra = 'lib_check_datajson'
itemlist = setting.conf_tools(item)
@@ -131,7 +130,6 @@ def SettingOnPosition(item):
def select(item):
# from core.support import dbg;dbg()
from platformcode import config, platformtools
# item.id = setting ID
# item.type = labels or values
+4 -3
View File
@@ -261,6 +261,7 @@ def mark_content_as_watched_on_kodi(item, value=1):
@param value: > 0 for seen, 0 for not seen
"""
logger.debug()
logger.dbg()
if item.contentType == 'movie':
path = '%{}%'.format(item.strm_path.split('\\')[0].split('/')[0] if item.strm_path else item.base_name)
@@ -270,6 +271,7 @@ def mark_content_as_watched_on_kodi(item, value=1):
if r:
payload = {"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": r[0][0], "playcount": value}, "id": 1}
data = get_data(payload)
logger.debug(data)
elif item.contentType == 'episode':
path = '%{}'.format(item.strm_path.replace('\\','%').replace('/', '%'))
sql = 'select idEpisode from episode_view where c18 like "{}"'.format(path)
@@ -299,7 +301,6 @@ def mark_content_as_watched_on_kodi(item, value=1):
def set_watched_on_kod(data):
from specials import videolibrary
from core import videolibrarydb
# from core.support import dbg;dbg()
data = jsontools.load(data)
Type = data.get('item', {}).get('type','')
@@ -329,7 +330,7 @@ def set_watched_on_kod(data):
# item.all_ep
else:
# support.dbg()
# logger.dbg()
sql = 'select strPath from {}_view where (id{} like "{}")'.format(Type, Type.replace('tv','').capitalize(), ID)
n, records = execute_sql_kodi(sql)
if records:
@@ -811,7 +812,7 @@ def clean_by_id(item):
tmdb_id = item.infoLabels.get('tmdb_id', '')
season_id = item.infoLabels.get('temporada_id', '')
episode_id = item.infoLabels.get('episodio_id', '')
# support.dbg()
# logger.dbg()
# search movie ID
if item.contentType == 'movie':