mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2026-04-27 22:05:38 +00:00
fix(player): use boolean not constant. re-inline report_playback
This commit is contained in:
parent
1d42d3f444
commit
bcf880df36
1 changed files with 34 additions and 39 deletions
|
|
@ -20,8 +20,6 @@ LOG = LazyLogger(__name__)
|
|||
|
||||
#################################################################################################
|
||||
|
||||
SETTING_MEDIA_SEGMENTS_ENABLED = "mediaSegmentsEnabled.bool"
|
||||
|
||||
|
||||
class Player(xbmc.Player):
|
||||
|
||||
|
|
@ -126,7 +124,7 @@ class Player(xbmc.Player):
|
|||
window("jellyfin.skip.%s.bool" % item["Id"], True)
|
||||
|
||||
# Immediate skip check for segments starting at 0:00
|
||||
if settings(SETTING_MEDIA_SEGMENTS_ENABLED):
|
||||
if settings("mediaSegmentsEnabled.bool"):
|
||||
try:
|
||||
self._fetch_skip_segments(item)
|
||||
current_pos = int(self.getTime())
|
||||
|
|
@ -334,7 +332,7 @@ class Player(xbmc.Player):
|
|||
LOG.info("--[ seek ]")
|
||||
|
||||
# Check skip segments immediately after seek
|
||||
if settings(SETTING_MEDIA_SEGMENTS_ENABLED):
|
||||
if settings("mediaSegmentsEnabled.bool"):
|
||||
try:
|
||||
current_file = self.get_playing_file()
|
||||
item = self.get_file_info(current_file)
|
||||
|
|
@ -343,37 +341,6 @@ class Player(xbmc.Player):
|
|||
except Exception:
|
||||
pass
|
||||
|
||||
def _should_skip_full_report(self, item):
|
||||
"""Check position and handle skip segments. Returns True if full report should be skipped."""
|
||||
previous = item["CurrentPosition"]
|
||||
|
||||
try:
|
||||
item["CurrentPosition"] = int(self.getTime())
|
||||
except Exception as e:
|
||||
LOG.debug("Failed to get playback position: %s", e)
|
||||
return None # Signal to return from caller
|
||||
|
||||
if int(item["CurrentPosition"]) == 1:
|
||||
return None # Signal to return from caller
|
||||
|
||||
try:
|
||||
played = (
|
||||
float(item["CurrentPosition"] * 10000000)
|
||||
/ int(item["Runtime"])
|
||||
* 100
|
||||
)
|
||||
except ZeroDivisionError:
|
||||
played = 0
|
||||
|
||||
if played > 2.0 and not self.up_next:
|
||||
self.up_next = True
|
||||
self.next_up()
|
||||
|
||||
if settings(SETTING_MEDIA_SEGMENTS_ENABLED):
|
||||
self.check_skip_segments(item, item["CurrentPosition"])
|
||||
|
||||
return (item["CurrentPosition"] - previous) < 30
|
||||
|
||||
def report_playback(self, report=True):
|
||||
"""Report playback progress to jellyfin server.
|
||||
Check if the user seek.
|
||||
|
|
@ -389,8 +356,36 @@ class Player(xbmc.Player):
|
|||
return
|
||||
|
||||
if not report:
|
||||
skip_result = self._should_skip_full_report(item)
|
||||
if skip_result is None or skip_result:
|
||||
previous = item["CurrentPosition"]
|
||||
|
||||
try:
|
||||
item["CurrentPosition"] = int(self.getTime())
|
||||
except Exception as e:
|
||||
# getTime() raises RuntimeError if nothing is playing
|
||||
LOG.debug("Failed to get playback position: %s", e)
|
||||
return
|
||||
|
||||
if int(item["CurrentPosition"]) == 1:
|
||||
return
|
||||
|
||||
try:
|
||||
played = (
|
||||
float(item["CurrentPosition"] * 10000000)
|
||||
/ int(item["Runtime"])
|
||||
* 100
|
||||
)
|
||||
except ZeroDivisionError: # Runtime is 0.
|
||||
played = 0
|
||||
|
||||
if played > 2.0 and not self.up_next:
|
||||
|
||||
self.up_next = True
|
||||
self.next_up()
|
||||
|
||||
if settings("mediaSegmentsEnabled.bool"):
|
||||
self.check_skip_segments(item, item["CurrentPosition"])
|
||||
|
||||
if (item["CurrentPosition"] - previous) < 30:
|
||||
return
|
||||
|
||||
result = JSONRPC("Application.GetProperties").execute(
|
||||
|
|
@ -418,7 +413,7 @@ class Player(xbmc.Player):
|
|||
}
|
||||
item["Server"].jellyfin.session_progress(data)
|
||||
|
||||
if settings(SETTING_MEDIA_SEGMENTS_ENABLED):
|
||||
if settings("mediaSegmentsEnabled.bool"):
|
||||
self.check_skip_segments(item, item["CurrentPosition"])
|
||||
|
||||
def onPlayBackStopped(self):
|
||||
|
|
@ -508,7 +503,7 @@ class Player(xbmc.Player):
|
|||
self.played.clear()
|
||||
|
||||
def _fetch_skip_segments(self, item):
|
||||
if not settings(SETTING_MEDIA_SEGMENTS_ENABLED):
|
||||
if not settings("mediaSegmentsEnabled.bool"):
|
||||
return
|
||||
|
||||
item_id = item["Id"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue