Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions resources/lib/deviceAuthDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@


class DeviceAuthDialog(xbmcgui.WindowXMLDialog):
code: str
url: str

def __init__(self, xmlFile, resourcePath, code, url):
def __init__(self, xmlFile: str, resourcePath: str, code: str, url: str) -> None:
self.code = code
self.url = url

def onInit(self):
def onInit(self) -> None:
instuction = self.getControl(INSTRUCTION_LABEL)
authcode = self.getControl(AUTHCODE_LABEL)
warning = self.getControl(WARNING_LABEL)
Expand All @@ -34,17 +36,17 @@ def onInit(self):
authcode.setLabel(self.code)
warning.setLabel(getString(32162))

def onAction(self, action):
def onAction(self, action: xbmcgui.Action) -> None:
if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
self.close()

def onControl(self, control):
def onControl(self, control: xbmcgui.Control) -> None:
pass

def onFocus(self, control):
def onFocus(self, control: xbmcgui.Control) -> None:
pass

def onClick(self, control):
def onClick(self, control: xbmcgui.Control) -> None:
logger.debug('onClick: %s' % (control))

if control == LATER_BUTTON:
Expand Down
3 changes: 2 additions & 1 deletion resources/lib/globals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
#
from typing import Any

traktapi = None
traktapi: Any = None
8 changes: 4 additions & 4 deletions resources/lib/kodilogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

class KodiLogHandler(logging.StreamHandler):

def __init__(self):
def __init__(self) -> None:
logging.StreamHandler.__init__(self)
addon_id = xbmcaddon.Addon().getAddonInfo('id')
prefix = "[%s] " % addon_id
formatter = logging.Formatter(prefix + '%(name)s: %(message)s')
self.setFormatter(formatter)

def emit(self, record):
def emit(self, record: logging.LogRecord) -> None:
levels = {
logging.CRITICAL: xbmc.LOGFATAL,
logging.ERROR: xbmc.LOGERROR,
Expand All @@ -44,10 +44,10 @@ def emit(self, record):
if getSettingAsBool('debug'):
xbmc.log(self.format(record), levels[record.levelno])

def flush(self):
def flush(self) -> None:
pass

def config():
def config() -> None:
logger = logging.getLogger()
logger.addHandler(KodiLogHandler())
logger.setLevel(logging.DEBUG)
6 changes: 4 additions & 2 deletions resources/lib/obfuscation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
from typing import List, Union

def deobfuscate(data):

def deobfuscate(data: Union[List[int], str]) -> str:
if not data or not isinstance(data, list):
return ""
return "".join(chr(b ^ 0x42) for b in data)

def obfuscate(data):
def obfuscate(data: str) -> List[int]:
if not data:
return []
return [ord(c) ^ 0x42 for c in data]
23 changes: 15 additions & 8 deletions resources/lib/rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import xbmcgui
from resources.lib import utilities
from resources.lib import kodiUtilities
from typing import Dict, List, Optional, Any, Union
from resources.lib import globals
import logging

Expand All @@ -13,7 +14,7 @@
__addon__ = xbmcaddon.Addon("script.trakt")


def ratingCheck(media_type, items_to_rate, watched_time, total_time):
def ratingCheck(media_type: str, items_to_rate: List[Dict], watched_time: float, total_time: float) -> None:
"""Check if a video should be rated and if so launches the rating dialog"""
logger.debug("Rating Check called for '%s'" % media_type)
if not kodiUtilities.getSettingAsBool("rate_%s" % media_type):
Expand All @@ -30,7 +31,7 @@ def ratingCheck(media_type, items_to_rate, watched_time, total_time):
media_type, watched, kodiUtilities.getSettingAsFloat("rate_min_view_time")))


def rateMedia(media_type, itemsToRate, unrate=False, rating=None):
def rateMedia(media_type: str, itemsToRate: List[Dict], unrate: bool = False, rating: Optional[Union[int, str]] = None) -> None:
"""Launches the rating dialog"""
for summary_info in itemsToRate:
if not utilities.isValidMediaType(media_type):
Expand Down Expand Up @@ -117,7 +118,7 @@ def rateMedia(media_type, itemsToRate, unrate=False, rating=None):
rating = None


def __rateOnTrakt(rating, media_type, media, unrate=False):
def __rateOnTrakt(rating: Union[int, str], media_type: str, media: Dict, unrate: bool = False) -> None:
logger.debug("Sending rating (%s) to Trakt.tv" % rating)

params = media
Expand Down Expand Up @@ -166,6 +167,12 @@ def __rateOnTrakt(rating, media_type, media, unrate=False):


class RatingDialog(xbmcgui.WindowXMLDialog):
media_type: str
media: Dict
rating: Optional[Union[int, str]]
rerate: bool
default_rating: int

buttons = {
11030: 1,
11031: 2,
Expand All @@ -192,17 +199,17 @@ class RatingDialog(xbmcgui.WindowXMLDialog):
11039: 32027
}

def __init__(self, xmlFile, resourcePath, media_type, media, rerate):
def __init__(self, xmlFile: str, resourcePath: str, media_type: str, media: Dict, rerate: bool) -> None:
self.media_type = media_type
self.media = media
self.rating = None
self.rerate = rerate
self.default_rating = kodiUtilities.getSettingAsInt('rating_default')

def __new__(cls, xmlFile, resourcePath, media_type, media, rerate):
def __new__(cls, xmlFile: str, resourcePath: str, media_type: str, media: Dict, rerate: bool) -> Any:
return super(RatingDialog, cls).__new__(cls, xmlFile, resourcePath)

