- aggiunto nuovo canale: guardaserie.cam
- autoplay migliorato, ora i settaggi sono globali e non più per canale
- adesso in onda riscritto, ora usa EPG (ringraziamo epg-guide.com)
- Riprendi la visione di un film o episodio da server diversi (solo videoteca)
- fix e ottimizzazioni varie
This commit is contained in:
marco
2020-07-03 23:08:20 +02:00
parent 8b78c88e41
commit 0932a1969f
296 changed files with 3205 additions and 8075 deletions
+177 -61
View File
@@ -5,7 +5,7 @@
from future import standard_library
standard_library.install_aliases()
#from builtins import str
import sys, os, threading, time, re, math, xbmc
import sys, os, threading, time, re, math, xbmc, xbmcgui
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
@@ -15,73 +15,84 @@ from core import scrapertools
from xml.dom import minidom
def mark_auto_as_watched(item):
def mark_as_watched_subThread(item):
def mark_auto_as_watched(item, nfo_path=None, head_nfo=None, item_nfo=None):
def mark_as_watched_subThread(item, nfo_path, head_nfo, item_nfo):
logger.info()
# logger.debug("item:\n" + item.tostring('\n'))
# if nfo and strm_path not exist
if not item.nfo:
if item.contentType == 'movie':
vl = xbmc.translatePath(filetools.join(config.get_setting("videolibrarypath"), config.get_setting("folder_movies")))
path = '%s [%s]' % (item.contentTitle, item.infoLabels['IMDBNumber'])
item.nfo = filetools.join(vl, path, path + '.nfo')
item.strm_path = filetools.join(path, item.contentTitle + '.strm')
else:
vl = xbmc.translatePath(filetools.join(config.get_setting("videolibrarypath"), config.get_setting("folder_tvshows")))
path = '%s [%s]' % (item.contentSerieName, item.infoLabels['IMDBNumber'])
item.nfo = filetools.join(vl, path, 'tvshow.nfo')
if item.contentSeason and item.contentEpisodeNumber:
title = str(item.contentSeason) + 'x' + str(item.contentEpisodeNumber).zfill(2)
else:
season, episode = scrapertools.find_single_match(item.title, r'(\d+)x(\d+)')
title = season + 'x' + episode.zfill(2)
item.strm_path = filetools.join(path, title + '.strm')
condicion = config.get_setting("watched_setting", "videolibrary")
time_limit = time.time() + 30
while not platformtools.is_playing() and time.time() < time_limit:
time.sleep(1)
sync_with_trakt = False
marked = False
next_episode = None
show_server = True
percentage = float(config.get_setting("watched_setting")) / 100
time_from_end = config.get_setting('next_ep_seconds')
if item.contentType != 'movie' and config.get_setting('next_ep'):
next_dialogs = ['NextDialog.xml', 'NextDialogExtended.xml', 'NextDialogCompact.xml']
next_ep_type = config.get_setting('next_ep_type')
ND = next_dialogs[next_ep_type]
next_episode = next_ep(item)
while platformtools.is_playing():
tiempo_actual = xbmc.Player().getTime()
totaltime = xbmc.Player().getTotalTime()
actual_time = xbmc.Player().getTime()
total_time = xbmc.Player().getTotalTime()
if item_nfo.played_time and item_nfo.played_time > actual_time > 1:
xbmc.Player().seekTime(item_nfo.played_time)
item_nfo.played_time = 0 # Fix for Slow Devices
mark_time = 0
if condicion == 0: # '5 minutos'
mark_time = 300
elif condicion == 1: # '30%'
mark_time = totaltime * 0.3
elif condicion == 2: # '50%'
mark_time = totaltime * 0.5
elif condicion == 3: # '80%'
mark_time = totaltime * 0.8
elif condicion == 4: # '0 seg'
mark_time = -1
mark_time = total_time * percentage
difference = total_time - actual_time
# logger.debug(str(tiempo_actual))
# logger.debug(str(mark_time))
if tiempo_actual > mark_time:
# Mark as Watched
if actual_time > mark_time and not marked:
logger.debug("Marked as Watched")
item.playcount = 1
sync_with_trakt = True
marked = True
show_server = False
from specials import videolibrary
videolibrary.mark_content_as_watched2(item)
break
if not next_episode:
break
time.sleep(5)
# check for next Episode
if next_episode and marked and time_from_end >= difference:
nextdialog = NextDialog(ND, config.get_runtime_path())
nextdialog.show()
while platformtools.is_playing() and not nextdialog.is_exit():
xbmc.sleep(100)
if nextdialog.continuewatching:
next_episode.next_ep = True
xbmc.Player().stop()
nextdialog.close()
break
xbmc.sleep(1000)
# Set played time
item_nfo.played_time = int(actual_time) if not marked and actual_time > 120 else 0
filetools.write(nfo_path, head_nfo + item_nfo.tojson())
# Silent sync with Trakt
if sync_with_trakt and config.get_setting("trakt_sync"):
sync_trakt_kodi()
if marked and config.get_setting("trakt_sync"): sync_trakt_kodi()
# logger.debug("Fin del hilo")
while platformtools.is_playing():
xbmc.sleep(100)
if not show_server and item.play_from != 'window':
xbmc.sleep(700)
xbmc.executebuiltin('Action(Back)')
xbmc.sleep(500)
if next_episode and next_episode.next_ep:
from platformcode.launcher import play_from_library
return play_from_library(next_episode)
# If it is configured to mark as seen
if config.get_setting("mark_as_watched", "videolibrary"):
threading.Thread(target=mark_as_watched_subThread, args=[item]).start()
threading.Thread(target=mark_as_watched_subThread, args=[item, nfo_path, head_nfo, item_nfo]).start()
def sync_trakt_addon(path_folder):
@@ -110,7 +121,7 @@ def sync_trakt_addon(path_folder):
shows = list(shows.items())
# we get the series id to compare
_id = re.findall("\[(.*?)\]", path_folder, flags=re.DOTALL)[0]
_id = re.findall(r"\[(.*?)\]", path_folder, flags=re.DOTALL)[0]
logger.debug("the id is %s" % _id)
if "tt" in _id:
@@ -152,7 +163,7 @@ def sync_trakt_addon(path_folder):
logger.debug("dict_trakt_show %s " % dict_trakt_show)
# we get the keys that are episodes
regex_epi = re.compile('\d+x\d+')
regex_epi = re.compile(r'\d+x\d+')
keys_episodes = [key for key in serie.library_playcounts if regex_epi.match(key)]
# we get the keys that are seasons
keys_seasons = [key for key in serie.library_playcounts if 'season ' in key]
@@ -210,14 +221,14 @@ def sync_trakt_kodi(silent=True):
# So that the synchronization is not silent it is worth with silent = False
if xbmc.getCondVisibility('System.HasAddon("script.trakt")'):
notificacion = True
if (not config.get_setting("sync_trakt_notification", "videolibrary") and platformtools.is_playing()):
if not config.get_setting("sync_trakt_notification", "videolibrary") and platformtools.is_playing():
notificacion = False
xbmc.executebuiltin('RunScript(script.trakt,action=sync,silent=%s)' % silent)
logger.info("Synchronization with Trakt started")
if notificacion:
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60045), time=2000)
platformtools.dialog_notification(config.get_localized_string(20000), config.get_localized_string(60045), sound=False, time=2000)
def mark_content_as_watched_on_kodi(item, value=1):
@@ -276,7 +287,6 @@ def mark_content_as_watched_on_kodi(item, value=1):
path = filetools.join(tail, filename)
for d in data['result']['episodes']:
if d['file'].replace("/", "\\").endswith(path.replace("/", "\\")):
# logger.debug("I mark the episode as seen")
episodeid = d['episodeid']
@@ -376,7 +386,7 @@ def mark_content_as_watched_on_kod(path):
path1 = path.replace("\\\\", "\\") # Windows format
if not path2:
path2 = path1.replace("\\", "/") # Format no Windows
nfo_name = scrapertools.find_single_match(path2, '\]\/(.*?)$') # I build the name of the .nfo
nfo_name = scrapertools.find_single_match(path2, r'\]\/(.*?)$') # I build the name of the .nfo
path1 = path1.replace(nfo_name, '') # for SQL I just need the folder
path2 = path2.replace(nfo_name, '') # for SQL I just need the folder
path2 = filetools.remove_smb_credential(path2) # If the file is on an SMB server, we remove the credentials
@@ -394,7 +404,7 @@ def mark_content_as_watched_on_kod(path):
if contentType == "episode_view":
title_plain = title.replace('.strm', '') # If it is Serial, we remove the suffix .strm
else:
title_plain = scrapertools.find_single_match(item.strm_path, '.(.*?\s\[.*?\])') # if it's a movie, we remove the title
title_plain = scrapertools.find_single_match(item.strm_path, r'.(.*?\s\[.*?\])') # if it's a movie, we remove the title
if playCount is None or playCount == 0: # not yet seen, we set it to 0
playCount_final = 0
elif playCount >= 1:
@@ -409,7 +419,7 @@ def mark_content_as_watched_on_kod(path):
if item.infoLabels['mediatype'] == "tvshow": # We update the Season and Series playCounts
for season in item.library_playcounts:
if "season" in season: # we look for the tags "season" inside playCounts
season_num = int(scrapertools.find_single_match(season, 'season (\d+)')) # we save the season number
season_num = int(scrapertools.find_single_match(season, r'season (\d+)')) # we save the season number
item = videolibrary.check_season_playcount(item, season_num) # We call the method that updates Temps. and series
filetools.write(path, head_nfo + item.tojson())
@@ -497,7 +507,7 @@ def update(folder_content=config.get_setting("folder_tvshows"), folder=""):
# update_path = filetools.join(videolibrarypath, folder_content, folder) + "/" # Encoder problems in "folder"
update_path = filetools.join(videolibrarypath, folder_content, ' ').rstrip()
if videolibrarypath.startswith("special:") or not scrapertools.find_single_match(update_path, '(^\w+:\/\/)'):
if videolibrarypath.startswith("special:") or not scrapertools.find_single_match(update_path, r'(^\w+:\/\/)'):
payload["params"] = {"directory": update_path}
while xbmc.getCondVisibility('Library.IsScanningVideo()'):
@@ -539,7 +549,7 @@ def set_content(content_type, silent=False, custom=False):
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))
install = platformtools.dialog_yesno(config.get_localized_string(60046),'')
else:
install = True
@@ -563,7 +573,7 @@ def set_content(content_type, silent=False, custom=False):
continuar = False
if not silent:
# Ask if we want to install metadata.universal
install = platformtools.dialog_yesno(config.get_localized_string(70095))
install = platformtools.dialog_yesno(config.get_localized_string(70095),'')
else:
install = True
@@ -593,7 +603,7 @@ def set_content(content_type, silent=False, custom=False):
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))
install = platformtools.dialog_yesno(config.get_localized_string(60048),'')
else:
install = True
@@ -617,7 +627,7 @@ def set_content(content_type, silent=False, custom=False):
continuar = False
if not silent:
# Ask if we want to install metadata.tvshows.themoviedb.org
install = platformtools.dialog_yesno(config.get_localized_string(60050))
install = platformtools.dialog_yesno(config.get_localized_string(60050),'')
else:
install = True
@@ -651,7 +661,7 @@ def set_content(content_type, silent=False, custom=False):
if sql_videolibrarypath.startswith("special://"):
sql_videolibrarypath = sql_videolibrarypath.replace('/profile/', '/%/').replace('/home/userdata/', '/%/')
sep = '/'
elif scrapertools.find_single_match(sql_videolibrarypath, '(^\w+:\/\/)'):
elif scrapertools.find_single_match(sql_videolibrarypath, r'(^\w+:\/\/)'):
sep = '/'
else:
sep = os.sep
@@ -1228,4 +1238,110 @@ def ask_set_content(silent=False):
# configuration from the settings menu
else:
platformtools.dialog_ok(config.get_localized_string(80026), config.get_localized_string(80023))
do_config(True)
do_config(True)
def next_ep(item):
from core.item import Item
logger.info()
item.next_ep = False
# check if next file exist
current_filename = filetools.basename(item.strm_path)
base_path = filetools.basename(filetools.dirname(item.strm_path))
path = filetools.join(config.get_videolibrary_path(), config.get_setting("folder_tvshows"),base_path)
fileList = []
for file in filetools.listdir(path):
if file.endswith('.strm'):
fileList.append(file)
fileList.sort()
nextIndex = fileList.index(current_filename) + 1
if nextIndex == 0 or nextIndex == len(fileList): next_file = None
else: next_file = fileList[nextIndex]
logger.info('Next File:' + str(next_file))
# start next episode window afther x time
if next_file:
season_ep = next_file.split('.')[0]
season = season_ep.split('x')[0]
episode = season_ep.split('x')[1]
next_ep = '%sx%s' % (season, episode)
item = Item(
action= 'play_from_library',
channel= 'videolibrary',
contentEpisodeNumber= episode,
contentSeason= season,
contentTitle= next_ep,
contentType= 'episode',
infoLabels= {'episode': episode, 'mediatype': 'episode', 'season': season, 'title': next_ep},
strm_path= filetools.join(base_path, next_file),
play_from = item.play_from)
global INFO
INFO = filetools.join(path, next_file.replace("strm", "nfo"))
else:
item=None
return item
class NextDialog(xbmcgui.WindowXMLDialog):
item = None
cancel = False
EXIT = False
continuewatching = True
def __init__(self, *args, **kwargs):
self.action_exitkeys_id = [xbmcgui.ACTION_STOP, xbmcgui.ACTION_BACKSPACE, xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK]
self.progress_control = None
# set info
f = filetools.file_open(INFO, 'r')
full_info = f.read().split('\n')
full_info = full_info[1:]
f.close()
full_info = "".join(full_info)
info = jsontools.load(full_info)
if "thumbnail" in info:
img = info["thumbnail"]
else:
img = filetools.join(config.get_runtime_path(), "resources", "noimage.png")
self.setProperty("next_img", img)
info = info["infoLabels"]
self.setProperty("title", info["tvshowtitle"])
self.setProperty("ep_title", "%dx%02d - %s" % (info["season"], info["episode"], info["title"]))
def set_exit(self, EXIT):
self.EXIT = EXIT
def set_continue_watching(self, continuewatching):
self.continuewatching = continuewatching
def is_exit(self):
return self.EXIT
def onFocus(self, controlId):
pass
def doAction(self):
pass
def closeDialog(self):
self.close()
def onClick(self, controlId):
if controlId == 3012: # Still watching
self.set_exit(True)
self.set_continue_watching(True)
self.close()
elif controlId == 3013: # Cancel
self.set_exit(True)
self.set_continue_watching(False)
self.close()
def onAction(self, action):
if action in self.action_exitkeys_id:
self.set_exit(True)
self.set_continue_watching(False)
self.close()