Modalità di riproduzione "segnalibro" via database

This commit is contained in:
Alhaziel01
2020-12-07 19:35:58 +01:00
parent 030ea82231
commit 702d89ff51
7 changed files with 147 additions and 67 deletions
+1 -1
View File
@@ -67,7 +67,7 @@ def start(itemlist, item):
# Enable the "View in high quality" action (if the server returns more than one quality, eg gdrive) # Enable the "View in high quality" action (if the server returns more than one quality, eg gdrive)
if not user_config_setting_action: config.set_setting("default_action", 2) if not user_config_setting_action: config.set_setting("default_action", 2)
if user_config_setting_player != 0: config.set_setting("player_mode", 0) # if user_config_setting_player != 0: config.set_setting("player_mode", 0)
# Priorities when ordering itemlist: # Priorities when ordering itemlist:
# 0: Servers and qualities # 0: Servers and qualities
+1
View File
@@ -1165,6 +1165,7 @@ def server(item, data='', itemlist=[], headers='', AutoPlay=True, CheckLinks=Tru
videoitem.quality = quality videoitem.quality = quality
videoitem.referer = item.url videoitem.referer = item.url
videoitem.action = "play" videoitem.action = "play"
videoitem.infoLabels = item.infoLabels
# videoitem.nfo = item.nfo # videoitem.nfo = item.nfo
# videoitem.strm_path = item.strm_path # videoitem.strm_path = item.strm_path
return videoitem return videoitem
+2 -1
View File
@@ -355,8 +355,10 @@ class SearchWindow(xbmcgui.WindowXML):
items = [] items = []
for result in channelResults: for result in channelResults:
if result: items.append(self.makeItem(result)) if result: items.append(self.makeItem(result))
pos = self.RESULTS.getSelectedPosition()
self.RESULTS.reset() self.RESULTS.reset()
self.RESULTS.addItems(items) self.RESULTS.addItems(items)
self.RESULTS.selectItem(pos)
if results: if results:
resultsList = '' resultsList = ''
channelParams = channeltools.get_channel_parameters(channel) channelParams = channeltools.get_channel_parameters(channel)
@@ -648,7 +650,6 @@ class SearchWindow(xbmcgui.WindowXML):
elif control_id in [SERVERLIST]: elif control_id in [SERVERLIST]:
server = Item().fromurl(self.getControl(control_id).getSelectedItem().getProperty('item')) server = Item().fromurl(self.getControl(control_id).getSelectedItem().getProperty('item'))
server.player_mode = 0
return run(server) return run(server)
def Back(self): def Back(self):
+12 -5
View File
@@ -489,17 +489,24 @@ def play_from_library(item):
item.play_from = 'window' item.play_from = 'window'
itemlist = videolibrary.findvideos(item) itemlist = videolibrary.findvideos(item)
p_dialog.update(100, ''); sleep(0.5); p_dialog.close() p_dialog.update(100, ''); sleep(0.5); p_dialog.close()
# while platformtools.is_playing(): # Conventional window while platformtools.is_playing(): sleep(1)
# sleep(100) # from core.support import dbg;dbg()
play_time = platformtools.resume_playback(item, True) if item.contentType == 'movie': nfo_path = item.nfo
if not play_time and config.get_setting('autoplay'): 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)
played_time = platformtools.get_played_time(item_nfo)
else: played_time = 0
if not played_time and config.get_setting('autoplay'):
return return
# The number of links to show is limited # The number of links to show is limited
if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist) if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist)
# The list of links is slightly "cleaned" # The list of links is slightly "cleaned"
if config.get_setting("replace_VD", "videolibrary") == 1: itemlist = reorder_itemlist(itemlist) if config.get_setting("replace_VD", "videolibrary") == 1: itemlist = reorder_itemlist(itemlist)
from core.support import dbg;dbg()
if len(itemlist) > 0: if len(itemlist) > 0:
while not xbmc.Monitor().abortRequested(): while not xbmc.Monitor().abortRequested():
# The user chooses the mirror # The user chooses the mirror
+116 -45
View File
@@ -679,9 +679,7 @@ def play_video(item, strm=False, force_direct=False, autoplay=False):
if force_direct: item.play_from = 'window' if force_direct: item.play_from = 'window'
set_player(item, xlistitem, mediaurl, view, strm)
item, nfo_path, head_nfo, item_nfo = resume_playback(item)
set_player(item, xlistitem, mediaurl, view, strm, nfo_path, head_nfo, item_nfo)
def stop_video(): def stop_video():
@@ -1009,7 +1007,7 @@ def get_video_seleccionado(item, seleccion, video_urls):
return mediaurl, view, mpd return mediaurl, view, mpd
def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=None, item_nfo=None): def set_player(item, xlistitem, mediaurl, view, strm):
logger.debug() logger.debug()
# logger.debug("item:\n" + item.tostring('\n')) # logger.debug("item:\n" + item.tostring('\n'))
# Moved del conector "torrent" here # Moved del conector "torrent" here
@@ -1028,7 +1026,7 @@ def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=No
player_mode = item.player_mode player_mode = item.player_mode
else: else:
player_mode = config.get_setting("player_mode") player_mode = config.get_setting("player_mode")
if (player_mode == 3 and mediaurl.startswith("rtmp")) or item.play_from == 'window' or item.nfo: player_mode = 0 if (player_mode == 3 and mediaurl.startswith("rtmp")): player_mode = 0
elif "megacrypter.com" in mediaurl: player_mode = 3 elif "megacrypter.com" in mediaurl: player_mode = 3
logger.info("mediaurl=" + mediaurl) logger.info("mediaurl=" + mediaurl)
@@ -1045,11 +1043,26 @@ def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=No
from core import trakt_tools from core import trakt_tools
trakt_tools.wait_for_update_trakt() trakt_tools.wait_for_update_trakt()
# elif player_mode == 1:
# logger.info('Player Mode: setResolvedUrl')
# xlistitem.setPath(mediaurl)
# xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xlistitem)
# # xbmc.sleep(2500)
elif player_mode == 1: elif player_mode == 1:
logger.info('Player Mode: setResolvedUrl') logger.info('Player Mode: Bookmark')
xlistitem.setPath(mediaurl) # Add the listitem to a playlist
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xlistitem) playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
# xbmc.sleep(2500) playlist.clear()
playlist.add(mediaurl, xlistitem)
played_time = resume_playback(get_played_time(item))
# Reproduce
xbmc_player.play(playlist, xlistitem)
viewed(item, played_time)
if config.get_setting('trakt_sync'):
from core import trakt_tools
trakt_tools.wait_for_update_trakt()
elif player_mode == 2: elif player_mode == 2:
logger.info('Player Mode: Built-In') logger.info('Player Mode: Built-In')
@@ -1070,7 +1083,7 @@ def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=No
# if it is a video library file send to mark as seen # if it is a video library file send to mark as seen
if strm or item.strm_path: if strm or item.strm_path:
from platformcode import xbmc_videolibrary from platformcode import xbmc_videolibrary
xbmc_videolibrary.mark_auto_as_watched(item, nfo_path, head_nfo, item_nfo) xbmc_videolibrary.mark_auto_as_watched(item)
# for cases where the audio playback window appears in place of the video one # for cases where the audio playback window appears in place of the video one
if item.focusOnVideoPlayer: if item.focusOnVideoPlayer:
@@ -1079,6 +1092,24 @@ def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=No
xbmc.sleep(500) xbmc.sleep(500)
xbmcgui.Window(12005).show() xbmcgui.Window(12005).show()
def viewed(item, played_time):
from core import filetools, jsontools
def viewedThread(item):
while is_playing():
total_time = xbmc.Player().getTotalTime()
actual_time = xbmc.Player().getTime()
if played_time and xbmcgui.getCurrentWindowId() == 12005 and actual_time < played_time:
xbmc.Player().seekTime(played_time)
xbmc.sleep(500)
if 120 < actual_time < (total_time / 100) * 80:
item.played_time = actual_time
else: item.played_time = 0
set_played_time(item)
from threading import Thread
Thread(target=viewedThread, args=(item,)).start()
def torrent_client_installed(show_tuple=False): def torrent_client_installed(show_tuple=False):
# External plugins found in servers / torrent.json node clients # External plugins found in servers / torrent.json node clients
@@ -1136,7 +1167,7 @@ def play_torrent(item, xlistitem, mediaurl):
time.sleep(3) time.sleep(3)
def resume_playback(item, return_played_time=False): def resume_playback(played_time):
class ResumePlayback(xbmcgui.WindowXMLDialog): class ResumePlayback(xbmcgui.WindowXMLDialog):
Close = False Close = False
Resume = False Resume = False
@@ -1144,8 +1175,8 @@ def resume_playback(item, return_played_time=False):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.action_exitkeys_id = [xbmcgui.ACTION_BACKSPACE, xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK] self.action_exitkeys_id = [xbmcgui.ACTION_BACKSPACE, xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK]
self.progress_control = None self.progress_control = None
self.item = kwargs.get('item') played_time = kwargs.get('played_time')
m, s = divmod(float(self.item.played_time), 60) m, s = divmod(played_time, 60)
h, m = divmod(m, 60) h, m = divmod(m, 60)
self.setProperty("time", '%02d:%02d:%02d' % (h, m, s)) self.setProperty("time", '%02d:%02d:%02d' % (h, m, s))
@@ -1168,38 +1199,16 @@ def resume_playback(item, return_played_time=False):
if action in self.action_exitkeys_id: if action in self.action_exitkeys_id:
self.set_values(False) self.set_values(False)
self.close() self.close()
if played_time:
Dialog = ResumePlayback('ResumePlayback.xml', config.get_runtime_path(), played_time=played_time)
from core import videolibrarytools, filetools Dialog.show()
t = 0
# Read NFO FILE while not Dialog.is_close() and t < 100:
if item.contentType == 'movie': t += 1
nfo_path = item.nfo xbmc.sleep(100)
else: if not Dialog.Resume: played_time = 0
nfo_path = item.strm_path.replace('strm','nfo') else: played_time = 0
return played_time
if filetools.isfile(nfo_path):
head_nfo, item_nfo = videolibrarytools.read_nfo(nfo_path)
if return_played_time:
return item_nfo.played_time
# Show Window
elif (config.get_setting("player_mode") not in [3] or item.play_from == 'window') and item_nfo.played_time and item_nfo.played_time >= 120:
Dialog = ResumePlayback('ResumePlayback.xml', config.get_runtime_path(), item=item_nfo)
Dialog.show()
t = 0
while not Dialog.is_close() and t < 100:
t += 1
xbmc.sleep(100)
if not Dialog.Resume: item_nfo.played_time = 0
else:
item_nfo.played_time = 0
return item, nfo_path, head_nfo, item_nfo
else:
item.nfo = item.strm_path = ""
return item, None, None, None
##### INPUTSTREM ##### ##### INPUTSTREM #####
@@ -1396,3 +1405,65 @@ def get_platform():
ret["arch"] = "arm" ret["arch"] = "arm"
return ret return ret
def get_played_time(item):
import sqlite3
from core import filetools
db_name = filetools.join(config.get_data_path(), "kod_db.sqlite")
ID = item.infoLabels['tmdb_id']
conn = sqlite3.connect(db_name, timeout=15)
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS viewed (tmdb_id TEXT, season INT, episode INT, played_time REAL)')
conn.commit()
if ID:
if item.contentType == 'movie': c.execute("SELECT played_time FROM viewed WHERE tmdb_id=?", (ID,))
elif 'season' in item.infoLabels:
S = item.infoLabels['season']
E = item.infoLabels['episode']
c.execute("SELECT played_time FROM viewed WHERE tmdb_id=? AND season=? AND episode=?", (ID, S, E))
elif 'episode' in item.infoLabels:
E = item.infoLabels['episode']
c.execute("SELECT played_time FROM viewed WHERE tmdb_id=? AND episode=?", (ID, E))
result = c.fetchone()
if not result: played_time = 0
else: played_time = result[0]
else: played_time = 0
conn.close()
return played_time
def set_played_time(item):
import sqlite3
from core import filetools
ID = item.infoLabels['tmdb_id']
played_time = item.played_time
db_name = filetools.join(config.get_data_path(), "kod_db.sqlite")
conn = sqlite3.connect(db_name, timeout=15)
c = conn.cursor()
if item.contentType == 'movie':
c.execute("SELECT played_time FROM viewed WHERE tmdb_id=?", (ID,))
result = c.fetchone()
if result:
if played_time > 0: c.execute("UPDATE viewed SET played_time=? WHERE tmdb_id=?", (item.played_time, ID))
else: c.execute("DELETE from viewed WHERE tmdb_id=?", (ID,))
else: c.execute("INSERT INTO viewed (tmdb_id, played_time) VALUES (?, ?)", (ID, item.played_time))
elif 'season' in item.infoLabels:
S = item.infoLabels['season']
E = item.infoLabels['episode']
c.execute("SELECT played_time FROM viewed WHERE tmdb_id=? AND season = ? AND episode=?", (ID, S, E))
result = c.fetchone()
if result:
if played_time > 0: c.execute("UPDATE viewed SET played_time=? WHERE tmdb_id=? AND season=? AND episode=?", (item.played_time, ID, S, E))
else: c.execute("DELETE from viewed WHERE tmdb_id=? AND season=? AND episode=?", (ID, S, E))
else: c.execute("INSERT INTO viewed (tmdb_id, season, episode, played_time) VALUES (?, ?, ?, ?)", (ID, S, E, item.played_time))
elif 'episode' in item.infoLabels:
E = item.infoLabels['episode']
c.execute("SELECT played_time FROM viewed WHERE tmdb_id=? AND episode=?", (ID, E))
result = c.fetchone()
if result:
if played_time > 0: c.execute("UPDATE viewed SET played_time=? WHERE tmdb_id=? AND episode=?", (item.played_time, ID, E))
else: c.execute("DELETE from viewed WHERE tmdb_id=? AND episode=?", (ID, E))
else: c.execute("INSERT INTO viewed (tmdb_id, episode, played_time) VALUES (?, ?, ?)", (ID, E, item.played_time))
conn.commit()
conn.close()
+14 -15
View File
@@ -20,8 +20,8 @@ from core import scrapertools
from xml.dom import minidom from xml.dom import minidom
def mark_auto_as_watched(item, nfo_path=None, head_nfo=None, item_nfo=None): def mark_auto_as_watched(item):
def mark_as_watched_subThread(item, nfo_path, head_nfo, item_nfo): def mark_as_watched_subThread(item):
logger.debug() logger.debug()
# logger.debug("item:\n" + item.tostring('\n')) # logger.debug("item:\n" + item.tostring('\n'))
@@ -44,9 +44,9 @@ def mark_auto_as_watched(item, nfo_path=None, head_nfo=None, item_nfo=None):
while platformtools.is_playing(): while platformtools.is_playing():
actual_time = xbmc.Player().getTime() actual_time = xbmc.Player().getTime()
total_time = xbmc.Player().getTotalTime() total_time = xbmc.Player().getTotalTime()
if item_nfo.played_time and xbmcgui.getCurrentWindowId() == 12005: # if item_nfo.played_time and xbmcgui.getCurrentWindowId() == 12005:
xbmc.Player().seekTime(item_nfo.played_time) # xbmc.Player().seekTime(item_nfo.played_time)
item_nfo.played_time = 0 # Fix for Slow Devices # item_nfo.played_time = 0 # Fix for Slow Devices
mark_time = total_time * percentage mark_time = total_time * percentage
difference = total_time - actual_time difference = total_time - actual_time
@@ -75,9 +75,9 @@ def mark_auto_as_watched(item, nfo_path=None, head_nfo=None, item_nfo=None):
break break
xbmc.sleep(1000) xbmc.sleep(1000)
# Set played time # # Set played time
item_nfo.played_time = int(actual_time) if not marked else 0 # item_nfo.played_time = int(actual_time) if not marked else 0
filetools.write(nfo_path, head_nfo + item_nfo.tojson()) # filetools.write(nfo_path, head_nfo + item_nfo.tojson())
# Silent sync with Trakt # Silent sync with Trakt
if marked and config.get_setting("trakt_sync"): sync_trakt_kodi() if marked and config.get_setting("trakt_sync"): sync_trakt_kodi()
@@ -94,7 +94,7 @@ def mark_auto_as_watched(item, nfo_path=None, head_nfo=None, item_nfo=None):
# If it is configured to mark as seen # If it is configured to mark as seen
if config.get_setting("mark_as_watched", "videolibrary"): if config.get_setting("mark_as_watched", "videolibrary"):
threading.Thread(target=mark_as_watched_subThread, args=[item, nfo_path, head_nfo, item_nfo]).start() threading.Thread(target=mark_as_watched_subThread, args=[item]).start()
@@ -1340,12 +1340,11 @@ class NextDialog(xbmcgui.WindowXMLDialog):
f.close() f.close()
full_info = "".join(full_info) full_info = "".join(full_info)
info = jsontools.load(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"] info = info["infoLabels"]
if "fanart" in info: img = info["fanart"]
elif "thumbnail" in info: img = info["thumbnail"]
else: img = filetools.join(config.get_runtime_path(), "resources", "noimage.png")
self.setProperty("next_img", img)
self.setProperty("title", info["tvshowtitle"]) self.setProperty("title", info["tvshowtitle"])
self.setProperty("ep_title", "%dx%02d - %s" % (info["season"], info["episode"], info["title"])) self.setProperty("ep_title", "%dx%02d - %s" % (info["season"], info["episode"], info["title"]))
@@ -1381,4 +1380,4 @@ class NextDialog(xbmcgui.WindowXMLDialog):
if action in self.action_exitkeys_id: if action in self.action_exitkeys_id:
self.set_exit(True) self.set_exit(True)
self.set_continue_watching(False) self.set_continue_watching(False)
self.close() self.close()
@@ -25,6 +25,7 @@
<width>326</width> <width>326</width>
<height>180</height> <height>180</height>
<texture>$INFO[Window.Property(next_img)]</texture> <texture>$INFO[Window.Property(next_img)]</texture>
<aspectratio>scale</aspectratio>
</control> </control>
<control type="grouplist" id="20"> <control type="grouplist" id="20">
<orientation>vertical</orientation> <orientation>vertical</orientation>