Best Practices

Hi,
The Documentation is insufficient and I didn’t find some good examples.

  1. What’s the best practice to pass a Cookie to the Url Service?
  2. Exists there any more documentation about the framework besides the ones linked here in the Sticky?
  3. Is ‘Cookie = GetCookiesForURL(url)’ possible? Or do I have to go down the road to manually deconstruct a returned response header? I find it extremely irritating to use the build in functions the whole time and when there’s one case where the documentation lacks information I end up having to import urllib and requests to get one piece of logic done. I really need the cookie to retrieve the video url.
  4. Can the URL Service Access the Data API feeded with Data from the main Plugin?
  5. Can a global Search Service return a directory object?

It would be extremely helpful, if someone experienced could answer my questions.

1-I don’t think you can pass anything to the url service besides the url. Some channels like YouTubeTV create custom urls for the urlservice which can include extra data. like http://something.that.doesnt.exist/?foo=bar&cookie=stuff

You could try skipping using a url service entirely.

if you do something like this in channel code I think its pretty much the equivalent of using url= on an object.

oc.add(VideoClipObject(
        key = Callback(MetadataObjectForURL, url=url, cookie="TEST"),
        rating_key = url,
        items = MediaObjectsForURL(url=url, cookie="TEST")
))

then you can define MetadataObjectForURL and MediaObjectsForURL in your channel code and pass them anything you want.

2-The only documentation I’ve found is the PlexPlug-inFramework.pdf and the undocumented stuff in the google docs sticky.

3-HTTP.CookiesForURL(url) should get you the cookie data. I needed a value from a cookie once so I did

r = HTTP.Request(url=LOGIN_URL, headers=headers, values=payload)

pattern = Regex('hash=([^;]*)')
hash = pattern.search(HTTP.CookiesForURL(LOGIN_URL)).group(1)
Dict['hash'] = hash
Dict.Save()

4-I don’t think the URL Service can access anything from the channel (Dict, Data, Prefs, etc)

5-I don’t know about global search, I’ve just been putting a Search(query) function in my channel code and using an InputDirectoryObject to call it. I think global search would have stricter requirements on what you return.

Thanks for your response.

First I went with encoding the cookie and appending him to the url passed to the service where I stripped the encoded cookie and decoded him again.

It was a pain in the ass, so I stripped the the URL Service entireley!

Thanks for your answer.