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 threading
import time import time
from syncplay.players.basePlayer import BasePlayer from syncplay.players.basePlayer import BasePlayer
from syncplay import constants from syncplay import constants, utils
from syncplay.messages import getMessage from syncplay.messages import getMessage
import os import os, sys
class MplayerPlayer(BasePlayer): class MplayerPlayer(BasePlayer):
speedSupported = True speedSupported = True
@ -29,6 +29,7 @@ class MplayerPlayer(BasePlayer):
self.quitReason = None self.quitReason = None
self.lastLoadedTime = None self.lastLoadedTime = None
self.fileLoaded = False self.fileLoaded = False
self.delayedFilePath = None
try: try:
self._listener = self.__Listener(self, playerPath, filePath, args) self._listener = self.__Listener(self, playerPath, filePath, args)
except ValueError: except ValueError:
@ -264,7 +265,11 @@ class MplayerPlayer(BasePlayer):
call = [playerPath] call = [playerPath]
if filePath: 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)) call.extend(playerController.getStartupArgs(playerPath))
if args: if args:
call.extend(args) call.extend(args)

View File

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

View File

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

View File

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