Skip to content

Commit dd4a51c

Browse files
authored
Merge pull request #10 from bossanova808/coderabbitai/docstrings/aa1926d
📝 Add docstrings to `pre-for-piers-and-use-playback-class`
2 parents aa1926d + 986050e commit dd4a51c

3 files changed

Lines changed: 48 additions & 9 deletions

File tree

resources/lib/monitor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ def __init__(self, *args, **kwargs):
1111
Logger.debug('KodiEventMonitor __init__')
1212

1313
def onSettingsChanged(self):
14+
"""
15+
Handle Kodi settings changes by reloading the add-on configuration from settings.
16+
17+
Invoked when Kodi reports settings have changed; calls the Store to reload configuration so runtime state reflects updated settings.
18+
"""
1419
Logger.info('onSettingsChanged - reload them.')
1520
Store.load_config_from_settings()
1621

resources/lib/playback_resumer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111

1212
def run():
1313
"""
14-
This is 'main'
15-
16-
:return:
14+
Start the addon: initialize logging and global state, configure Kodi monitor and player, attempt to resume or start playback, then run the main event loop until an abort is requested.
15+
16+
This function:
17+
- Starts the logger and creates the global Store.
18+
- Instantiates and stores Kodi event monitor and player objects.
19+
- Attempts to resume previous playback; if nothing resumed and no video is playing, triggers autoplay when enabled.
20+
- Enters a loop that waits for an abort request and exits when one is detected.
21+
- Stops the logger before returning.
1722
"""
1823
Logger.start()
1924
# load settings and create the store for our globals

resources/lib/player.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class KodiPlayer(xbmc.Player):
1919

2020
# noinspection PyUnusedLocal
2121
def __init__(self, *args):
22+
"""
23+
Initialize the KodiPlayer instance and bind it to xbmc.Player.
24+
25+
Parameters:
26+
*args: Optional positional arguments accepted for compatibility; any values passed are ignored.
27+
"""
2228
xbmc.Player.__init__(self)
2329
Logger.debug('KodiPlayer __init__')
2430

@@ -33,10 +39,26 @@ def onPlayBackEnded(self): # video ended normally (user didn't stop it)
3339
self.autoplay_random_if_enabled()
3440

3541
def onPlayBackStopped(self):
42+
"""
43+
Handle the playback-stopped event and mark the current resume point as managed by Kodi.
44+
45+
When playback stops, record a sentinel resume value indicating that Kodi should retain or handle the resume point (internal sentinel -2).
46+
"""
3647
Logger.info("onPlayBackStopped")
3748
self.update_resume_point(-2)
3849

3950
def onPlayBackSeek(self, time_to_seek, seek_offset):
51+
"""
52+
Handle a user-initiated seek during playback and update the stored resume point.
53+
54+
When a seek occurs, attempt to record the current playback time as the resume point.
55+
If reading the current playback time raises a RuntimeError (e.g., seeked past the end),
56+
clear the stored resume point.
57+
58+
Parameters:
59+
time_to_seek (float): The target time position of the seek (seconds).
60+
seek_offset (float): The relative offset of the seek from the previous position (seconds).
61+
"""
4062
Logger.info(f'onPlayBackSeek time {time_to_seek}, seekOffset {seek_offset}')
4163
try:
4264
self.update_resume_point(self.getTime())
@@ -229,9 +251,12 @@ def update_resume_point(self, seconds):
229251

230252
def resume_if_was_playing(self):
231253
"""
232-
Automatically resume a video after a crash, if one was playing...
233-
234-
:return:
254+
Attempt to resume playback after a previous shutdown if resuming is enabled and saved resume data exist.
255+
256+
If configured and valid resume data are present, the player will start the saved file and seek to the stored resume time; on any failure or if no resume data are applicable, no playback is resumed.
257+
258+
Returns:
259+
True if playback was resumed and seeked to the saved position, False otherwise.
235260
"""
236261

237262
if Store.resume_on_startup \
@@ -271,9 +296,13 @@ def resume_if_was_playing(self):
271296

272297
def get_random_library_video(self):
273298
"""
274-
Get a random video from the library for playback
275-
276-
:return:
299+
Selects a random video file path from the Kodi library.
300+
301+
Chooses among episodes, movies, and music videos and returns the file path of a randomly selected item if one exists. Updates Store.video_types_in_library to reflect whether a given type is present. If the library contains no eligible videos, no selection is made.
302+
303+
Returns:
304+
str: File path of the selected video.
305+
False: If no episodes, movies, or music videos exist in the library.
277306
"""
278307

279308
# Short circuit if library is empty

0 commit comments

Comments
 (0)