Plex Transcode API

I’m trying to follow the C# example in Javascript to match what was posted on the blog, but I keep getting a 400 Bad Request and the log file says:

Had trouble breaking X-Plex-Access-Code=3W3wnpyaxPEIfbV+mSg5fPFU3HZHWqRbh9aYfmDAbFU=



My javascript is basically the example given in the blog post but constructs the URL and redirects to it.



<br />
<br />
<script type="text/javascript" src="base64.js"></script><br />
<script type="text/javascript" src="jssha256.js"></script><br />
<script><br />
<br />
function move() {<br />
<br />
part = '/library/parts/1/Jake%20and%20Amir_%20Karate.m4v';<br />
part = encodeURI(part);<br />
myurl = "/video/:/transcode/segmented/start.m3u8?identifier=com.plexapp.plugins.library&ratingKey=97007888&offset=0&quality=5&url=http%3A%2F%2Flocalhost%3A32400" + part + "&3g=0&httpCookies=&userAgent=";<br />
<br />
publicKey = "KQMIY6GATPC63AIMC4R2";<br />
privateKey = decode64("k3U6GLkZOoNIoSgjDshPErvqMIFdE0xMTx8kgsrhnC0=");<br />
time = Math.round(new Date().getTime() / 1000);<br />
<br />
msg = myurl+"@"+time;<br />
redirectURL = msg;<br />
HMAC_SHA256_init(privateKey);<br />
HMAC_SHA256_write(msg);<br />
mac = HMAC_SHA256_finalize();<br />
token = encode64(array_to_string(mac));<br />
<br />
<br />
window.location = 'http://localhost:32400' + redirectURL + "&X-Plex-Access-Key=" + publicKey + "&X-Plex-Access-Time="+ time + "&X-Plex-Access-Code=" + token; <br />
}<br />
<br />
</script><br />
<br />
<body onload="timer=setTimeout('move()',0)"><br />
<br />




It produces something like

http://localhost:32400/video/:/transcode/segmented/start.m3u8?identifier=com.plexapp.plugins.library&ratingKey=97007888&offset=0&quality=5&url=http%3A%2F%2Flocalhost%3A32400/library/parts/1/Jake%2520and%2520Amir_%2520Karate.m4v&3g=0&httpCookies=&userAgent=@1306120533&X-Plex-Access-Key=KQMIY6GATPC63AIMC4R2&X-Plex-Access-Time=1306120533&X-Plex-Access-Code=3W3wnpyaxPEIfbV+mSg5fPFU3HZHWqRbh9aYfmDAbFU=



And in the log file I get


<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG - Request: GET /video/:/transcode/segmented/start.m3u8?identifier=com.plexapp.plugins.library&ratingKey=97007888&offset=0&quality=5&url=http%3A%2F%2Flocalhost%3A32400/library/parts/1/Jake%2520and%2520Amir_%2520Karate.m4v&3g=0&httpCookies=&userAgent=@1306120533&X-Plex-Access-Key=KQMIY6GATPC63AIMC4R2&X-Plex-Access-Time=1306120533&X-Plex-Access-Code=3W3wnpyaxPEIfbV+mSg5fPFU3HZHWqRbh9aYfmDAbFU= [::1] (1 live)<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * identifier => com.plexapp.plugins.library<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * ratingKey => 97007888<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * offset => 0<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * quality => 5<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * url => http://localhost:32400/library/parts/1/Jake%20and%20Amir_%20Karate.m4v<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * 3g => 0<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * httpCookies => <br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * userAgent => @1306120533<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * X-Plex-Access-Key => KQMIY6GATPC63AIMC4R2<br />
May 22, 2011 22:15:33 [0xb038d000] DEBUG -  * X-Plex-Access-Time => 1306120533<br />
May 22, 2011 22:15:33 [0xb038d000] ERROR - Had trouble breaking X-Plex-Access-Code=3W3wnpyaxPEIfbV+mSg5fPFU3HZHWqRbh9aYfmDAbFU=<br />
May 22, 2011 22:15:33 [0xb038d000] ERROR - ERROR: Parsing request failed.<br />
May 22, 2011 22:15:33 [0xb0c08000] DEBUG - Request: GET /favicon.ico [::1] (1 live)<br />
May 22, 2011 22:15:33 [0xb0c08000] DEBUG - Content-Length of /Users/dan/Library/Application Support/Plex/Plex Media Server.app/Contents/Resources/Graphics/favicon.ico is 1150.<br />




Any ideas on what I'm doing wrong here?


I've got a similar problem when testing transcoding against the linux server.
Under Linux the problem seems to be that it generates the following ffmpeg parameter:
-vpre /home/user/Library/Application Support/Plex Media Server/Plug-ins/System.bundle/Contents/Resources/transcode-presets/video-embedded-h264.ffpreset
which is interpreted as different parameters because the path contains spaces which are not escaped/put between quotes.
Is it a Linux specific problem? Is there any workaround? Any way to make Plex use a path without spaces?

Yannick

I know this topic has been silent for more than a year now. But I do have a question about the transcode API. Is it possible to set the offset time for where the transcode has to start? I have a working transcode URL generator in python and a way of playing them. All it needs now is to start from a given offset.

1 Like

Would you be interested in releasing the python source by chance? I am looking into a similar project for more reliable dlna streaming to certain devices.

Would you be interested in releasing the python source by chance? I am looking into a similar project for more reliable dlna streaming to certain devices.

I'ts part of a bigger app that was used as a interface-less plex client for the raspberry pi, before porting plex HT to the pi was started. The code responsible for the transcode url can be found on github, the direct link to the file is: https://github.com/megawubs/pyplex/blob/master/plexAPI/info.py, it's part of my modifications on the existing python plex-api.

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