0

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.

  • 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. – graham Mar 03 '22 at 20:56
  • @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. – Abdullah AL Shohag Mar 03 '22 at 21:01

0 Answers0