def onInit(self):
def onInit(self) -> None:
s = utilities.getFormattedItemName(self.media_type, self.media)
self.getControl(10012).setLabel(s)

Expand All @@ -211,12 +218,12 @@ def onInit(self):
rateID = 11029 + int(self.media['user']['ratings']['rating'])
self.setFocus(self.getControl(rateID))

def onClick(self, controlID):
def onClick(self, controlID: int) -> None:
if controlID in self.buttons:
self.rating = self.buttons[controlID]
self.close()

def onFocus(self, controlID):
def onFocus(self, controlID: int) -> None:
if controlID in self.focus_labels:
s = kodiUtilities.getString(self.focus_labels[controlID])

Expand Down
5 changes: 3 additions & 2 deletions resources/lib/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from resources.lib import utilities
from resources.lib import kodiUtilities
from resources.lib import sqlitequeue
from typing import Dict
from resources.lib.traktContextMenu import traktContextMenu

logger = logging.getLogger(__name__)


def __getArguments():
def __getArguments() -> Dict:
data = None
default_actions = {0: "sync"}
if len(sys.argv) == 1:
Expand All @@ -26,7 +27,7 @@ def __getArguments():
return data


def run():
def run() -> None:
args = __getArguments()
data = {}

Expand Down
59 changes: 30 additions & 29 deletions resources/lib/scrobbler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import xbmc
import time
import logging
from typing import Dict, List, Optional, Any
from resources.lib import utilities
from resources.lib import kodiUtilities
import math
Expand All @@ -13,34 +14,34 @@


class Scrobbler:
traktapi = None
isPlaying = False
isPaused = False
stopScrobbler = False
isPVR = False
isMultiPartEpisode = False
lastMPCheck = 0
curMPEpisode = 0
videoDuration = 1
watchedTime = 0
pausedAt = 0
curVideo = None
curVideoInfo = None
playlistIndex = 0
traktShowSummary = None
videosToRate = []

def __init__(self, api):
traktapi: Any = None
isPlaying: bool = False
isPaused: bool = False
stopScrobbler: bool = False
isPVR: bool = False
isMultiPartEpisode: bool = False
lastMPCheck: float = 0
curMPEpisode: int = 0
videoDuration: float = 1
watchedTime: float = 0
pausedAt: float = 0
curVideo: Optional[Dict] = None
curVideoInfo: Optional[Dict] = None
playlistIndex: int = 0
traktShowSummary: Optional[Dict] = None
videosToRate: List[Dict] = []

def __init__(self, api: Any) -> None:
self.traktapi = api

def _currentEpisode(self, watchedPercent, episodeCount):
def _currentEpisode(self, watchedPercent: float, episodeCount: int) -> int:
split = 100 / episodeCount
for i in range(episodeCount - 1, 0, -1):
if watchedPercent >= (i * split):
return i
return 0

def transitionCheck(self, isSeek=False):
def transitionCheck(self, isSeek: bool = False) -> None:
if not xbmc.Player().isPlayingVideo():
return

Expand Down Expand Up @@ -198,7 +199,7 @@ def transitionCheck(self, isSeek=False):
elif isSeek:
self.__scrobble("start")

def playbackStarted(self, data):
def playbackStarted(self, data: Dict) -> None:
logger.debug("playbackStarted(data: %s)" % data)
if not data:
return
Expand Down Expand Up @@ -406,7 +407,7 @@ def playbackStarted(self, data):

self.__preFetchUserRatings(result)

def __preFetchUserRatings(self, result):
def __preFetchUserRatings(self, result: Dict) -> None:
if result:
if utilities.isMovie(
self.curVideo["type"]
Expand Down Expand Up @@ -439,7 +440,7 @@ def __preFetchUserRatings(self, result):
}
logger.debug("Pre-Fetch result: %s; Info: %s" % (result, self.curVideoInfo))

def playbackResumed(self):
def playbackResumed(self) -> None:
if not self.isPlaying or self.isPVR:
return

Expand All @@ -451,7 +452,7 @@ def playbackResumed(self):
self.isPaused = False
self.__scrobble("start")

def playbackPaused(self):
def playbackPaused(self) -> None:
if not self.isPlaying or self.isPVR:
return

Expand All @@ -461,14 +462,14 @@ def playbackPaused(self):
self.pausedAt = time.time()
self.__scrobble("pause")

def playbackSeek(self):
def playbackSeek(self) -> None:
if not self.isPlaying:
return

logger.debug("playbackSeek()")
self.transitionCheck(isSeek=True)

def playbackEnded(self):
def playbackEnded(self) -> None:
if not self.isPVR:
self.videosToRate.append(self.curVideoInfo)
if not self.isPlaying:
Expand Down Expand Up @@ -497,15 +498,15 @@ def playbackEnded(self):
self.curVideo = None
self.playlistIndex = 0

def __calculateWatchedPercent(self):
def __calculateWatchedPercent(self) -> float:
# we need to floor this, so this calculation yields the same result as the playback progress calculation
floored = math.floor(self.videoDuration)
if floored != 0:
return (self.watchedTime / floored) * 100
else:
return 0

def __scrobble(self, status):
def __scrobble(self, status: str) -> Optional[Dict]:
if not self.curVideoInfo:
return

Expand Down Expand Up @@ -609,7 +610,7 @@ def __scrobble(self, status):
% (self.traktShowSummary, self.curVideoInfo, watchedPercent, status)
)

def __scrobbleNotification(self, info):
def __scrobbleNotification(self, info: Dict) -> None:
if not self.curVideoInfo:
return

Expand Down
Loading