@@ -34,7 +34,7 @@ def __init__(self):
3434 utils .ensure_addon_data ()
3535 self ._update_properties ()
3636 self ._clean_widgets ()
37- self .queue = queue . Queue ()
37+ self .queue = OrderedSetQueue ()
3838 for _ in range (1 if self .low_end else 4 ):
3939 thread = threading .Thread (target = self ._processQueue )
4040 thread .start ()
@@ -84,7 +84,7 @@ def tick(self, step, max, abort_check=lambda: False):
8484
8585 def _update_widgets (self ):
8686 if self .low_end :
87- self .waitForAbort (120 )
87+ self .waitForAbort (30 )
8888
8989 startup = True
9090 while not self .abortRequested ():
@@ -101,26 +101,26 @@ def _update_widgets(self):
101101 def onNotification (self , sender , method , data ):
102102 if sender == "AutoWidget" :
103103 data = json .loads (data )
104- # TODO: ensure we don't queue same one twice
105- utils . log ( "Added to queue: {} {}" . format ( data [ 'hash' ][: 5 ], data [ 'path' ]), "notice" )
106- self .queue .put (data )
104+ utils . log ( "Added to queue: {} {} {}" . format ( * data ), "notice" )
105+ # special queue ensures we don't queue same one twice at the same time
106+ self .queue .put (tuple ( data ) )
107107 return True
108108
109109
110110 def _processQueue (self ):
111111 if self .low_end :
112- self .waitForAbort (170 ) # TODO: wait until no more added to queue?
112+ self .waitForAbort (70 ) # TODO: wait until no more added to queue?
113113 utils .log ("Starting processing queue" , "notice" )
114114
115115 while not self .abortRequested ():
116116 if self .player .isPlayingVideo ():
117117 xbmc .sleep (1000 )
118118 continue
119119 try :
120- res = self .queue .get (timeout = 5 )
120+ hash , path , widget_id = self .queue .get (timeout = 5 )
121121 except queue .Empty :
122+ # TODO: first run of queue. first refresh now?
122123 continue
123- path , hash , widget_id = res ['path' ], res ['hash' ], res ['widget_id' ]
124124 history_path = os .path .join (_addon_data , "{}.history" .format (hash ))
125125 cache_data = utils .read_json (history_path ) if xbmcvfs .exists (history_path ) else None
126126 # class Progress(object):
@@ -433,6 +433,7 @@ def __init__(self):
433433 self .totalTime = - 1
434434 self .playingTime = 0
435435 self .info = {}
436+ self .path = None
436437
437438 def playing_type (self ):
438439 """
@@ -488,6 +489,7 @@ def onPlayBackStarted(self):
488489 self .totalTime = - 1
489490 # self.recordPlay()
490491 self .type = self .playing_type ()
492+ self .path = self .getPlayingFile ()
491493
492494 def update_playback_time (self = self ):
493495 while self .isPlaying ():
@@ -515,9 +517,11 @@ def onPlayBackEnded(self):
515517 self .totalTime = - 1.0
516518 self .playingTime = 0.0
517519 self .info = {}
518- cache .save_playback_history (self .type , pp )
520+ cache .save_playback_history (self .type , pp , self . path )
519521 utils .log ("recorded playback of {}% {}" .format (pp , self .type ), "notice" )
520522
523+ # TODO: find which cache file has self.path in it. This probably would have changed
524+
521525 # wait for a bit so scrobing can happen
522526 # time.sleep(5)
523527 for hash , path in cache .widgets_changed_by_watching (self .type ):
@@ -547,3 +551,13 @@ def onPlayBackSpeedChanged(self, speed):
547551
548552 def onQueueNextItem (self ):
549553 pass
554+
555+ class OrderedSetQueue (queue .Queue ):
556+ def _init (self , maxsize ):
557+ self .queue = {} # Python 3 dict is ordered
558+ def _put (self , item ):
559+ self .queue [item ] = None
560+ def _get (self ):
561+ val = next (iter (self .queue .keys ()))
562+ del self .queue [val ]
563+ return val
0 commit comments