Kodi Community Forum

Full Version: TVShow episode request via JSON
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi at all,

I try check via fsonrpc if a TVShow episode is in db or not...
If I understand right for this I would need the tvshowid by name.
So I tried:

Code:
def TVShowName2TVShowDBID(tvshowname):
    query = {
            "jsonrpc": "2.0",
            "method": "VideoLibrary.GetTVShows",
            "params": {
                "properties": ["originaltitle", "tvshowid"]
            },
            "id": "libTvShows"
            }
    
    res = json.loads(xbmc.executeJSONRPC(json.dumps(query, encoding='utf-8')))
    writeLog("JSON returns: %s" % (res), level=xbmc.LOGDEBUG)
     try:
        if 'result' in res and 'tvshows' in res['result']:
            res = res['result']['tvshows']
            for tvshow in res:
                if tvshow['label'] == tvshowname:
                    return tvshow['tvshowid']

        return False
    except Exception:
        writeLog("JSON query returns an error", level=xbmc.LOGDEBUG)
        return False

but it allways returning "FALSE" but it's for sure that the tvshow is in the db...

I don't know were I'm wrong...
okay, get it work...

first i try to get tvshowid
Code:
query = {
            "jsonrpc": "2.0",
            "method": "VideoLibrary.GetTVShows",
            "params": {
                "properties": ["originaltitle", "imdbnumber"]
            },
            "id": "libTvShows"
            }
    
    res = json.loads(xbmc.executeJSONRPC(json.dumps(query, encoding='utf-8')))
    
    try:
        if 'result' in res and 'tvshows' in res['result']:
            res = res['result']['tvshows']
            for tvshow in res:
                if tvshow['label'] == tvshowname:
                    return tvshow['tvshowid']

        return False
    except Exception:
        writeLog("JSON query returns an error", level=xbmc.LOGDEBUG)
        return False

and than i take the tvshowid and look for the season and episode

Code:
def SeasonAndEpisodeInDB(tvshowid, season, episode):
    query = {
            "jsonrpc": "2.0",
            "method": "VideoLibrary.GetEpisodes",
            "params": {
                "tvshowid": tvshowid,
                "properties": ["season", "episode"]
            },
            "id": "libEpisodes"
            }
    
    res = json.loads(xbmc.executeJSONRPC(json.dumps(query, encoding='utf-8')))
#    writeLog("JSON returns: %s" % (res), level=xbmc.LOGDEBUG)
    try:
        if 'result' in res and 'episodes' in res['result']:
            res = res['result']['episodes']
            for episo in res:
                if episo['season'] == season and episo['episode'] == episode:
                    return True
        return False
    except Exception:
        writeLog("JSON query returns an error", level=xbmc.LOGDEBUG)
        return False
PLease Help Me AS i am New to python,and working on my 2nd video Addon ,

And video links are on this site

http://ok.ru/videoembed/93942254125

and tihs link work only in browser but not in Vlc as a test



So:

How can i include this To My Addon
i found Answer But not sure how to include it in my Addon
Code:
import urllib, urllib2, urlparse, re, json

HEADERS = {
    'User-Agent':      'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36',
    'Accept':          'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Cache-Control': 'no-transform'
}

def http_req(url, getCookie=False, data=None, customHeader=None):
    if data: data = urllib.urlencode(data)
    req = urllib2.Request(url, data, HEADERS)
    if customHeader:
        req = urllib2.Request(url, data, customHeader)
    response = urllib2.urlopen(req)
    source = response.read()
    response.close()
    if getCookie:
        cookie = response.headers.get('Set-Cookie')
        return {'source': source, 'cookie': cookie}
    return source

sources = []

mirrorUrl = 'http://www.ok.ru/videoembed/36530555610'

try:
    id = re.search('\d+', mirrorUrl).group(0)
    u = urlparse.urlparse(mirrorUrl)
    hostUrl = '://'.join([u.scheme, u.netloc])
    jsonUrl = 'http://ok.ru/dk?cmd=videoPlayerMetadata&mid=' + id
    jsonSource = json.loads(http_req(jsonUrl))

    quality = {
        'mobile': '144p',
        'lowest':  '240p',
        'low':      '360p',
        'sd':       '480p',
        'hd':       '720p',
        'full':      '1080p'
    }
    
    for source in jsonSource['videos']:
        q = source['name'].strip()
        q = quality.get(q, None)
        if not q:
            continue
        name = '%s %s' % ('[ok.ru]', q)
            'User-Agent':   HEADERS['User-Agent'],
            'Referer':      mirrorUrl,
            'Origin':       hostUrl
        }
        params = '&'.join(['%s=%s' % (k, urllib.quote_plus(v)) for k, v in params.iteritems()])
        link = '%s|%s' % (source['url'], params)
        
        item = {'name': name, 'url': link}
        sources.append(item)
except:
    pass

print sources

or shoulg i make it as util.pay and how to import it to my default.py