Source

VPlayer / bitrateresolver.py



from time import sleep
from collections import deque

from PyQt4 import QtCore

from vplayer.logger import log

class BitrateResolver(QtCore.QThread):
    def __init__(self):
        QtCore.QThread.__init__(self)
        self.queue = deque()
        self.active = True

    def add(self, track):
        #was = False
        #for item in self.queue:
        #    if item.url == track.url:
        #        was = True
        #        break
        #if not was:
        self.queue.append(track)

    def remove(self, track):
        if track in self.queue:
            try:
                self.queue.remove(track)
            except:
                pass

    def run(self):
        while self.active:
            if self.queue:
                track = self.queue[0]
                if track.got_size:
                    self.queue.popleft()
                    continue
                #log.debug("Resolvind bitrate for " + unicode(track))
                track.get_filesize()
                try: self.queue.popleft()
                except: pass
                if track.filesize is None:
                    track.got_size = False
                    self.add(track)
                sleep(0.01)
                continue
            sleep(0.1)