Skip to content

Commit 622b82f

Browse files
committed
CR
1 parent dd4a51c commit 622b82f

1 file changed

Lines changed: 25 additions & 14 deletions

File tree

resources/lib/player.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class KodiPlayer(xbmc.Player):
1818
"""
1919

2020
# noinspection PyUnusedLocal
21-
def __init__(self, *args):
21+
def __init__(self, *_args):
2222
"""
2323
Initialize the KodiPlayer instance and bind it to xbmc.Player.
2424
2525
Parameters:
26-
*args: Optional positional arguments accepted for compatibility; any values passed are ignored.
26+
*_args: Optional positional arguments accepted for compatibility; any values passed are ignored.
2727
"""
2828
xbmc.Player.__init__(self)
2929
Logger.debug('KodiPlayer __init__')
@@ -65,7 +65,6 @@ def onPlayBackSeek(self, time_to_seek, seek_offset):
6565
except RuntimeError:
6666
Logger.warning("Could not get playing time - seeked past end? Clearing resume point.")
6767
self.update_resume_point(0)
68-
pass
6968

7069
def onPlayBackSeekChapter(self, chapter):
7170
Logger.info(f'onPlayBackSeekChapter chapter: {chapter}')
@@ -74,7 +73,6 @@ def onPlayBackSeekChapter(self, chapter):
7473
except RuntimeError:
7574
Logger.warning("Could not get playing time - seeked past end? Clearing resume point.")
7675
self.update_resume_point(0)
77-
pass
7876

7977
def onAVStarted(self):
8078
Logger.info("onAVStarted")
@@ -109,7 +107,11 @@ def update_resume_point(self, seconds):
109107
"""
110108
This is where the work is done - stores a new resume point in the Kodi library for the currently playing file
111109
112-
:param: seconds: the time to update the resume point to. @todo add notes on -1, -2 etc here!
110+
:param seconds: target resume time in seconds.
111+
Special values:
112+
-2 -> stopped normally, let Kodi persist native resume (no-op here)
113+
-1 -> end-of-file, clear resume point (sends 0)
114+
0 -> explicit clear resume point
113115
:param: Store.library_id: the Kodi library id of the currently playing file
114116
:return: None
115117
"""
@@ -162,11 +164,13 @@ def update_resume_point(self, seconds):
162164
seconds = 0
163165

164166
# if current time > Kodi's ignorepercentatend setting
165-
percent_played = int((seconds * 100) / Store.length_of_currently_playing_file)
166-
if percent_played > (100 - Store.ignore_percent_at_end):
167-
Logger.info(f'Not updating resume point as current percent played ({percent_played}) is above Kodi\'s ignorepercentatend'
168-
f' setting of {Store.ignore_percent_at_end}')
169-
return
167+
# if current time > Kodi's ignorepercentatend setting
168+
total = Store.length_of_currently_playing_file
169+
if total:
170+
percent_played = int((seconds * 100) / total)
171+
if percent_played > (100 - Store.ignore_percent_at_end):
172+
Logger.info(f"Not updating resume point as current percent played ({percent_played}) is above Kodi's ignorepercentatend setting of {Store.ignore_percent_at_end}")
173+
return
170174

171175
# OK, BELOW HERE, we're probably going to set a resume point
172176

@@ -278,13 +282,17 @@ def resume_if_was_playing(self):
278282
with open(Store.file_to_store_last_played, 'r') as f:
279283
full_path = f.read()
280284

281-
str_timestamp = '%d:%02d' % (resume_point / 60, resume_point % 60)
282-
Logger.info(f'Will resume playback at {str_timestamp} of {full_path}')
285+
if not full_path:
286+
Logger.info("No last-played file found; skipping resume.")
287+
return False
288+
289+
mins, secs = divmod(int(resume_point), 60)
290+
str_timestamp = f'{mins}:{secs:02d}'
283291

284292
self.play(full_path)
285293

286294
# wait up to 10 secs for the video to start playing before we try to seek
287-
for i in range(0, 1000):
295+
for _ in range(100):
288296
if not self.isPlayingVideo() and not Store.kodi_event_monitor.abortRequested():
289297
xbmc.sleep(100)
290298
else:
@@ -379,7 +387,10 @@ def autoplay_random_if_enabled(self):
379387
if not self.isPlayingVideo() \
380388
and (video_playlist.getposition() == -1 or video_playlist.getposition() == video_playlist.size()):
381389
full_path = self.get_random_library_video()
382-
Logger.info("Auto-playing next random video because nothing is playing and playlist is empty: " + full_path)
390+
if not full_path:
391+
Logger.info("No random video available to autoplay.")
392+
return
393+
Logger.info(f"Auto-playing next random video because nothing is playing and playlist is empty: {full_path}")
383394
self.play(full_path)
384395
Notify.info(f'Auto-playing random video: {full_path}')
385396
else:

0 commit comments

Comments
 (0)