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.