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

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)
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:
# 0: Servers and qualities

View File

@@ -1165,6 +1165,7 @@ def server(item, data='', itemlist=[], headers='', AutoPlay=True, CheckLinks=Tru
videoitem.quality = quality
videoitem.referer = item.url
videoitem.action = "play"
videoitem.infoLabels = item.infoLabels
# videoitem.nfo = item.nfo
# videoitem.strm_path = item.strm_path
return videoitem

View File

@@ -355,8 +355,10 @@ class SearchWindow(xbmcgui.WindowXML):
items = []
for result in channelResults:
if result: items.append(self.makeItem(result))
pos = self.RESULTS.getSelectedPosition()
self.RESULTS.reset()
self.RESULTS.addItems(items)
self.RESULTS.selectItem(pos)
if results:
resultsList = ''
channelParams = channeltools.get_channel_parameters(channel)
@@ -648,7 +650,6 @@ class SearchWindow(xbmcgui.WindowXML):
elif control_id in [SERVERLIST]:
server = Item().fromurl(self.getControl(control_id).getSelectedItem().getProperty('item'))
server.player_mode = 0
return run(server)
def Back(self):

View File

@@ -489,17 +489,24 @@ def play_from_library(item):
item.play_from = 'window'
itemlist = videolibrary.findvideos(item)
p_dialog.update(100, ''); sleep(0.5); p_dialog.close()
# while platformtools.is_playing(): # Conventional window
# sleep(100)
play_time = platformtools.resume_playback(item, True)
if not play_time and config.get_setting('autoplay'):
while platformtools.is_playing(): sleep(1)
# from core.support import dbg;dbg()
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)
played_time = platformtools.get_played_time(item_nfo)
else: played_time = 0
if not played_time and config.get_setting('autoplay'):
return
# The number of links to show is limited
if config.get_setting("max_links", "videolibrary") != 0: itemlist = limit_itemlist(itemlist)
# The list of links is slightly "cleaned"
if config.get_setting("replace_VD", "videolibrary") == 1: itemlist = reorder_itemlist(itemlist)
from core.support import dbg;dbg()
if len(itemlist) > 0:
while not xbmc.Monitor().abortRequested():
# The user chooses the mirror

View File

@@ -679,9 +679,7 @@ def play_video(item, strm=False, force_direct=False, autoplay=False):
if force_direct: item.play_from = 'window'
item, nfo_path, head_nfo, item_nfo = resume_playback(item)
set_player(item, xlistitem, mediaurl, view, strm, nfo_path, head_nfo, item_nfo)
set_player(item, xlistitem, mediaurl, view, strm)
def stop_video():
@@ -1009,7 +1007,7 @@ def get_video_seleccionado(item, seleccion, video_urls):
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("item:\n" + item.tostring('\n'))
# 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
else:
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
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
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:
logger.info('Player Mode: setResolvedUrl')
xlistitem.setPath(mediaurl)
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, xlistitem)
# xbmc.sleep(2500)
logger.info('Player Mode: Bookmark')
# Add the listitem to a playlist
playlist = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
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:
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 strm or item.strm_path:
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
if item.focusOnVideoPlayer:
@@ -1079,6 +1092,24 @@ def set_player(item, xlistitem, mediaurl, view, strm, nfo_path=None, head_nfo=No
xbmc.sleep(500)
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):
# External plugins found in servers / torrent.json node clients
@@ -1136,7 +1167,7 @@ def play_torrent(item, xlistitem, mediaurl):
time.sleep(3)
def resume_playback(item, return_played_time=False):
def resume_playback(played_time):
class ResumePlayback(xbmcgui.WindowXMLDialog):
Close = False
Resume = False
@@ -1144,8 +1175,8 @@ def resume_playback(item, return_played_time=False):
def __init__(self, *args, **kwargs):
self.action_exitkeys_id = [xbmcgui.ACTION_BACKSPACE, xbmcgui.ACTION_PREVIOUS_MENU, xbmcgui.ACTION_NAV_BACK]
self.progress_control = None
self.item = kwargs.get('item')
m, s = divmod(float(self.item.played_time), 60)
played_time = kwargs.get('played_time')
m, s = divmod(played_time, 60)
h, m = divmod(m, 60)
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:
self.set_values(False)
self.close()
from core import videolibrarytools, filetools
# Read NFO FILE
if item.contentType == 'movie':
nfo_path = item.nfo
else:
nfo_path = item.strm_path.replace('strm','nfo')
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
if played_time:
Dialog = ResumePlayback('ResumePlayback.xml', config.get_runtime_path(), played_time=played_time)
Dialog.show()
t = 0
while not Dialog.is_close() and t < 100:
t += 1
xbmc.sleep(100)
if not Dialog.Resume: played_time = 0
else: played_time = 0
return played_time
##### INPUTSTREM #####
@@ -1396,3 +1405,65 @@ def get_platform():
ret["arch"] = "arm"
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()

View File

@@ -20,8 +20,8 @@ from core import scrapertools
from xml.dom import minidom
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):
def mark_auto_as_watched(item):
def mark_as_watched_subThread(item):
logger.debug()
# 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():
actual_time = xbmc.Player().getTime()
total_time = xbmc.Player().getTotalTime()
if item_nfo.played_time and xbmcgui.getCurrentWindowId() == 12005:
xbmc.Player().seekTime(item_nfo.played_time)
item_nfo.played_time = 0 # Fix for Slow Devices
# if item_nfo.played_time and xbmcgui.getCurrentWindowId() == 12005:
# xbmc.Player().seekTime(item_nfo.played_time)
# item_nfo.played_time = 0 # Fix for Slow Devices
mark_time = total_time * percentage
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
xbmc.sleep(1000)
# Set played time
item_nfo.played_time = int(actual_time) if not marked else 0
filetools.write(nfo_path, head_nfo + item_nfo.tojson())
# # Set played time
# item_nfo.played_time = int(actual_time) if not marked else 0
# filetools.write(nfo_path, head_nfo + item_nfo.tojson())
# Silent sync with Trakt
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 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()
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"]
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("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:
self.set_exit(True)
self.set_continue_watching(False)
self.close()
self.close()

View File

@@ -25,6 +25,7 @@
<width>326</width>
<height>180</height>
<texture>$INFO[Window.Property(next_img)]</texture>
<aspectratio>scale</aspectratio>
</control>
<control type="grouplist" id="20">
<orientation>vertical</orientation>