Problem with german umlauts / new trailers function

Hey there,

 

PlexConnect is great and i love it. But i'm a bit unhappy with the trailer function an tmdb. A lot of movie trailer are not found on tmdb and that would be found are in english. I want trailers in german. So, now im learning a bit python and thought, try to rebuild the trailer function. Well, i found out all the trailer code is in javascript :P

 

Now i've rewritten the trailers.js, that it search and get trailers directly from youtube, possibly in any language, but the lange is "hardcoded" in the url string yet.

/*
 * lookup movie title on tmdb and pass trailer ID to PlexConnect
 */
function playTrailer(title,year)
{
    var google_api_key = "PutGoogleApiKeyHere";
	var lookup = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=1&order=relevance&key="+google_api_key+"&q="+encodeURIComponent(title+" "+year+" trailer deutsch");
var req = new XMLHttpRequest();
req.open('GET', lookup, false);
req.send();

var doc = JSON.parse(req.responseText);

if (doc.items[0].id.videoId.length === 0)
{
    XML_Error("{{TEXT(PlexConnect)}}", "{{TEXT(Youtube: Kein Trailer gefunden)}}");
    return;
}

var id = doc.items[0].id.videoId;
var url = "{{URL(/)}}&PlexConnect=PlayTrailer&PlexConnectTrailerID="+id;
atv.loadURL(url);

};

/*

  • displays error message
    */
    function XML_Error(title,desc)
    {
    var errorXML =
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    \ \ \ " + title + " \ " + desc + " \ \ \

";
var doc = atv.parseXML(errorXML);
atv.loadXML(doc);
};

Now, i figured out a Problem with german umlauts and special chars like [ ], that was before also. If there german umlauts in the title, the trailer function won't started. The Problem, the PrePlay.xml is parsed with the umlauts in the function call:

                

I don't know, where or how the Video/title is created, but for the Button the german umlauts have to changed and special chars removed.

 

Second thing, maybe someone want to include this to the project, so he can add a var to the config for trailer language and get this var in the  trailers.js youtube search url and add a public google api key.

 

First thing, i hope the german umlauts and special char problem can be done by ibaa in the project :)

 

regards

Manuel

When using "{{VAL_QUOTED(Video/title)}}" as shown, there should be no "Umlauts" in the resulting XML. Are there really some in there? The Quoting is actually done to make the title "URL safe", I think that should kind of make it "JS safe" as well.

Do you have a produced XML (found in the log)?

Hey Baa, i don't changed anything on the PrePlay.xml and i don't really know, if umlauts in {{VAL_QUOTED(Video/title)}}.

But, on all Movies with umlauts (and i see with [ ] ) in the title won't load the trailers.js.

I testet this by putting a XML_Error(title,year) in the first line of the PlayTrailer function in trailers.js, and i get no output on all this movies with umlauts and the special chars. On movies without this it works fine. So something went wrong with umlauts.

Again, please post a log (or a snipped thereof) that we can have a look at the produced XML.

Here is what happens in Log with umlauts. The ? is a german ö

23:01:14 XMLConverter: XML_ExpandLine: {{VAL(title)}}
23:01:14 XMLConverter: CCmds_getParam: title, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: G?tz vorm Haus,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: G?tz vorm Haus
23:01:14 XMLConverter: XML_ExpandLine: G?tz vorm Haus - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(key)}}
23:01:14 XMLConverter: CCmds_getParam: key, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: /library/metadata/16537,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: /library/metadata/16537
23:01:14 XMLConverter: XML_ExpandLine: /library/metadata/16537 - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(title)}}
23:01:14 XMLConverter: CCmds_getParam: title, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: G?tz vorm Haus,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: G?tz vorm Haus
23:01:14 XMLConverter: XML_ExpandLine: G?tz vorm Haus - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(year:?)}}
23:01:14 XMLConverter: CCmds_getParam: year, ?
23:01:14 XMLConverter: CCmds_getParam: ?, 
23:01:14 XMLConverter: CCmds_getKey: 2014,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: 2014
23:01:14 XMLConverter: XML_ExpandLine: 2014 - done

and here what happens with a special char [ ]

23:01:14 XMLConverter: XML_ExpandLine: {{VAL(title)}}
23:01:14 XMLConverter: CCmds_getParam: title, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: [DER] 1: Movie,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: [DER] 1: Movie
23:01:14 XMLConverter: XML_ExpandLine: [DER] 1: Movie - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(key)}}
23:01:14 XMLConverter: CCmds_getParam: key, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: /library/metadata/16458,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: /library/metadata/16458
23:01:14 XMLConverter: XML_ExpandLine: /library/metadata/16458 - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(title)}}
23:01:14 XMLConverter: CCmds_getParam: title, 
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getKey: [DER] 1: Movie,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: [DER] 1: Movie
23:01:14 XMLConverter: XML_ExpandLine: [DER] 1: Movie - done
23:01:14 XMLConverter: XML_ExpandLine: {{VAL(year:?)}}
23:01:14 XMLConverter: CCmds_getParam: year, ?
23:01:14 XMLConverter: CCmds_getParam: ?, 
23:01:14 XMLConverter: CCmds_getKey: 2014,,False
23:01:14 XMLConverter: CCmds_getParam: , 
23:01:14 XMLConverter: CCmds_getConversion: [],
23:01:14 XMLConverter: CCmds_applyConversion: 2014
23:01:14 XMLConverter: XML_ExpandLine: 2014 - done

