Ejemplo n.º 1
0
 def openFile(self, filePath, resetPosition=False):
     if not utils.isURL(filePath):
         normedPath = os.path.normpath(filePath)
         if os.path.isfile(normedPath):
             filePath = normedPath
     if utils.isASCII(filePath) and not utils.isURL(filePath):
         self._listener.sendLine('load-file: {}'.format(filePath.encode('ascii', 'ignore')))
     else:
         fileURL = self.getMRL(filePath)
         self._listener.sendLine('load-file: {}'.format(fileURL))
Ejemplo n.º 2
0
    def getMRL(self, fileURL):
        if utils.isURL(fileURL):
            fileURL = urllib.parse.quote(fileURL, safe="%/:=&?~#+!$,;'@()*")
            return fileURL

        fileURL = fileURL.replace('\\', '/')
        fileURL = fileURL.encode('utf8')
        fileURL = urllib.parse.quote_plus(fileURL)
        if isWindows():
            fileURL = "file:///" + fileURL
        else:
            fileURL = "file://" + fileURL
        fileURL = fileURL.replace("+", "%20")
        return fileURL
Ejemplo n.º 3
0
    def getMRL(self, fileURL):
        if utils.isURL(fileURL):
            fileURL = fileURL.encode('utf8')
            fileURL = urllib.quote(fileURL, safe="%/:=&?~#+!$,;'@()*[]")
            return fileURL

        fileURL = fileURL.replace(u'\\', u'/')
        fileURL = fileURL.encode('utf8')
        fileURL = urllib.quote_plus(fileURL)
        if sys.platform.startswith('win'):
            fileURL = "file:///" + fileURL
        else:
            fileURL = "file://" + fileURL
        fileURL = fileURL.replace("+", "%20")
        return fileURL
Ejemplo n.º 4
0
 def openFile(self, filePath, resetPosition=False):
     self._client.ui.showDebugMessage("openFile, resetPosition=={}".format(resetPosition))
     if resetPosition:
         self.lastResetTime = time.time()
         if isURL(filePath):
             self.lastResetTime += constants.STREAM_ADDITIONAL_IGNORE_TIME
     self._loadFile(filePath)
     if self._paused != self._client.getGlobalPaused():
         self._client.ui.showDebugMessage("Want to set paused to {}".format(self._client.getGlobalPaused()))
     else:
         self._client.ui.showDebugMessage("Don't want to set paused to {}".format(self._client.getGlobalPaused()))
     if resetPosition == False:
         self.setPosition(self._client.getGlobalPosition())
     else:
         self._storePosition(0)
Ejemplo n.º 5
0
    def getMRL(self, fileURL):
        if utils.isURL(fileURL):
            fileURL = fileURL.encode('utf8')
            fileURL = urllib.quote(fileURL, safe="%/:=&?~#+!$,;'@()*[]")
            return fileURL

        fileURL = fileURL.replace(u'\\', u'/')
        fileURL = fileURL.encode('utf8')
        fileURL = urllib.quote_plus(fileURL)
        if sys.platform.startswith('win'):
            fileURL = "file:///" + fileURL
        else:
            fileURL = "file://" + fileURL
        fileURL = fileURL.replace("+", "%20")
        return fileURL
Ejemplo n.º 6
0
 def openFile(self, filePath, resetPosition=False):
     self._client.ui.showDebugMessage("openFile, resetPosition=={}".format(resetPosition))
     if resetPosition:
         self.lastResetTime = time.time()
         if isURL(filePath):
             self._client.ui.showDebugMessage("Setting additional lastResetTime due to stream")
             self.lastResetTime += constants.STREAM_ADDITIONAL_IGNORE_TIME
     self._loadFile(filePath)
     if self._paused != self._client.getGlobalPaused():
         self._client.ui.showDebugMessage("Want to set paused to {}".format(self._client.getGlobalPaused()))
     else:
         self._client.ui.showDebugMessage("Don't want to set paused to {}".format(self._client.getGlobalPaused()))
     if resetPosition == False:
         self._client.ui.showDebugMessage("OpenFile setting position to global position: {}".format(self._client.getGlobalPosition()))
         self.setPosition(self._client.getGlobalPosition())
     else:
         self._storePosition(0)
