def resolve(url, debrid='realdebrid'):
    u = url
    u = u.replace('filefactory.com/stream/', 'filefactory.com/file/')
    #control.log("@@@@  REALDEBRID INIT %s ### %s" % (url,debrid))
    try:
        u1 = urlparse.urlparse(url)[1].split('.')
        u1 = u[-2] + '.' + u[-1]
        if status() is False:raise Exception()
        if not debrid == 'realdebrid' and not debrid == True: raise Exception()
        #raise Exception()

        if '' in credentials()['realdebrid'].values(): raise Exception()
        id, secret, token, refresh = credentials()['realdebrid']['id'], credentials()['realdebrid']['secret'], credentials()['realdebrid']['token'], credentials()['realdebrid']['refresh']

        USER_AGENT = 'Kodi Exodus/3.0'

        post = {'link': u}
        headers = {'Authorization': 'Bearer %s' % token, 'User-Agent': USER_AGENT}
        url = 'http://api.real-debrid.com/rest/1.0/unrestrict/link'

        result = client.request(url, post=post, headers=headers, error=True)
        control.log('@@ DEBRID  RESULTS@@ %s' % result)

        result = json.loads(result)

        if 'error' in result and result['error'] == 'bad_token':
            result = client.request('https://api.real-debrid.com/oauth/v2/token', post={'client_id': id, 'client_secret': secret, 'code': refresh, 'grant_type': 'http://oauth.net/grant_type/device/1.0'}, headers={'User-Agent': USER_AGENT}, error=True)
            result = json.loads(result)
            control.log('Refreshing Expired Real Debrid Token: |%s|%s|' % (id, refresh))
            control.log('Refreshing Expired : |%s|' % (result))

            if 'error' in result: return
            token, refresh = result['access_token'], result['refresh_token']

            control.set_setting('realdebrid_token', token)
            control.set_setting('realdebrid_refresh', refresh)

            headers['Authorization'] = 'Bearer %s' % result['access_token']
            result = client.request(url, post=post, headers=headers)
            result = json.loads(result)
        if 'error' in result and result['error'] == 'file_unavailable':
            control.log("@@@@  REALDEBRID FILE UNAVAIL %s ### %s" % (url))

            return

        url = result['download']
        control.log('@@ DEBRID  URl@@ %s' % url)

        return url
    except:
        pass

    try:
        if not debrid == 'premiumize' and not debrid == True: raise Exception()

        if '' in credentials()['premiumize'].values(): raise Exception()
        user, password = credentials()['premiumize']['user'], credentials()['premiumize']['pass']

        url = 'http://api.premiumize.me/pm-api/v1.php?method=directdownloadlink&params[login]=%s&params[pass]=%s&params[link]=%s' % (user, password, urllib.quote_plus(u))
        result = client.request(url, close=False)
        url = json.loads(result)['result']['location']
        return url
    except:
        pass

    try:
        if not debrid == 'alldebrid' and not debrid == True: raise Exception()

        if '' in credentials()['alldebrid'].values(): raise Exception()
        user, password = credentials()['alldebrid']['user'], credentials()['alldebrid']['pass']

        login_data = {'action': 'login', 'login_login': user, 'login_password': password}
        login_link = 'http://alldebrid.com/register/?%s' % login_data
        cookie = client.request(login_link, output='cookie', close=False)

        url = 'http://www.alldebrid.com/service.php?link=%s' % urllib.quote_plus(u)
        result = client.request(url, cookie=cookie, close=False)
        url = client.parseDOM(result, 'a', ret='href', attrs = {'class': 'link_dl'})[0]
        url = client.replaceHTMLCodes(url)
        url = '%s|Cookie=%s' % (url, urllib.quote_plus(cookie))
        return url
    except:
        pass

    try:
        if not debrid == 'rpnet' and not debrid == True: raise Exception()

        if '' in credentials()['rpnet'].values(): raise Exception()
        user, password = credentials()['rpnet']['user'], credentials()['rpnet']['pass']

        login_data = {'username': user, 'password': password, 'action': 'generate', 'links': u}
        login_link = 'http://premium.rpnet.biz/client_api.php?%s' % login_data
        result = client.request(login_link, close=False)
        result = json.loads(result)
        url = result['links'][0]['generated']
        return url
    except:
        return
dataset/ETHPy150Open mrknow/filmkodi/plugin.video.specto/resources/lib/resolvers/realdebrid.py/resolve/original