Improve support for unicode in URL paths

This commit is contained in:
Et0h 2016-12-04 19:41:22 +00:00
parent 628b9fffa2
commit 7b3efae32b
5 changed files with 50 additions and 7 deletions

View File

@ -1,4 +1,4 @@
version = '1.4.0'
milestone = 'Yoitsu'
release_number = '33'
release_number = '34'
projectURL = 'http://syncplay.pl/'

View File

@ -443,8 +443,10 @@ class SyncplayClient(object):
def updateFile(self, filename, duration, path):
newPath = u""
if utils.isURL(path):
filename = path
try:
filename = path.encode('utf-8')
except UnicodeDecodeError:
filename = path
if not path:
return
try:

View File

@ -136,6 +136,11 @@ class VlcPlayer(BasePlayer):
self._listener.sendLine('set-playstate: {}'.format("paused" if value else "playing"))
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)
@ -151,7 +156,7 @@ class VlcPlayer(BasePlayer):
normedPath = os.path.normpath(filePath)
if os.path.isfile(normedPath):
filePath = normedPath
if utils.isASCII(filePath):
if utils.isASCII(filePath) and not utils.isURL(filePath):
self._listener.sendLine('load-file: {}'.format(filePath.encode('ascii', 'ignore')))
else:
fileURL = self.getMRL(filePath)
@ -185,6 +190,9 @@ class VlcPlayer(BasePlayer):
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":

View File

@ -343,7 +343,7 @@ class MainWindow(QtGui.QMainWindow):
if filename:
if filename == getMessage("nofile-note"):
return constants.FILEITEM_SWITCH_NO_SWITCH
if self._syncplayClient.userlist.currentUser.file and filename == self._syncplayClient.userlist.currentUser.file['name']:
if self._syncplayClient.userlist.currentUser.file and utils.sameFilename(filename,self._syncplayClient.userlist.currentUser.file['name']):
return constants.FILEITEM_SWITCH_NO_SWITCH
if isURL(filename):
return constants.FILEITEM_SWITCH_STREAM_SWITCH
@ -417,6 +417,10 @@ class MainWindow(QtGui.QMainWindow):
filename = user.file['name']
if isURL(filename):
filename = urllib.unquote(filename)
try:
filename = filename.decode('utf-8')
except UnicodeEncodeError:
pass
filenameitem = QtGui.QStandardItem(filename)
fileSwitchState = self.getFileSwitchState(user.file['name']) if room == currentUser.room else None
if fileSwitchState != constants.FILEITEM_SWITCH_NO_SWITCH:
@ -819,6 +823,12 @@ class MainWindow(QtGui.QMainWindow):
self.updatingPlaylist = True
for URI in URIsToAdd:
URI = URI.rstrip()
try:
URI = URI.encode('utf-8')
except UnicodeDecodeError:
pass
URI = urllib.unquote(URI)
URI = URI.decode('utf-8')
if URI <> "":
self.addStreamToPlaylist(URI)
self.updatingPlaylist = False

View File

@ -164,9 +164,16 @@ def blackholeStdoutForFrozenWindow():
def stripfilename(filename, stripURL):
if filename:
try:
filename = filename.encode('utf-8')
except UnicodeDecodeError:
pass
filename = urllib.unquote(filename)
if stripURL:
filename = filename.split(u"/")[-1]
try:
filename = urllib.unquote(filename.split(u"/")[-1])
except UnicodeDecodeError:
filename = urllib.unquote(filename.split("/")[-1])
return re.sub(constants.FILENAME_STRIP_REGEX, "", filename)
else:
return ""
@ -181,7 +188,15 @@ def stripRoomName(RoomName):
return ""
def hashFilename(filename, stripURL = False):
return hashlib.sha256(stripfilename(filename, stripURL).encode('utf-8')).hexdigest()[:12]
if isURL(filename):
stripURL = True
strippedFilename = stripfilename(filename, stripURL)
try:
strippedFilename = strippedFilename.encode('utf-8')
except UnicodeDecodeError:
pass
filenameHash = hashlib.sha256(strippedFilename).hexdigest()[:12]
return filenameHash
def hashFilesize(size):
return hashlib.sha256(str(size)).hexdigest()[:12]
@ -197,6 +212,14 @@ def sameHashed(string1raw, string1hashed, string2raw, string2hashed):
return True
def sameFilename (filename1, filename2):
try:
filename1 = filename1.encode('utf-8')
except UnicodeDecodeError:
pass
try:
filename2 = filename2.encode('utf-8')
except UnicodeDecodeError:
pass
stripURL = True if isURL(filename1) ^ isURL(filename2) else False
if filename1 == constants.PRIVACY_HIDDENFILENAME or filename2 == constants.PRIVACY_HIDDENFILENAME:
return True