Logfile or terminal print out? The terminal really is not able to display all those fancy unicode characters...

At least in the PrePlay screen (here Trailer button...), on my side those German characters don't translate into a simple question mark:


That is a Logifle print out.

How did you get the output of PrePlay?

As i sad, tested with a absolute blank install of plexconnect too, i can't play trailers with umlauts or some special chars.

The PlayTrailer function in trailers.js isn't called.

It's in the logs. Find "XMLTemplate: Movie/PrePlay.xml" then further down "generated aTV-XML" to skip all the XMLConverter debug output.

Got to check what happen when pressing this button, though. :-)

Ah ok, i found it. Looks good i think.


So i don't understand, why it won't work. Have you try'd to play the trailer for this movie?

Maybe the are a problem in javascript?

When playing that trailer:

In the logs:

21:54:32 ATVLogger: playTrailer: Kokow%C3%A4%C3%A4h+Mkv 

On aTV/TV:

"TheMovieDB: No trailer info available"

My take: It can't be the name...

Not sure how that movie would be named in TheMovieDB - Hm. "Kokowaah", but then it really doesn't show a trailer in that database.

Could it be this one ?

https://www.themoviedb.org/movie/53174-kokow-h?language=de

When playing that trailer:

In the logs:

21:54:32 ATVLogger: playTrailer: Kokow%C3%A4%C3%A4h+Mkv 

On aTV/TV:

"TheMovieDB: No trailer info available"

My take: It can't be the name...

Not sure how that movie would be named in TheMovieDB - Hm. "Kokowaah", but then it really doesn't show a trailer in that database.

hmm :(   i don't understand why i won't work on my plexconnect. 

yes, it is the movie.

I tested again with a very simple change.

function playTrailer(title,year)
{

XML_Error(“Test”,“works”);




On any movie without umlauts or special vars, i see the message on my atv. On movies with umlauts nothing happens, it stay's on PrePlay Screen without doing something.

I don't understand... are you using modified py, js, xml files, or some modified versions when seeing the "trailers won't work with umlauts" issue? Or does it happen with the stock files as well?

Nope, i have nothing modified. That’s all the original files from your git repo.


I only modified the PlayTrailer function as above, to figure out if she is executed. But she isn’t.


And I found today, that all signs that are not be letters breaks it. ,?!’- all this signs won’t work.

Baa, can you tell me where the values for PrePlay.xml are generated? Maybe i can try a bit on this function with replace some characters.

So, i figured something out.

i changed in PrePlay.xml (PrePlay_Fanart.xml) the following


to this


and it works perfectly with all umlauts and special chars, except Movies with ' in the title.

I removed the "_QUOTED".

So, the ' have to be replaced but umlauts not and i don't know where i can do this.

The output looks like this after this change, with a german ö:

onPlay="playTrailer('Götz vorm Haus','2014')

I still don't understand.

Modifying Movie/PrePlay line 110 to 

<actionButton id="playTrailer" onSelect="playTrailer('Umlauts-!§$%C3%A4%C3%A4','{{VAL(Video/year)}}')"

works perfectly fine. When adding your change

    XML_Error("{{TEXT(PlexConnect)}}", title);

to js/trailers.js/playTrailer(), aTV will as well show "Umlauts-!§$%C3%A4%C3%A4".

Why wouldn't that work on your side? What OS do you run PlexConnect on? Is there some other application "in between", like a web server with forwarding on a NAS?

If you don't quote the string, you might get in trouble sending it over to youtube in the query string. At that point the title has to be "URL safe".

I have a ubuntu server running. On this machine is the PlexMediaserver and Plexconnect running. No Forwardings, no NAS, no other Webserver.

The sting quote isn't needed in PrePlay, because it is done in trailers.js

encodeURIComponent("Film " +title+" "+year+" Trailer Deutsch German")

I don't know why, but the string quote in PrePlay is a problem on my machine, perhaps because of the % sign. I had this issue with some movies always before i did some changes, but never thought about it until i did my recoding for youtube trailers.

As i sayd, without this all works perfect, except the ' because it closes the string zu early :) There must be a quote only for this sign, but i don't know where to do this. So i removed all ' from movie titles where it was, so every thing is fine. 

And, at least for german, the direct youtube trailer search i much much better. I have only found 3 movies from about 100 where a trailer was played only in english and only 1 movie where no trailer was found.

Can you tell me, how i can get a value from a sting from Settings.cfg to trailers.js?

And, how only the ' in PrePlay could be quoted?

Maybe we can make the language setting more useable and include it sometime in plexconnect :)

>>Can you tell me, how i can get a value from a sting from Settings.cfg to trailers.js?

Settings.cfg? Or rather ATVSettings.cfg? The latter one should be lie a {{VAL($setting)}} - or {{SETTING(setting)}}. This would write it into the XML, eg. as JS function call parameter, then you can grab it from JS code.

 

>>And, how only the ' in PrePlay could be quoted?

\' maybe?

 

>>Maybe we can make the language setting more useable and include it sometime in plexconnect  :)

Have you had a play with the PMS based trailers? I would rather rely on PMS for content delivery...