Skip to content Skip to sidebar Skip to footer

Open Json File Link Through A Code

I'm creating an addon and I'm modifying some functions that come within a py file. What I intend to do is the following, I have this code: This code gives access to a lib.json fil

Solution 1:

Given that your link holds valid json - which is not the case with the content you posted - you could use requests.

If the content at dropbox looked liked this:

{"tv": 
    {"epg": "tv",
    "streams": 
        [{"url": "http://topchantv.net:3456/live/Stalker/Stalker/838.m3u8", 
        "name": "IPTV", 
        "resolve": False, 
        "visible": True}], 
    "name": "tv", 
    "thumb": "thumb_tv.png"
    }
}

Then fetching the content would be like this

import requests

url = 'https://www.dropbox.com/s/sj1246qtiodm6qd/lib.json?dl=1'
r = requests.get(url)
json_object = r.json()

So if you needed it inside a function, I guess you'd input the url and return the json like so:

def channellist(url):
    r = requests.get(url)
    json_object = r.json()
    return json_object 

Post a Comment for "Open Json File Link Through A Code"