How to decode filename from metadata XML?

I’m using the following to get the filename in a metadata agent, when search or update is called:


pageUrl = "http://localhost:32400/library/metadata/" + media.id<br />
xml = XML.ElementFromURL(pageUrl)<br />
nfoXML = xml.xpath('//Part')[0]<br />
path1 = nfoXML.get('file')<br />
Log('file = ' + path1)<br />



My problem is that when the filename contains accented characters, the filename I get with this looks like:
"De pe%CC%80re en flic.mpg"

How can I convert "pe%CC%80re" back to the original "père" ?

Thanks.


This works for me:

<br />
>>> from urllib2 import unquote<br />
>>> file_path = "pe%CC%80re"<br />
>>> file_path = unquote(file_path).decode('utf-8')<br />
>>> file_path<br />
u'pe\u0300re'<br />
>>> print file_path<br />
père<br />


Use String.Unquote() - importing non-framework modules is generally frowned upon :wink:



Well, that method:
http://dev.plexapp.com/docs/api/utilkit.html#String.Unquote
is only available when the python code is running as an agent or plugin. I missed that fact! My code snippet came from some of my own "external" scripts that interact with the pms ;)

In other words, use the built in Unquote function if you can!

Thank you very much. Updated both XBMC (TV & Movies) metadata agents to use that, instead of the dumb search-and-replace method I created while testing!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.