Special chars in Play() command failing
#1
hi,

i am having some trouble getting python to play a file with special characters in the name. here is the path that is trying to play:
xbms://192.168.0.1/tv3_alla älskar raymond_200512061440p3919.mpg

the problem was originally found because an exception was being thrown when i was trying to convert it to an ascii string to use in the xbmc.player().play() command as it does not seem to work unless i format the variable as a string. eg:

fnamenew = "xbms://" + mpsettings.ip + "/" + fnamenew[1]
p = xbmc.player()
p.play(str(fnamenew))

to get around this problem i am encoding the variable to utf-8 which works fine for all files without any special characters using the following:

fnamenew = "xbms://" + mpsettings.ip + "/" + fnamenew[1]
p = xbmc.player()
p.play(fnamenew.encode('utf_8'))

the variable is taken from an xml string which was already utf-8 encoded so it should be fine.

however now after converting the string to utf-8 i get an error in xbmc error log saying that the file can not be found. the log file has a different filename in it as it mis-represents the special character; this may be an issue with the encoding of the log though, not sure. i have checked what is passed to the emulation script on my dev machine and it prints out the path that i have included at the start of my problem.

i had a quick look at using the http api but could not get it to work. the file plays fine if i browse to it using my videos.

i am new to all this language and encoding stuff so any help would be greatly appreciated.
Reply
#2
ok, i have been debugging this for weeks and have still not made any progress. i am sure that i am missing something here and my mediaportal scripts are suffering as i am stuck with this issue.

i have included a test case which fails on my machine and am hoping someone can help me out please, im beggin this is doing my head in. :veryangry:

ok, quick run down on what this part of the script has to do.
* receives a filename and path to a video from xml
* has to extract the filename and drop the path.
* add xbmp:// path to filename
* play the file using the new path.

test.xml
------------------------------
Quote:<?xml version="1.0" encoding="utf-8"?><filename>e:\video\tv\tv3_alla älskar raymond_200512061440p3919.mpg</filename>

testfail.py
------------------------------
Quote:from xml.dom import minidom
import os
import xbmc

dom = minidom.parse('q:/scripts/test.xml')
rootnode = dom.documentelement

node = rootnode.firstchild
fname = node.data

fnamenew = os.path.split(fname)
fnamenew = 'xbms://192.168.0.1/' + fnamenew[1]

p = xbmc.player()
p.play(fnamenew)
---------------------------
with testfail.py nothing happens and file is not played. no errors are recieved and xbox is left running fine with no crash. also no other files will play until i convert the fnamenew variable using str() which obviously fails due to the special character.

now if i was to directly declare the same file name that is in the xml file in the script it will work fine, even without str() around fnamenew.

testok.py
---------------------------
Quote:import xbmc
import os

fname = 'e:\video\tv\tv3_alla älskar raymond_200512061440p3919.mpg'

fnamenew = os.path.split(fname)
fnamenew = 'xbms://192.168.0.1/' + fnamenew[1]

p = xbmc.player()
p.play(fnamenew)

i anyone can help with this i would be very grateful. also if i can provide any further details please let me know.

regards,

chad
Reply

Logout Mark Read Team Forum Stats Members Help
Special chars in Play() command failing0