WebVideoItem cookies?

Hi,



I am trying to fix my Sputnik plugin, after they changed how the player works.



Sputnik requires a user to be logged in, or else they won’t start playback. I can easily login using the HTTP module, and following HTTP requests shows that I am still logged in.



But when trying to do a WebVideoItem request, it doesn’t send the cookie info gathered from the previous HTTP requests? I guess it is because the WebVideoItem uses a Safari instance?

It could be fixed if the WebVideoItem allowed for post requests as I could send username and password as post in the WebVideoItem url.



Any ideas?



Sune

Hello Sune!



You are correct that cookies are not (yet?) shared between Python and Webkit. That’s why you sometimes need to login twice: once from inside your Python code to get access to certain information and once from inside the Site Config to get access to a video.



Posting forms (for logging in and things like that) is possible inside Site Configs (javascript ftw!)



First we need access to the plugin’s preferences from inside the Site Config to retrieve the stored username and password. To do this you add an identifier attribute to the site tag. The value of this attribute is the same value used for CFBundleIdentifier in the Info.plist of the plugin:



<site site="..."<br />
plugin="..."<br />
identifier="com.plexapp.plugins.sputnik"<br />
initialState="..."<br />
version="1.0">



Now we can grab values of the stored preferences. For example, if the id you gave to the username pref is *my_username*, you can get that with *${my_username}*. You can use those ${} values inside javascripts, for example to fill out a form. Here is an example:


<br />
<run script="<br />
document.getElementById('id_of_the_username_input_field').value="${username}";<br />
document.getElementById('id_of_the_password_input_field').value="${password}";<br />
document.getElementById('id_of_the_form').submit();<br />
" /><br />




You can return to the original videopage by using the "special" *${url}* variable that contains the url that you sent from your WebVideoItem in your Python script:


<visit url="${url}" />



An example of a Site Config that relies heavily on javascript is the one I wrote for [TV4 Anytime](http://github.com/sander1/TV4-Anytime.bundle/blob/master/Contents/Site%20Configurations/TV4%20Anytime.xml). It's not doing exactly the same thing (logging in isn't done by a POST action in this case), but it may give you an idea of how to work with multiple states and javascript inside a Site Config file.

Let me know if you need more help, good luck!

Thanks for the great reply, should be possible to get things working with this approach!



thanks again

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