44import xbmc
55import time
66import logging
7+ from typing import Dict , List , Optional , Any
78from resources .lib import utilities
89from resources .lib import kodiUtilities
910import math
1314
1415
1516class Scrobbler :
16- traktapi = None
17- isPlaying = False
18- isPaused = False
19- stopScrobbler = False
20- isPVR = False
21- isMultiPartEpisode = False
22- lastMPCheck = 0
23- curMPEpisode = 0
24- videoDuration = 1
25- watchedTime = 0
26- pausedAt = 0
27- curVideo = None
28- curVideoInfo = None
29- playlistIndex = 0
30- traktShowSummary = None
31- videosToRate = []
32-
33- def __init__ (self , api ) :
17+ traktapi : Any = None
18+ isPlaying : bool = False
19+ isPaused : bool = False
20+ stopScrobbler : bool = False
21+ isPVR : bool = False
22+ isMultiPartEpisode : bool = False
23+ lastMPCheck : float = 0
24+ curMPEpisode : int = 0
25+ videoDuration : float = 1
26+ watchedTime : float = 0
27+ pausedAt : float = 0
28+ curVideo : Optional [ Dict ] = None
29+ curVideoInfo : Optional [ Dict ] = None
30+ playlistIndex : int = 0
31+ traktShowSummary : Optional [ Dict ] = None
32+ videosToRate : List [ Dict ] = []
33+
34+ def __init__ (self , api : Any ) -> None :
3435 self .traktapi = api
3536
36- def _currentEpisode (self , watchedPercent , episodeCount ) :
37+ def _currentEpisode (self , watchedPercent : float , episodeCount : int ) -> int :
3738 split = 100 / episodeCount
3839 for i in range (episodeCount - 1 , 0 , - 1 ):
3940 if watchedPercent >= (i * split ):
4041 return i
4142 return 0
4243
43- def transitionCheck (self , isSeek = False ):
44+ def transitionCheck (self , isSeek : bool = False ) -> None :
4445 if not xbmc .Player ().isPlayingVideo ():
4546 return
4647
@@ -198,7 +199,7 @@ def transitionCheck(self, isSeek=False):
198199 elif isSeek :
199200 self .__scrobble ("start" )
200201
201- def playbackStarted (self , data ) :
202+ def playbackStarted (self , data : Dict ) -> None :
202203 logger .debug ("playbackStarted(data: %s)" % data )
203204 if not data :
204205 return
@@ -406,7 +407,7 @@ def playbackStarted(self, data):
406407
407408 self .__preFetchUserRatings (result )
408409
409- def __preFetchUserRatings (self , result ) :
410+ def __preFetchUserRatings (self , result : Dict ) -> None :
410411 if result :
411412 if utilities .isMovie (
412413 self .curVideo ["type" ]
@@ -439,7 +440,7 @@ def __preFetchUserRatings(self, result):
439440 }
440441 logger .debug ("Pre-Fetch result: %s; Info: %s" % (result , self .curVideoInfo ))
441442
442- def playbackResumed (self ):
443+ def playbackResumed (self ) -> None :
443444 if not self .isPlaying or self .isPVR :
444445 return
445446
@@ -451,7 +452,7 @@ def playbackResumed(self):
451452 self .isPaused = False
452453 self .__scrobble ("start" )
453454
454- def playbackPaused (self ):
455+ def playbackPaused (self ) -> None :
455456 if not self .isPlaying or self .isPVR :
456457 return
457458
@@ -461,14 +462,14 @@ def playbackPaused(self):
461462 self .pausedAt = time .time ()
462463 self .__scrobble ("pause" )
463464
464- def playbackSeek (self ):
465+ def playbackSeek (self ) -> None :
465466 if not self .isPlaying :
466467 return
467468
468469 logger .debug ("playbackSeek()" )
469470 self .transitionCheck (isSeek = True )
470471
471- def playbackEnded (self ):
472+ def playbackEnded (self ) -> None :
472473 if not self .isPVR :
473474 self .videosToRate .append (self .curVideoInfo )
474475 if not self .isPlaying :
@@ -497,15 +498,15 @@ def playbackEnded(self):
497498 self .curVideo = None
498499 self .playlistIndex = 0
499500
500- def __calculateWatchedPercent (self ):
501+ def __calculateWatchedPercent (self ) -> float :
501502 # we need to floor this, so this calculation yields the same result as the playback progress calculation
502503 floored = math .floor (self .videoDuration )
503504 if floored != 0 :
504505 return (self .watchedTime / floored ) * 100
505506 else :
506507 return 0
507508
508- def __scrobble (self , status ) :
509+ def __scrobble (self , status : str ) -> Optional [ Dict ] :
509510 if not self .curVideoInfo :
510511 return
511512
@@ -609,7 +610,7 @@ def __scrobble(self, status):
609610 % (self .traktShowSummary , self .curVideoInfo , watchedPercent , status )
610611 )
611612
612- def __scrobbleNotification (self , info ) :
613+ def __scrobbleNotification (self , info : Dict ) -> None :
613614 if not self .curVideoInfo :
614615 return
615616
0 commit comments