mirror of
https://github.com/Syncplay/syncplay
synced 2024-12-15 19:35:07 +00:00
Improve support for unicode in URL paths
This commit is contained in:
parent
628b9fffa2
commit
7b3efae32b
@ -1,4 +1,4 @@
|
||||
version = '1.4.0'
|
||||
milestone = 'Yoitsu'
|
||||
release_number = '33'
|
||||
release_number = '34'
|
||||
projectURL = 'http://syncplay.pl/'
|
||||
|
@ -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:
|
||||
|
@ -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":
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user