Modalità di riproduzione "segnalibro" via database
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user