// https://www.youtube.com/watch?v=HzqnQThFSX8&list=RDHzqnQThFSX8&start_radio=1 function ytdl() { var ytid = ""; var url = document.getElementById("url").value; if (url === "") { alert("Please enter a URL"); return; } if (url.includes("youtube.com/watch?v=")) { var ytid_prep1 = url.split("="); if (ytid_prep1[1].includes("&")) { var ytid_prep2 = ytid_prep1[1].split("&"); var ytid = ytid_prep2[0]; } else { var ytid = ytid_prep1[1]; } } else if (url.includes("youtu.be/")) { var ytid_prep1 = url.split(".be/"); var ytid = ytid_prep1[1]; } else { alert("URL is not compliant with this website - I am kinda sorry(Just kidding)"); } add_db(ytid); return; } function add_db(ytid) { var base_url = "http://localhost:8000/api/get/"; var url = base_url.concat(ytid); console.log(url); send_get(url); //fetch(url).then(res => res.json()).then(data => console.log(data)); //.catch(res => console.log("Failed: " + res)) //return; } function send_get(url){ fetch(url) .then(response => { // indicates whether the response is successful (status code 200-299) or not if (!response.ok) { throw new Error(`Request failed with status ${reponse.status}`) } else { console.log(response.body) } return response.json() }) }