URLService help

Hello all,

 

I am creating a channel for http://saiyanwatch.com/

 

I have populated the menus in the __init__.py  and that works

 

I am having issues with creating a URL service. For some reason I cannot test it using the URL

 

http://localhost:32400/system/services/url/lookup?url=INSERT_TEST_URL

 

 

The url i am using is

 

http://localhost:32400/system/services/url/lookup?url=http%3A%2F%2Fsaiyanwatch.com%2Fdragonball%2Fdb1%2F

 

I get a blank screen when doing so.

 

 

When i try

http://localhost:32400/:/plugins/com.plexapp.system/serviceTestURLs/com.plexapp.plugins.saiyanwatch 

 

I get 

 

 

This is my ServiceCode.pys

import re

def MetadataObjectForURL(url):
pageContent = HTML.ElementFromURL(url)
title = pageContent.xpath("//meta[@property=‘og:title’]/@content")
return EpisodeObject(
title = title
)

def MediaObjectsForURL(url):
return [
MediaObject(
audio_codec = AudioCodec.AAC,
video_codec = VideoCodec.H264,
container = ‘mp4’,
parts = [PartObject(key=Callback(PlayVideo, url=url))])]

def NormalizeURL(url):
return url

@indirect
def PlayVideo(url):
Log(url)
BASE_URL = "http://saiyanwatch.com/wp-admin/admin-ajax.php?"
URL_ACTION = “action=outofthebox-getplaylist&”
URL_SORT = “lastpath=%2F&sort=name%3Aasc&”

tokenRegex = "data-token=\\'[a-z,0-9]*\\'"
jsonRegex = "var\soutofthebox_vars\s=\s{.*}"

pageContent = HTTP.Request(url).content
token = re.search(tokenRegex, pageContent, re.IGNORECASE).group()[11:].replace("'", "").strip()

jsonVar = re.search(jsonRegex, pageContent, re.IGNORECASE).group()[23:].strip()
jsonObj = JSON.ObjectFromString(jsonVar)
nonce = jsonObj["getplaylist_nonce"]   

fileUrl = BASE_URL + URL_ACTION + URL_SORT + "listtoken=" + token + "&_ajax_nonce=" + nonce


videoObj = JSON.ObjectFromString(HTTP.Request(fileUrl).content[1:-1])

finalVidUrl = videoObj["m4v"]
                  
return IndirectResponse(VideoClipObject, key=finalVidUrl)

def TestURLs():
test_urls =
test_urls.append(“http://saiyanwatch.com/dragonball/db1/”)
test_urls.append(“http://saiyanwatch.com/dragonball/db3/”)
return test_urls

This is my ServiceInfo.plist

<?xml version="1.0" encoding="UTF-8"?>



    URL
        
            SaiyanWatch
                
                    URLPatterns
                        
                            http://([^.]+.)?saiyanwatch.com/.+ 		
                        
                    TestURLs
                        
                            http://saiyanwatch.com/dragonball/db2/
                        
            
        


My directories:

 

Contents > Services >  ServiceInfo.plist

Contents > Services > URL > SaiyanWatch > ServiceCode.pys

I don't see anything strange ...

Have you tried restarting PMS? Sometimes this is required in order to pickup changes in plugins(especially when doing changes in service code)

... looking a little bit more you should probably change this line

title = pageContent.xpath("//meta[@property='og:title']/@content")

into

title = pageContent.xpath("//meta[@property='og:title']/@content")[0]

When debugging service code, the com.plexapp.system.log is a very good place to look for errors etc ..

Thanks for your reply.


I didn’t restart PMS when I updated the code.


Ill try out your suggestions when I get home. I was wondering why I didn’t see any errors in my bundles log. I only saw that it found a matching service.

Alright, so I restarted PMS and it works lol.

I feel like an idiot, thanks a lot though! :D

Do you plan on releasing this channel? Let me know if so! Thanks!