Kodi Community Forum
Solved how to save/extract data from "url" plugin:// - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+---- Forum: PVR (https://forum.kodi.tv/forumdisplay.php?fid=136)
+---- Thread: Solved how to save/extract data from "url" plugin:// (/showthread.php?tid=366377)



how to save/extract data from "url" plugin:// - Kangool - 2022-01-07

hi i am working on an stalker client for mz own
livetv is working but with the vod i have a little bit problems

save the js to file is not a problem but it takes a verlz long time cuy must send request for every single page wich
onlz gives data back for 14items

çmost portals have about 10000 items in the vod section so need to send about 700 request...thats too much

so i want to usw "get_category" so i only need to load onlz choosen categorz ( movie german, movie english and so on)

to create the folder for the vod streams i use this function

python:
def GenresVOD():

    try:
        data = vod.getGenresVOD(portal['mac'], portal['url'], portal['serial'], addondir);
        
    except Exception as e:
        xbmcgui.Dialog().notification(addonname, str(e), xbmcgui.NOTIFICATION_ERROR );
        
        return;

    data = data['genresVOD'];
    
    
    for id, i in list(data.items()):

        title     = i["title"];
        category     = i["genre"];
        

        
        url = build_url({
            'mode': 'channelsVOD',
            'genre_name': title.title(),
            'id': category,  i want to get this number
            'portal' : json.dumps(portal)
            });   
            
        li = xbmcgui.ListItem(title.title())
        xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li, isFolder=True);
        

    xbmcplugin.endOfDirectory(addon_handle);

this send an "url" with informations to another function

in build url i take the rigth id wich i want to use how i can extract/read the url 
Quote:plugin://plugin.video.stalkerportal/?genre_name=Movie: Netherlands &;id=365&;mode=channelsVOD&;portal={"parental": "", "password": "", "name": "24.02.2022", "url": "http://portalurl", "mac": "my mac", "serial": null
in this example i need to take out the number 365

to use it in another script
here:

category : here i need the number

python:
def getVoDchannels(portal_mac, url, serial, path):    
    now = time();
    portalurl = "_".join(re.findall("[a-zA-Z0-9]+", url));
    portalurl = path + '/' + portalurl + '-vodchannels';
    
    setMac(portal_mac);
    setSerialNumber(serial);
    
    if not os.path.exists(path):
        os.makedirs(path)
    
    if os.path.exists(portalurl):
        with open(portalurl) as data_file: data = json.load(data_file);
    
    handshake(url);
    
    data=data1
    
    data = '{ "version" : "' + cache_version + '", "time" : "' + str(now) + '", "vodchannels" : [  \n'
    
    page = 1;

    while True:
        info = retrieveData(url, values = {
            'type' : 'vod', 
            'action' : 'get_ordered_list',
            'sortby' : 'year',
            'not_ended' : '0',
            'category' : here i need the number,
            'p' : page,
            'fav' : '0',
            'JsHttpRequest' : '1-xml'})
        
        results = info['js']['data']

        for i in results:
            name     = i["name"]
            cmd     = i['cmd']
            logo     = i["screenshot_uri"]
            category_id     = i["category_id"]
            
            data += '{"name":"'+ name +'", "cmd":"'+ cmd +'", "logo":"'+ logo +'"}, \n'

        page += 1;
        if page > pages or page == 200:
            break;

    data = data[:-3] + '\n]}'

    with open(portalurl, 'wb') as f: f.write(data.encode('utf-8'));
    
    return json.loads(data.encode('utf-8'));

sorry for my bad englisch and my dirty code...
it was not mz code i onlz updated it to pzthon3 and change it for my own use....i am not realy a programmer
please can somebody help me


RE: how to save/extract data from "url" plugin:// - DarrenHill - 2022-01-07

Thread moved to PVR addons


RE: how to save/extract data from "url" plugin:// - M89SE - 2022-01-08

Why can't you use the id from the for loop? or is there an id in the json request? Check what the json list(data.items() contains.

python:
for id, i in list(data.items()):
    # check what is in json, xbmc.log('json: {}'.format(i),level=xbmc.LOGNOTICE)
    title     = i["title"];
    category     = i["genre"];

    url = build_url({
        'mode': 'channelsVOD',
        'genre_name': title.title(),
        'id': id, #
        'portal' : json.dumps(portal)
        })



RE: how to save/extract data from "url" plugin:// - black_eagle - 2022-01-08

Using your url as an example, can you not do something like this?
python:
from urllib.parse import urlparse, parse_qs
url = 'plugin://plugin.video.stalkerportal/?genre_name=Movie: Netherlands &;id=365&;mode=channelsVOD&;portal={"parental": "", "password": "", "name": "24.02.2022", "url": "http://portalurl", "mac": "my mac", "serial": null'
parsed_url = urlparse(url)
queries = parse_qs(parsed_url.query)
print(queries[';id'])

>>> ['365']




RE: how to save/extract data from "url" plugin:// - Kangool - 2022-01-09

got it

python:
def getVoDchannels(portal_mac, url, serial, path):
    args = urllib.parse.parse_qs(sys.argv[2][1:])
    id     = args['id'][0];

thanks for your help


how to save/extract data from "url" plugin:// - black_eagle - 2022-01-09

Glad you've got it sorted.

Thread marked solved.