Sign up here and you can log into the forum!

upnp-cmd and apostrophes

This is the place to ask for how to use software that is (or isn't) included in the various wdlxtv flavours. Questions about software such as rtorrent, NZBGet, sshfs, curlftpfs, ssh, telnet, etc.

upnp-cmd and apostrophes   

Postby Darren » Fri Mar 25, 2011 8:27 am

I have some automation that uses upnp-cmd to start video file playback, and all is working fine except for files that have apostrophes in their names.

I am using the command with both arguments "upnp-cmd SetAVTransportURI <URI> <URIMetaData>" because I found that specifying only the URI does not set the current file name/title on the wdtv playback gui, and it uses the name of the last file played instead. So I'm also including the URIMetaData in its <DIDL-Lite> tag to set the file's title to show correctly on the gui.

I can't find a way to properly escape the file URI inside the URIMetaData. It appears to require the file URI to be include in the child <res> tag, and I think this is where I need to escape that apostrophe. I've tried the typical methods, like &apos; or \' or %27 but then the wdtv either leaves those entities untouched or double-escapes them.

I looked inside the upnp-cmd php file and its passing the URIMetaData through htmlentities(), but that function doesn't do anything to apostrophes.

If I manually play the file using the regular wdtv remote, and then run "upnp-cmd GetMediaInfo" via telnet, it shows the apostrophe escaped as %27. But the question is, how do I format the URIMetaData so that the wdtv receives the apostrophe in the format it needs?

Thanks

Here's an example of the URIMetaData I'm testing with:

Code: Select all
$meta = '<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item><dc:title>' . 'Test' . '</dc:title><upnp:class>object.item.videoItem</upnp:class><res  protocolInfo="file-get:*:video/x-matroska::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000">' . 'file:///tmp/media/usb/USB1/A02CCBB62CCF93BE/Video/A Midsummer\'s Nice Dreams.mkv' . '</res></item></DIDL-Lite>';
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Re: upnp-cmd and apostrophes   

Postby recliq » Fri Mar 25, 2011 10:21 am

Code: Select all
' => '\''
:ugeek:
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5035
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: upnp-cmd and apostrophes   

Postby Darren » Fri Mar 25, 2011 4:28 pm

Thanks, that's the first thing I had tried, and is in the example I included :-)

I guess using
Code: Select all
'\''

is equivalent to using
Code: Select all
"'"

and either one of those methods is sending the apostrophe as a "raw" character, which the wdtv apparently will not process. If I send such an unencoded apostrophe in the <res> tag then the wdtv does not process the SetAVTransportURI command at all. It just ignores the command.

Edit:
I just did some more testing:
In the <title> tag it does not like the escaped (\') apostrophe, but encoding it as &apos; works fine.
However, using either method in the <res> tag fails. And when I use &apos; in this tag then it gets converted to %26apos%3B

Btw, when I google for "xml apostrophe" it looks like plenty of people have (sometimes platform-specific) issues with properly encoding this character for xml consumption. It depends on the parsing engine.
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Re: upnp-cmd and apostrophes   

Postby RMerlin » Fri Mar 25, 2011 5:32 pm

Darren wrote:Btw, when I google for "xml apostrophe" it looks like plenty of people have (sometimes platform-specific) issues with properly encoding this character for xml consumption. It depends on the parsing engine.


Yay for non-standard standards! Almost makes you think it was designed by Microsoft or something.
WDLXTV Webend maintainer. Visit http://www.lostrealm.ca/wdlxtv to see my other WDLXTV projects.
If you like my work, please consider donating.
User avatar
RMerlin
WDLXTV Team
 
Posts: 3236
Joined: Sat Jun 26, 2010 9:25 am
Location: Montreal, Canada

Re: upnp-cmd and apostrophes   

Postby recliq » Sat Mar 26, 2011 2:13 am

Darren wrote:Thanks, that's the first thing I had tried, and is in the example I included :-)

I guess using
Code: Select all
'\''

is equivalent to using
Code: Select all
"'"

and either one of those methods is sending the apostrophe as a "raw" character, which the wdtv apparently will not process. If I send such an unencoded apostrophe in the <res> tag then the wdtv does not process the SetAVTransportURI command at all. It just ignores the command.

Edit:
I just did some more testing:
In the <title> tag it does not like the escaped (\') apostrophe, but encoding it as &apos; works fine.
However, using either method in the <res> tag fails. And when I use &apos; in this tag then it gets converted to %26apos%3B

Btw, when I google for "xml apostrophe" it looks like plenty of people have (sometimes platform-specific) issues with properly encoding this character for xml consumption. It depends on the parsing engine.

Well
Code: Select all
'\''

obviously is different from
Code: Select all
"'"

and your example does not include my proposal.
try this:
Code: Select all
$meta = '<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item><dc:title>A Midsummer'\''s Nice Dreams</dc:title><upnp:class>object.item.videoItem</upnp:class><res  protocolInfo="file-get:*:video/x-matroska::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000">file:///tmp/media/usb/USB1/A02CCBB62CCF93BE/Video/A Midsummer'\''s Nice Dreams.mkv</res></item></DIDL-Lite>';
­WDLXTV Project Maintainer
-:] If you like my contributions feel free to donate for a beer or a new flash drive. ...and always remember: RTFM! (README, FAQ, WIKI) [:-
User avatar
recliq
WDLXTV Team
 
Posts: 5035
Joined: Thu Apr 15, 2010 8:09 am
Location: Kiel, Germany

Re: upnp-cmd and apostrophes   

Postby zoster » Sat Mar 26, 2011 3:24 am

How/where do you pass the $meta variable?
This works for aaa'bbb.avi :

Code: Select all
function _actionSetMeta($prmURI = '') {
    $meta  = '<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/">';
    $meta .= '<item id="dummy1" parentID="dummy0" restricted="0">';
    $meta .= '<dc:title>aaa\'bbb</dc:title>';
    $meta .= '<dc:date></dc:date>';
    $meta .= '<upnp:class>object.item.videoItem</upnp:class>';
    $meta .= '<dc:creator></dc:creator>';
    $meta .= '<upnp:genre></upnp:genre>';
    $meta .= '<upnp:album></upnp:album>';
    $meta .= '<res protocolInfo="*:*:video/x-msvideo:*"  resolution="512X384"  colorDepth="0" >file:///tmp/aaa\'bbb.avi</res>';
    $meta .= '</item>';
    $meta .= '</DIDL-Lite>';
   
    $action = 'SetAVTransportURI';
    $args   = '<InstanceID>0</InstanceID>' . "\r\n";
    $args  .= '<CurrentURI>' . $prmURI . '</CurrentURI>' . "\r\n";
    $args  .= '<CurrentURIMetaData>' . htmlentities($meta) . '</CurrentURIMetaData>' . "\r\n";
    $result = _sendUPnPCommand($action, $args, 'AVTransport');
}
zoster
WDLXTV Team
 
Posts: 218
Joined: Wed Apr 14, 2010 10:14 am

Re: upnp-cmd and apostrophes   

Postby PaulF » Sat Mar 26, 2011 12:08 pm

I am on vacation, posting on my phone so I can't test.
Try: $meta = htmlentities(xxx);
User avatar
PaulF
Developer
 
Posts: 422
Joined: Sat May 08, 2010 8:34 pm
Location: Oregon

Re: upnp-cmd and apostrophes   

Postby Darren » Sat Mar 26, 2011 2:02 pm

recliq wrote:...your example does not include my proposal.
try this:
Code: Select all
$meta = '<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><item><dc:title>A Midsummer'\''s Nice Dreams</dc:title><upnp:class>object.item.videoItem</upnp:class><res  protocolInfo="file-get:*:video/x-matroska::DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=00000000001000000000000000000000">file:///tmp/media/usb/USB1/A02CCBB62CCF93BE/Video/A Midsummer'\''s Nice Dreams.mkv</res></item></DIDL-Lite>';


Sorry, I didn't understand what you meant when you suggested (' => '\''). Your proposal does not close the string properly. If I greatly simplify the example meta string, you'd get something like this:
Code: Select all
$meta = '<tag>Title'\''s Text</tag>';

which could be interpreted as
Code: Select all
$meta = '<tag>Title'
\'
's Text</tag>';

Its hard to say how it would be interpreted, but there should be only one string.
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Re: upnp-cmd and apostrophes   

Postby Darren » Sat Mar 26, 2011 4:29 pm

zoster wrote:How/where do you pass the $meta variable?
This works for aaa'bbb.avi :


You're right! If I embed my strings directly inside the upnp-cmd php file then it works! So now I need to track down why the values are not getting there...

I'm passing the variables on the command for upnp-cmd SetAVTransportURI URI URIMeta
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Re: upnp-cmd and apostrophes   

Postby Darren » Sat Mar 26, 2011 4:33 pm

PaulF wrote:I am on vacation, posting on my phone so I can't test.
Try: $meta = htmlentities(xxx);


Thanks, I tried that too, although the SetAVTransportURI command already uses this for the meta value. It looks like htmlentities() only encodes for amp, quot, lt, gt. It does not do anything with apostrophes.
Darren
DLX'er
 
Posts: 69
Joined: Sat Jun 19, 2010 3:35 pm

Next

Return to Application Questions

Who is online

Users browsing this forum: No registered users and 2 guests