Skip to content

Commit

Permalink
V2.0.6 - Add support for non-library videos
Browse files Browse the repository at this point in the history
  • Loading branch information
bossanova808 committed Apr 11, 2024
1 parent fd195ef commit 80c7276
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
6 changes: 2 additions & 4 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.service.playbackresumer" name="Kodi Playback Resumer" version="2.0.5" provider-name="bossanova808, bradvido88">
<addon id="script.service.playbackresumer" name="Kodi Playback Resumer" version="2.0.6" provider-name="bossanova808, bradvido88">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
</requires>
Expand All @@ -15,9 +15,7 @@
<source>https://github.com/bossanova808/script.service.playbackresumer</source>
<forum>https://forum.kodi.tv/showthread.php?tid=355383</forum>
<email>[email protected]</email>
<news>v2.0.5
- Fix odd reported bug with resume points
</news>
<news>v2.0.6 - Add support for non-library videos</news>
<assets>
<icon>icon.png</icon>
</assets>
Expand Down
3 changes: 2 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
v2.0.6 (unreleased)
v2.0.6

- Add support for non library videos

v2.0.5
Expand Down
71 changes: 49 additions & 22 deletions resources/lib/common.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
# -*- coding: utf-8 -*-

"""
Handy utility functions for Kodi Addons
By bossanova808
Free in all senses....
VERSION 0.2.3 2021-06-21
(For Kodi Matrix & later)
Handy utility functions & constants for Kodi Addons
For Kodi Matrix & later
By bossanova808 - freely released
VERSION 0.2.6 2024-04-11
Changelog:
0.2.6 - (SkinPatcher) - add float KODI_VERSION_FLOAT constant, alongside string KODI_VERSION
0.2.5 - (Skin) - move to storing copy of latest in bossanova808 repo and adding this mini changelog
For latest version - ALWAYS COPY BACK ANY CHANGES, plus do changelog, and a version & date bump above:
https://github.com/bossanova808/repository.bossanova808/blob/main/latest-common/common.py
"""

import sys
import traceback

import xbmc
import xbmcvfs
import xbmcgui
import xbmcaddon
import json


ADDON = xbmcaddon.Addon()
ADDON_NAME = ADDON.getAddonInfo('name')
Expand All @@ -25,6 +38,7 @@
LANGUAGE = ADDON.getLocalizedString
PROFILE = xbmcvfs.translatePath(ADDON.getAddonInfo('profile'))
KODI_VERSION = xbmc.getInfoLabel('System.BuildVersion')
KODI_VERSION_FLOAT = float(KODI_VERSION.split("(")[0])
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
HOME_WINDOW = xbmcgui.Window(10000)
WEATHER_WINDOW = xbmcgui.Window(12600)
Expand All @@ -49,6 +63,8 @@
"""

unit_testing = False

# Testing outside of Kodi
if not xbmc.getUserAgent():

xbmc = None
Expand All @@ -63,6 +79,7 @@ def log(message, exception_instance=None, level=None):
print(f'EXCPT: {traceback.format_exc(exception_instance)}')


# Running inside of Kodi
else:

def log(message, exception_instance=None, level=xbmc.LOGDEBUG):
Expand Down Expand Up @@ -105,42 +122,43 @@ def set_property(window, name, value=""):
def get_property(window, name):
"""
Return the value of a window property
@param window:
@param name:
@return:
:param window: the Kodi window to get the property value from
:param name: the name of the property to get
:return: the value of the window property
"""
return window.getProperty(name)


def get_property_as_bool(window, name):
"""
Return the value of a window property as a boolean
@param window:
@param name:
@return:
:param window: the Kodi window to get the property value from
:param name: the name of the property to get
:return: the value of the window property in boolean form
"""
return window.getProperty(name).lower() == "true"


def send_kodi_json(human_description, json_string):
"""
Send a JSON command to Kodi, logging the human description, command, and result returned.
Send a JSON command to Kodi, logging the human description, command, and result as returned.
:param human_description: Required. A human sensible description of what the command is aiming to do/retrieve.
:param json_string: Required. The json command to send.
:return the json object loaded from the result string
"""
log(f'KODI JSON RPC command: {human_description} [{json_string}]')
result = xbmc.executeJSONRPC(json_string)
log(f'KODI JSON RPC result: {result}')
return result
return json.loads(result)


def get_setting(setting):
"""
Helper function to get string type from settings
@param setting:
@return: setting value
:param setting: The addon setting to return
:return: the setting value
"""
return ADDON.getSetting(setting).strip()

Expand All @@ -149,8 +167,8 @@ def get_setting_as_bool(setting):
"""
Helper function to get bool type from settings
@param setting:
@return: setting value as boolen
:param setting: The addon setting to return
:return: the setting value as boolean
"""
return get_setting(setting).lower() == "true"

Expand All @@ -159,10 +177,10 @@ def notify(message, notification_type=xbmcgui.NOTIFICATION_ERROR, duration=5000)
"""
Send a notification to the user via the Kodi GUI
@param message: the message to send
@param notification_type: xbmcgui.NOTIFICATION_ERROR (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_INFO
@param duration: time to display notification in milliseconds, default 5000
@return: None
:param message: the message to send
:param notification_type: xbmcgui.NOTIFICATION_ERROR (default), xbmcgui.NOTIFICATION_WARNING, or xbmcgui.NOTIFICATION_INFO
:param duration: time to display notification in milliseconds, default 5000
:return: None
"""
dialog = xbmcgui.Dialog()

Expand All @@ -171,6 +189,15 @@ def notify(message, notification_type=xbmcgui.NOTIFICATION_ERROR, duration=5000)
notification_type,
duration)

def is_playback_paused():
"""
Helper function to return Kodi player state.
(Odd this is needed, it should be a testable state on Player really..)
:return: boolean indicating player paused state
"""
return bool(xbmc.getCondVisibility("Player.Paused"))


def footprints(startup=True):
"""
Expand All @@ -180,7 +207,7 @@ def footprints(startup=True):
"""
if startup:
log(f'Starting...', level=xbmc.LOGINFO)
log(f'Kodi Version: {KODI_VERSION}', level=xbmc.LOGINFO)
log(f'Kodi Version: {KODI_VERSION}, as float {KODI_VERSION_FLOAT}', level=xbmc.LOGINFO)
log(f'Addon arguments: {ADDON_ARGUMENTS}', level=xbmc.LOGINFO)
else:
log(f'Exiting...', level=xbmc.LOGINFO)
Expand Down

0 comments on commit 80c7276

Please sign in to comment.