# URLService help

**URL:** <https://forums.plex.tv/t/urlservice-help/98342>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [March 29, 2015, 8:41pm UTC](https://forums.plex.tv/t/urlservice-help/98342 "2015-03-29T20:41:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![raptore](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@raptore](https://forums.plex.tv/u/raptore)\
**Post date:** [March 29, 2015, 8:41pm UTC](https://forums.plex.tv/t/urlservice-help/98342/1 "2015-03-29T20:41:22Z")

</div>

Hello all,

&nbsp;

I am creating a channel for&nbsp;[http://saiyanwatch.com/](http://saiyanwatch.com/)

&nbsp;

I have populated the menus in the \_\_init\_\_.py &nbsp;and that works

&nbsp;

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

&nbsp;

[http://localhost:32400/system/services/url/lookup?url=INSERT\_TEST\_URL](http://localhost:32400/system/services/url/lookup?url=INSERT_TEST_URL)

&nbsp;

&nbsp;

The url i am using is

&nbsp;

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

&nbsp;

I get a blank screen when doing so.

&nbsp;

&nbsp;

When i try

[http://localhost:32400/:/plugins/com.plexapp.system/serviceTestURLs/com.plexapp.plugins.saiyanwatch&nbsp;](http://localhost:32400/:/plugins/com.plexapp.system/serviceTestURLs/com.plexapp.plugins.saiyanwatch%C2%A0)

&nbsp;

I get&nbsp;

&nbsp;

&nbsp;

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?"](http://saiyanwatch.com/wp-admin/admin-ajax.php?%22)  
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/](http://saiyanwatch.com/dragonball/db1/)”)  
test\_urls.append(“[http://saiyanwatch.com/dragonball/db3/](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:

&nbsp;

Contents \> Services \> &nbsp;ServiceInfo.plist

Contents \> Services \> URL \> SaiyanWatch \> ServiceCode.pys

---

<div class="post-metadata">

**Author:** ![meo](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/meo/32/4534_2.png) [@meo](https://forums.plex.tv/u/meo)\
**Post date:** [March 29, 2015, 9:17pm UTC](https://forums.plex.tv/t/urlservice-help/98342/2 "2015-03-29T21:17:31Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![meo](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/meo/32/4534_2.png) [@meo](https://forums.plex.tv/u/meo)\
**Post date:** [March 29, 2015, 9:31pm UTC](https://forums.plex.tv/t/urlservice-help/98342/3 "2015-03-29T21:31:38Z")

</div>

... 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 ..

---

<div class="post-metadata">

**Author:** ![raptore](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@raptore](https://forums.plex.tv/u/raptore)\
**Post date:** [March 29, 2015, 10:35pm UTC](https://forums.plex.tv/t/urlservice-help/98342/4 "2015-03-29T22:35:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![raptore](https://avatars.discourse-cdn.com/v4/letter/r/7feea3/32.png) [@raptore](https://forums.plex.tv/u/raptore)\
**Post date:** [March 30, 2015, 2:57am UTC](https://forums.plex.tv/t/urlservice-help/98342/5 "2015-03-30T02:57:02Z")

</div>

Alright, so I restarted PMS and it works lol.

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

---

<div class="post-metadata">

**Author:** ![Roborobp](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Roborobp](https://forums.plex.tv/u/Roborobp)\
**Post date:** [August 14, 2015, 6:57pm UTC](https://forums.plex.tv/t/urlservice-help/98342/6 "2015-08-14T18:57:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [January 8, 2020, 7:48pm UTC](https://forums.plex.tv/t/urlservice-help/98342/7 "2020-01-08T19:48:03Z")

</div>