Ejemplo n.º 7
0
    def lineReceived(self, line):
        try:
            self._client.ui.showDebugMessage("player << {}".format(line))
        except:
            pass
        match, name, value = self.RE_ANSWER.match(line), "", ""
        if match:
            name, value = match.group('command'), match.group('argument')

        if line == "filepath-change-notification":
            self._filechanged = True
            t = threading.Thread(target=self._onFileUpdate)
            t.setDaemon(True)
            t.start()
        elif name == "filepath":
            self._filechanged = True
            if value == "no-input":
                self._filepath = None
            else:
                if "file://" in value:
                    value = value.replace("file://", "")
                    if not os.path.isfile(value):
                        value = value.lstrip("/")
                elif utils.isURL(value):
                    value = urllib.unquote(value)
                    value = value.decode('utf-8')
                self._filepath = value
            self._pathAsk.set()
        elif name == "duration":
            if value == "no-input":
                self._duration = 0
            elif value == "invalid-32-bit-value":
                self._duration = 0
                self.drop(getMessage("vlc-failed-versioncheck"))
            else:
                self._duration = float(value.replace(",", "."))
            self._durationAsk.set()
        elif name == "playstate":
            self._paused = bool(value != 'playing') if (
                value != "no-input" and self._filechanged
                == False) else self._client.getGlobalPaused()
            if self._paused == False \
            and self._position == self._previousPreviousPosition \
            and self._previousPosition == self._position \
            and self._duration > constants.PLAYLIST_LOAD_NEXT_FILE_MINIMUM_LENGTH \
            and self._position == self._duration:
                self._paused = True
                self._client.ui.showDebugMessage(
                    "Treating 'playing' response as 'paused' due to VLC EOF bug"
                )
            self._pausedAsk.set()
        elif name == "position":
            newPosition = float(value.replace(
                ",", ".")) if (value != "no-input" and self._filechanged
                               == False) else self._client.getGlobalPosition()
            if newPosition == self._previousPosition and newPosition <> self._duration and not self._paused:
                self._client.ui.showDebugMessage(
                    "Not considering position {} duplicate as new time because of VLC time precision bug"
                    .format(newPosition))
                self._positionAsk.set()
                return
            self._previousPreviousPosition = self._previousPosition
            self._previousPosition = self._position
            self._position = newPosition
            if self._position < 0 and self._duration > 2147 and self._vlcVersion == "3.0.0":
                self.drop(getMessage("vlc-failed-versioncheck"))
            self._lastVLCPositionUpdate = time.time()
            self._positionAsk.set()
        elif name == "filename":
            self._filechanged = True
            self._filename = value.decode('utf-8')
            self._filenameAsk.set()
        elif line.startswith("vlc-version: "):
            self._vlcVersion = line.split(': ')[1].replace(' ',
                                                           '-').split('-')[0]
            if not utils.meetsMinVersion(self._vlcVersion,
                                         constants.VLC_MIN_VERSION):
                self._client.ui.showErrorMessage(
                    getMessage("vlc-version-mismatch").format(
                        constants.VLC_MIN_VERSION))
            self._vlcready.set()
Ejemplo n.º 8
0
    def lineReceived(self, line):
        try:
            self._client.ui.showDebugMessage("player << {}".format(line))
        except:
            pass
        match, name, value = self.RE_ANSWER.match(line), "", ""
        if match:
            name, value = match.group('command'), match.group('argument')

        if line == "filepath-change-notification":
            self._filechanged = True
            t = threading.Thread(target=self._onFileUpdate)
            t.setDaemon(True)
            t.start()
        elif name == "filepath":
            self._filechanged = True
            if value == "no-input":
                self._filepath = None
            else:
                if "file://" in value:
                    value = value.replace("file://", "")
                    if not os.path.isfile(value):
                        value = value.lstrip("/")
                elif utils.isURL(value):
                    value = urllib.unquote(value)
                    value = value.decode('utf-8')
                self._filepath = value
            self._pathAsk.set()
        elif name == "duration":
            if value == "no-input":
                self._duration = 0
            elif value == "invalid-32-bit-value":
                self._duration = 0
                self.drop(getMessage("vlc-failed-versioncheck"))
            else:
                self._duration = float(value.replace(",", "."))
            self._durationAsk.set()
        elif name == "playstate":
            self._paused = bool(value != 'playing') if(value != "no-input" and self._filechanged == False) else self._client.getGlobalPaused()
            if self._paused == False \
            and self._position == self._previousPreviousPosition \
            and self._previousPosition == self._position \
            and self._duration > constants.PLAYLIST_LOAD_NEXT_FILE_MINIMUM_LENGTH \
            and self._position == self._duration:
                self._paused = True
                self._client.ui.showDebugMessage("Treating 'playing' response as 'paused' due to VLC EOF bug")
            self._pausedAsk.set()
        elif name == "position":
            newPosition = float(value.replace(",", ".")) if (value != "no-input" and self._filechanged == False) else self._client.getGlobalPosition()
            if newPosition == self._previousPosition and newPosition <> self._duration and not self._paused:
                self._client.ui.showDebugMessage("Not considering position {} duplicate as new time because of VLC time precision bug".format(newPosition))
                self._positionAsk.set()
                return
            self._previousPreviousPosition = self._previousPosition
            self._previousPosition = self._position
            self._position = newPosition
            if self._position < 0 and self._duration > 2147 and self._vlcVersion == "3.0.0":
                self.drop(getMessage("vlc-failed-versioncheck"))
            self._lastVLCPositionUpdate = time.time()
            self._positionAsk.set()
        elif name == "filename":
            self._filechanged = True
            self._filename = value.decode('utf-8')
            self._filenameAsk.set()
        elif line.startswith("vlc-version: "):
            self._vlcVersion = line.split(': ')[1].replace(' ','-').split('-')[0]
            if not utils.meetsMinVersion(self._vlcVersion, constants.VLC_MIN_VERSION):
                self._client.ui.showErrorMessage(getMessage("vlc-version-mismatch").format(constants.VLC_MIN_VERSION))
            self._vlcready.set()