Help writing a new resolver plugin

samu-rai

New member
Nov 15, 2013
14
0
0
Hi Guys

I'm trying to write a plugin for mediafire, but after a few days of trial and error I don't seem to be getting any further, and thought I would ask the experts :)

My script is as follow. I'd be grateful to anyone who could take a look for me:

Code:
from t0mm0.common.net import Net
from urlresolver.plugnplay.interfaces import UrlResolver
from urlresolver.plugnplay.interfaces import PluginSettings
from urlresolver.plugnplay import Plugin
from urlresolver import common
import re, urllib2, os, xbmcgui, xbmc

net = Net()

error_logo = os.path.join(common.addon_path, 'resources', 'images', 'logo.png')
datapath = common.profile_path

class MediaFireResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "mediafire"

    
	
    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()

		
    def get_media_url(self, host, media_id):
        url = self.get_url(host, media_id)

        website = urllib2.urlopen(url)

        html = website.read()

        link = re.search(r'http://download[0-9].[\'"]?([^\'" >])+', html)
        if link:
            return link.groups(0)
        else:
            return

    def get_url(self, host, media_id):
        return 'http://www.mediafire.com/download/%s' % media_id

    def get_host_and_id(self, url):
        r = re.search('//(.+?)/([0-9a-zA-Z]+)', url)
        if r:
            return r.groups()
        else:
            return False

    def valid_url(self, url, host):
        return (re.match('http://(www.)?mediafire.com/download/' +
                                 '[0-9A-Za-z]+', url) or 
				 'mediafire' in host)
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
Would be easier for us if you give us more details on what issues you are hitting, errors etc.

The code looks rather simple, so I'm assuming you don't have a method to get the final link yet?
 

samu-rai

New member
Nov 15, 2013
14
0
0
Thanks for the reply Eldorado.

I've only just started learning to code, hence why it's so simple :)

But having tested:

Code:
url = "http://www.mediafire.com/download/example12345/test.mp4"

website = urllib2.urlopen(url)

html = website.read()

link = re.search(r'http://download[0-9].[\'"]?([^\'" >])+', html)
if link:
     print link.group(0)
else:
     pass
in the interpreter, I get the desired resolved link.

I then add that code to my plugin (as above) and call a mediafire url through urlresolver.

The log shows that the resolver calls my plugin correctly, but then returns the following error:

Leaving Python method 'XBMCAddon_xbmc_Player_play'. Exception from call to 'play' 'Non api type passed to "play" in place of the expected type "p.XBMCAddon::xbmc::playList."' ... returning NULL
As the code is so simple I must be making a basic mistake, but I can't for the like of me figure out what.

Edit: Scrap that. It looks like I need to reassess my regex, as sometimes the interpreter finds the link and sometimes it doesn't :confused:
 
Last edited: