Score:0

Syntax Error on accessing JSON data in QML data from python youtube_dl

cn flag

I have a simple youtube_dl function to access the youtube download links here,

@QtCore.Slot(str, result=str)
def getDownloadLinks(self, url):
    try:
        with youtube_dl.YoutubeDL({}) as ydl:
            result = ydl.extract_info(url, download=False)
        if "entries" in result:
            videos = result["entries"][0]
        else:
            videos = result
        r_videos = []
        for video in videos["formats"]:
            r_videos.append({"url": video["url"], "format": video["format"], "size": video["filesize"]})
        resRet = {"status":"true", "urls": r_videos}
        return str(resRet)
    except Exception as e:
        resRet = {"status":"true", "error": str(e)}
        return str(resRet)

And I am trying to access it in a QML file which has a function like this which access this python function by calling it like this.

function getLinks(url){
    jsonString = downloadeng.getDownloadLinks(url)
    console.log(jsonString)
    var jsonObject = JSON.parse(jsonString)
    var anObject = JSON.parse(jsonObject)

    if (anObject.status == 'false') {
        //open Popup
        console.log("opening popup")
    } else {
        console.log(anObject.url)
    }
}

But every time I get syntax error like this SyntaxError: JSON.parse: Parse error indicating var anObject = JSON.parse(jsonObject) this line. Another thing is that I am parsing the JSON twice as it errors on one parse but works fine on second parse. Please help me with this two things.

24601 avatar
in flag
YouTube quite often change their program set often requiring programs to be amended too. Beyond that, I can't really help except as to suggest you have a look at DL-YOUTUBE PRO (which uses Python Version 0.1). The free version can be downloaded from the ubuntu software centre (the paid version which is regularly updated is not that expensive - just a few $USD). You might want to try it.
cn flag
@24601, It's not really something with youtube_ds as far as I am concerned. If I return some plain text instead of any json data it works just fine. I am just not able to use the proper way of transmitting json data from python to qml.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.