Fix e migliorie Videoteca

- aggiunti in settings:
   - Converti Videoteca
   - Ripristina Videoteca da DB
This commit is contained in:
Alhaziel01
2021-07-14 19:19:32 +02:00
parent b3eff4bb07
commit 2764c48805
10 changed files with 241 additions and 90 deletions
+2 -2
View File
@@ -33,6 +33,7 @@
"piratestreaming": "https://www.piratestreaming.shop",
"polpotv": "https://roma.polpo.tv",
"raiplay": "https://www.raiplay.it",
"seriehd": "https://seriehd.cam",
"serietvonline": "https://serietvonline.art",
"serietvsubita": "http://serietvsubita.xyz",
"serietvu": "https://www.serietvu.link",
@@ -46,7 +47,6 @@
"findhost": {
"altadefinizioneclick": "https://altadefinizione-nuovo.click",
"animealtadefinizione": "https://www.animealtadefinizione.it",
"filmpertutti": "https://filmpertuttiii.nuovo.live",
"seriehd": "https://nuovoindirizzo.info/seriehd"
"filmpertutti": "https://filmpertuttiii.nuovo.live"
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
{
"id": "seriehd",
"name": "SerieHD",
"active": false,
"active": true,
"language": ["ita"],
"thumbnail": "seriehd.png",
"banner": "seriehd.png",
+3 -3
View File
@@ -5,10 +5,10 @@
from core import support
def findhost(url):
return support.match(url, patron=r'<h2[^>]+><a href="([^"]+)"').match
# def findhost(url):
# return support.match(url, patron=r'<h2[^>]+><a href="([^"]+)"').match
host = support.config.get_channel_url(findhost)
host = support.config.get_channel_url()
headers = [['Referer', host]]
+130 -7
View File
@@ -15,7 +15,7 @@ import math, traceback, re, os
from core import filetools, scraper, scrapertools, support, httptools, tmdb
from core.item import Item
from lib import generictools
from platformcode import config, logger, platformtools
from platformcode import config, dbconverter, logger, platformtools
from platformcode.autorenumber import RENUMBER
from core.videolibrarydb import videolibrarydb
@@ -265,9 +265,10 @@ def save_movie(item, silent=False):
if not silent:
p_dialog.update(100, item.contentTitle)
p_dialog.close()
# Update Kodi Library
from platformcode.dbconverter import add_video
add_video(movie_item)
if config.is_xbmc() and config.get_setting("videolibrary_kodi") and not item.not_add:
# Update Kodi Library
from platformcode.dbconverter import add_video
add_video(movie_item)
# if config.is_xbmc() and config.get_setting("videolibrary_kodi") and not silent and inserted:
# from platformcode.xbmc_videolibrary import update
# update(MOVIES_PATH)
@@ -429,7 +430,7 @@ def save_tvshow(item, episodelist, silent=False):
logger.debug()
inserted, overwritten, failed = save_episodes(tvshow_item, episodelist, extra_info, item.host, local_files, silent=silent)
videolibrarydb.close()
if config.is_xbmc() and config.get_setting("videolibrary_kodi") and not silent:# and inserted:
if config.is_xbmc() and config.get_setting("videolibrary_kodi") and not item.not_add:
from platformcode.dbconverter import add_video
add_video(tvshow_item)
@@ -682,7 +683,7 @@ def save_episodes(item, episodelist, extra_info, host, local_files, silent=False
def add_to_videolibrary(item, channel):
itemlist = getattr(channel, item.from_action)(item)
if itemlist and itemlist[0].contentType == 'episode':
return add_tvshow(item, itemlist)
return add_tvshow(item, itemlist=itemlist)
elif itemlist and itemlist[0].server:
return add_movie(item)
else:
@@ -1066,4 +1067,126 @@ def set_base_name(item, _id):
if config.get_setting("lowerize_title", "videolibrary"):
base_name = base_name.lower()
return '{} [{}]'.format(base_name, _id)
return '{} [{}]'.format(base_name, _id)
def restore_videolibrary():
movies = [x['item'] for x in dict(videolibrarydb['movie']).values()]
tvshows = [x['item'] for x in dict(videolibrarydb['tvshow']).values()]
total = len(movies) + len(tvshows)
progress = 0
dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Ripristino videoteca in corso')
try: os.mkdir(MOVIES_PATH)
except: pass
try: os.mkdir(TVSHOWS_PATH)
except: pass
for item in movies:
base_name = set_base_name(item, item.videolibrary_id)
path = filetools.join(MOVIES_PATH, base_name)
try: os.mkdir(path)
except: pass
nfo_path = filetools.join(base_name, "{}.nfo".format(base_name))
strm_path = filetools.join(base_name, "{}.strm".format(base_name))
nfo_exists = filetools.exists(filetools.join(MOVIES_PATH, nfo_path))
strm_exists = filetools.exists(filetools.join(MOVIES_PATH, strm_path))
local = True if 'local' in videolibrarydb['movie'][item.videolibrary_id]['channels'] else False
if not nfo_exists:
if not item.head_nfo: item.head_nfo = scraper.get_nfo(item)
filetools.write(filetools.join(MOVIES_PATH, item.nfo_path), item.head_nfo)
if not strm_exists and not local:
item_strm = Item(channel='videolibrary', action='play_from_library', strm_path=item.strm_path, contentType='movie', contentTitle=item.contentTitle, videolibrary_id=item.videolibrary_id)
filetools.write(filetools.join(MOVIES_PATH, item.strm_path), '{}?{}'.format(addon_name, item_strm.tourl()))
progress += 1
dialog.update(int(progress / total * 100))
for item in tvshows:
base_name = set_base_name(item, item.videolibrary_id)
path = filetools.join(TVSHOWS_PATH, base_name)
try: os.mkdir(path)
except: pass
nfo_path = filetools.join(base_name, "tvshow.nfo")
nfo_exists = filetools.exists(filetools.join(TVSHOWS_PATH, nfo_path))
if not nfo_exists:
if not item.head_nfo: item.head_nfo = scraper.get_nfo(item)
filetools.write(filetools.join(TVSHOWS_PATH, item.nfo_path), item.head_nfo)
episodes = [x['item'] for x in dict(videolibrarydb['episode'][item.videolibrary_id]).values()]
for e in episodes:
season_episode = '{}x{:02d}'.format(e.contentSeason, e.contentEpisodeNumber)
strm_path = filetools.join(item.base_name, "{}.strm".format(season_episode))
strm_exists = filetools.exists(filetools.join(MOVIES_PATH, strm_path))
local = True if 'local' in videolibrarydb['episode'][item.videolibrary_id][season_episode]['channels'] else False
if not strm_exists and not local:
logger.debug("Creating .strm: " + strm_path)
item_strm = Item(channel='videolibrary', action='play_from_library', strm_path=strm_path, contentType='episode', videolibrary_id=e.videolibrary_id, contentSeason = e.contentSeason, contentEpisodeNumber = e.contentEpisodeNumber,)
filetools.write(filetools.join(TVSHOWS_PATH, strm_path), '{}?{}'.format(addon_name, item_strm.tourl()))
progress += 1
dialog.update(int(progress / total * 100))
videolibrarydb.close()
dbconverter.save_all()
def convert_videolibrary():
import glob, xbmc
from platformcode import xbmc_videolibrary
from core import jsontools
dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
path_to_delete = []
film_lst = glob.glob(filetools.join(MOVIES_PATH, '*/*.json'))
tvshow_lst = glob.glob((filetools.join(TVSHOWS_PATH, '*/tvshow.nfo')))
total = len(film_lst) + len(tvshow_lst)
progress = 0
tvPath = filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'))
moviePath = filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_movies'))
# set local info only
xbmc_videolibrary.execute_sql_kodi('update path set strScraper="metadata.local", strSettings="" where strPath = "{}{}"'.format(tvPath, '/' if '/' in tvPath else '\\'))
xbmc_videolibrary.execute_sql_kodi('update path set strScraper="metadata.local", strSettings="" where strPath = "{}{}"'.format(moviePath, '/' if '/' in moviePath else '\\'))
for film in film_lst:
path_to_delete.append(filetools.dirname(film))
it = Item().fromjson(filetools.read(film))
it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'movie'}
tmdb.find_and_set_infoLabels(it)
it.no_reload = True
save_movie(it)
progress += 1
dialog.update(int(progress / total * 100))
for tvshow in tvshow_lst:
if not dialog:
dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
js = jsontools.load('\n'.join(filetools.read(tvshow).splitlines()[1:]))
channels_dict = js.get('library_urls')
if channels_dict:
for ch, url in channels_dict.items():
dir = filetools.listdir(xbmc.translatePath(filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'), js['path'])))
json_files = [f for f in dir if f.endswith('.json')]
if json_files:
path_to_delete.append(filetools.dirname(tvshow))
nfo, it = read_nfo(tvshow)
it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'tvshow'}
it.contentType = 'tvshow'
it.channel = ch
it.url = channels_dict[ch]
remove_host(it)
tmdb.find_and_set_infoLabels(it)
try: channel = __import__('channels.%s' % ch, fromlist=['channels.%s' % ch])
except: channel = __import__('specials.%s' % ch, fromlist=['specials.%s' % ch])
it.host = channel.host
it.url = channel.host + it.url
episodes = getattr(channel, 'episodios')(it)
for ep in episodes:
logger.debug('EPISODE URL', ep.url)
it.no_reload = True
save_tvshow(it, episodes, True)
progress += 1
dialog.update(int(progress / total * 100))
for path in path_to_delete:
filetools.rmdirtree(path, True)
dialog.close()
if path_to_delete:
dbconverter.save_all()
+24 -20
View File
@@ -14,6 +14,7 @@ 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
@@ -29,24 +30,23 @@ def save_all():
def reload():
movieid = get_id('idMovie', 'movie')
showid = get_id('idShow', 'tvshow')
payload = {"jsonrpc": "2.0",
"method": "VideoLibrary.Scan",
"id": 1}
if movieid > 0 and showid > 0:
xbmc.executebuiltin('ReloadSkin()')
else:
payload = {
"jsonrpc": "2.0",
"method": "VideoLibrary.Scan",
"directory": videolibrarytools.FOLDER_TVSHOWS,
"id": 1
}
get_data(payload)
payload = {
"jsonrpc": "2.0",
"method": "VideoLibrary.Scan",
"directory": videolibrarytools.FOLDER_MOVIES,
"id": 1
}
get_data(payload)
while xbmc.getCondVisibility('Library.IsScanningVideo()'): pass
payload["directory"] = videolibrarytools.FOLDER_TVSHOWS
get_data(payload)
while xbmc.getCondVisibility('Library.IsScanningVideo()'): pass
payload["directory"] = videolibrarytools.FOLDER_MOVIES
get_data(payload)
while xbmc.getCondVisibility('Library.IsScanningVideo()'): pass
xbmc.executebuiltin('ReloadSkin()')
def add_video(item):
@@ -223,7 +223,7 @@ class addMovie(object):
get_data(payload)
else:
xbmc.executebuiltin('ReloadSkin()')
conn.close()
conn.close()
def get_id(self):
Type = 'id' + self.item.contentType.replace('tv', '').capitalize()
@@ -243,7 +243,9 @@ class addMovie(object):
if records:
self.idParentPath = records[0][0]
else:
return
self.idParentPath = get_id('idPath', 'path')
sql = 'INSERT OR IGNORE INTO path (idPath, strPath, strContent, strScraper, noUpdate) VALUES ({}, "{}", "{}", "{}", {})'.format(self.idParentPath, self.parentPath, 'movies', 'meatadata.local', 0)
nun_records, records = execute_sql_kodi(sql, conn=conn)
sql = 'select idPath from path where (strPath = "{}") limit 1'.format(self.strPath)
nun_records, records = execute_sql_kodi(sql, conn=conn)
@@ -559,7 +561,9 @@ class addTvShow(object):
if records:
self.idParentPath = records[0][0]
else:
return
self.idParentPath = get_id('idPath', 'path')
sql = 'INSERT OR IGNORE INTO path (idPath, strPath, strContent, strScraper, noUpdate) VALUES ({}, "{}", "{}", "{}", {})'.format(self.idParentPath, self.parentPath, 'tvshows', 'meatadata.local', 0)
nun_records, records = execute_sql_kodi(sql, conn=conn)
sql = 'select idPath from path where (strPath = "{}") limit 1'.format(self.strPath)
nun_records, records = execute_sql_kodi(sql, conn=conn)
@@ -6167,6 +6167,14 @@ msgctxt "#70838"
msgid "There are no valid content for: %s"
msgstr ""
msgctxt "#70839"
msgid "Convert Videolibrary"
msgstr ""
msgctxt "#70840"
msgid "Restore Video Library from DB"
msgstr ""
# DNS start [ settings and declaration ]
msgctxt "#707401"
msgid "Enable DNS check alert"
@@ -6166,7 +6166,15 @@ msgstr "Abilita/Disabilita Canali"
msgctxt "#70838"
msgid "There are no valid content for: %s"
msgstr "Non ci sono contenti validi per: %s"
msgstr "Non ci sono contenuti validi per: %s"
msgctxt "#70839"
msgid "Convert Videolibrary"
msgstr "Converti Videoteca"
msgctxt "#70840"
msgid "Restore Video Library from DB"
msgstr "Ripristina Videoteca da DB"
# DNS start [ settings and declaration ]
msgctxt "#707401"
+2
View File
@@ -54,6 +54,8 @@
<setting id="vidolibrary_export" type="action" label="80000" action="RunPlugin(plugin://plugin.video.kod/?ew0KICAgICJhY3Rpb24iOiAiZXhwb3J0X3ZpZGVvbGlicmFyeSIsDQogICAgImNoYW5uZWwiOiAiYmFja3VwIg0KfQ==)"/>
<setting id="vidolibrary_import" type="action" label="80001" action="RunPlugin(plugin://plugin.video.kod/?ew0KICAgICJhY3Rpb24iOiAiaW1wb3J0X3ZpZGVvbGlicmFyeSIsDQogICAgImNoYW5uZWwiOiAiYmFja3VwIg0KfQ==)"/>
<setting id="vidolibrary_delete" type="action" label="80036" action="RunPlugin(plugin://plugin.video.kod/?ew0KICAgICJhY3Rpb24iOiAiZGVsZXRlX3ZpZGVvbGlicmFyeSIsDQogICAgImNoYW5uZWwiOiAidmlkZW9saWJyYXJ5Ig0KfQ==)"/>
<setting id="vidolibrary_convert" type="action" label="70839" action="RunPlugin(plugin://plugin.video.kod/?ew0KICAgICJhY3Rpb24iOiAiY29udmVydF92aWRlb2xpYnJhcnkiLA0KICAgICJjaGFubmVsIjogInZpZGVvbGlicmFyeSINCn0=)"/>
<setting id="vidolibrary_restore" type="action" label="70840" action="RunPlugin(plugin://plugin.video.kod/?ew0KICAgICJhY3Rpb24iOiAicmVzdG9yZV92aWRlb2xpYnJhcnkiLA0KICAgICJjaGFubmVsIjogInZpZGVvbGlicmFyeSINCn0=)"/>
</category>
<!-- Channels -->
+57 -56
View File
@@ -200,65 +200,66 @@ if __name__ == "__main__":
config.get_setting('folder_tvshows')) +
'/" and strScraper<>"metadata.local"')
if nun_records:
dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
path_to_delete = []
film_lst = glob.glob(xbmc.translatePath(
filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_movies'),
'*/*.json')))
tvshow_lst = glob.glob(xbmc.translatePath(
filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'),
'*/tvshow.nfo')))
total = len(film_lst) + len(tvshow_lst)
progress = 0
videolibrarytools.convert_videolibrary()
# dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
# path_to_delete = []
# film_lst = glob.glob(xbmc.translatePath(
# filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_movies'),
# '*/*.json')))
# tvshow_lst = glob.glob(xbmc.translatePath(
# filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'),
# '*/tvshow.nfo')))
# total = len(film_lst) + len(tvshow_lst)
# progress = 0
# set local info only
xbmc_videolibrary.execute_sql_kodi(
'update path set strScraper="metadata.local", strSettings="" where strPath = "' +
filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows')) + '/"')
xbmc_videolibrary.execute_sql_kodi(
'update path set strScraper="metadata.local", strSettings="" where strPath = "' +
filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_movies')) + '/"')
# # set local info only
# xbmc_videolibrary.execute_sql_kodi(
# 'update path set strScraper="metadata.local", strSettings="" where strPath = "' +
# filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows')) + '/"')
# xbmc_videolibrary.execute_sql_kodi(
# 'update path set strScraper="metadata.local", strSettings="" where strPath = "' +
# filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_movies')) + '/"')
for film in film_lst:
path_to_delete.append(filetools.dirname(film))
it = Item().fromjson(filetools.read(film))
it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'movie'}
tmdb.find_and_set_infoLabels(it)
videolibrarytools.save_movie(it)
progress += 1
dialog.update(int(progress / total * 100))
for tvshow in tvshow_lst:
if not dialog:
dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
js = jsontools.load('\n'.join(filetools.read(tvshow).splitlines()[1:]))
channels_dict = js.get('library_urls')
if channels_dict:
for ch, url in channels_dict.items():
dir = filetools.listdir(xbmc.translatePath(filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'), js['path'])))
json_files = [f for f in dir if f.endswith('.json')]
if json_files:
path_to_delete.append(filetools.dirname(tvshow))
nfo, it = videolibrarytools.read_nfo(tvshow)
it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'tvshow'}
it.contentType = 'tvshow'
it.channel = ch
it.url = channels_dict[ch]
tmdb.find_and_set_infoLabels(it)
try:
channel = __import__('channels.%s' % ch, fromlist=['channels.%s' % ch])
except:
channel = __import__('specials.%s' % ch, fromlist=['specials.%s' % ch])
it.host = channel.host
episodes = getattr(channel, 'episodios')(it)
for ep in episodes:
logger.debug('EPISODE URL',ep.url)
# for film in film_lst:
# path_to_delete.append(filetools.dirname(film))
# it = Item().fromjson(filetools.read(film))
# it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'movie'}
# tmdb.find_and_set_infoLabels(it)
# videolibrarytools.save_movie(it)
# progress += 1
# dialog.update(int(progress / total * 100))
# for tvshow in tvshow_lst:
# if not dialog:
# dialog = platformtools.dialog_progress(config.get_localized_string(20000), 'Conversione videoteca in corso')
# js = jsontools.load('\n'.join(filetools.read(tvshow).splitlines()[1:]))
# channels_dict = js.get('library_urls')
# if channels_dict:
# for ch, url in channels_dict.items():
# dir = filetools.listdir(xbmc.translatePath(filetools.join(config.get_setting('videolibrarypath'), config.get_setting('folder_tvshows'), js['path'])))
# json_files = [f for f in dir if f.endswith('.json')]
# if json_files:
# path_to_delete.append(filetools.dirname(tvshow))
# nfo, it = videolibrarytools.read_nfo(tvshow)
# it.infoLabels = {'tmdb_id': it.infoLabels['tmdb_id'], 'mediatype':'tvshow'}
# it.contentType = 'tvshow'
# it.channel = ch
# it.url = channels_dict[ch]
# tmdb.find_and_set_infoLabels(it)
# try:
# channel = __import__('channels.%s' % ch, fromlist=['channels.%s' % ch])
# except:
# channel = __import__('specials.%s' % ch, fromlist=['specials.%s' % ch])
# it.host = channel.host
# episodes = getattr(channel, 'episodios')(it)
# for ep in episodes:
# logger.debug('EPISODE URL',ep.url)
videolibrarytools.save_tvshow(it, episodes, True)
progress += 1
dialog.update(int(progress / total * 100))
for path in path_to_delete:
filetools.rmdirtree(path, True)
dialog.close()
# videolibrarytools.save_tvshow(it, episodes, True)
# progress += 1
# dialog.update(int(progress / total * 100))
# for path in path_to_delete:
# filetools.rmdirtree(path, True)
# dialog.close()
if config.get_setting('autostart'):
xbmc.executebuiltin('RunAddon(plugin.video.' + config.PLUGIN_NAME + ')')
+5
View File
@@ -1325,3 +1325,8 @@ def get_results(nfo_path, root, Type, local=False):
# platformtools.itemlist_refresh()
def convert_videolibrary(item):
videolibrarytools.convert_videolibrary()
def restore_videolibrary(item):
videolibrarytools.restore_videolibrary()