mpv can't be run with UTF-8 filepath in Windows, so load UTF-8 files via API instead

This commit is contained in:
Et0h 2015-02-17 23:21:31 +00:00
parent fd6d15790a
commit a4b35431fa
4 changed files with 15 additions and 8 deletions

View File

@ -3,9 +3,9 @@ import re
import threading
import time
from syncplay.players.basePlayer import BasePlayer
from syncplay import constants
from syncplay import constants, utils
from syncplay.messages import getMessage
import os
import os, sys
class MplayerPlayer(BasePlayer):
speedSupported = True
@ -29,6 +29,7 @@ class MplayerPlayer(BasePlayer):
self.quitReason = None
self.lastLoadedTime = None
self.fileLoaded = False
self.delayedFilePath = None
try:
self._listener = self.__Listener(self, playerPath, filePath, args)
except ValueError:
@ -264,7 +265,11 @@ class MplayerPlayer(BasePlayer):
call = [playerPath]
if filePath:
call.extend([filePath])
if sys.platform.startswith('win') and not utils.isASCII(filePath):
self.__playerController.delayedFilePath = filePath
filePath = None
else:
call.extend([filePath])
call.extend(playerController.getStartupArgs(playerPath))
if args:
call.extend(args)

View File

@ -137,6 +137,8 @@ class NewMpvPlayer(OldMpvPlayer):
self._client.updatePlayerStatus(self._paused, self._position)
def _preparePlayer(self):
if self.delayedFilePath:
self.openFile(self.delayedFilePath)
self.setPaused(True)
self.reactor.callLater(0, self._client.initPlayer, self)

View File

@ -121,11 +121,8 @@ class VlcPlayer(BasePlayer):
fileURL = fileURL.replace("+", "%20")
return fileURL
def _isASCII (self, s):
return all(ord(c) < 128 for c in s)
def openFile(self, filePath, resetPosition=False):
if self._isASCII(filePath):
if utils.isASCII(filePath):
self._listener.sendLine('load-file: {}'.format(filePath.encode('ascii', 'ignore')))
else:
fileURL = self.getMRL(filePath)
@ -250,7 +247,7 @@ class VlcPlayer(BasePlayer):
self.__playerController = playerController
call = [playerPath]
if filePath:
if self.__playerController._isASCII(filePath):
if utils.isASCII(filePath):
call.append(filePath)
else:
call.append(self.__playerController.getMRL(filePath))

View File

@ -108,6 +108,9 @@ def formatSize (bytes, precise=False):
except: # E.g. when filesize is hashed
return "???"
def isASCII(s):
return all(ord(c) < 128 for c in s)
def findWorkingDir():
frozen = getattr(sys, 'frozen', '')
if not frozen: