2022-05-11 00:47:22 +02:00
|
|
|
// 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) {
|
2022-06-08 23:23:57 +02:00
|
|
|
var base_url = "http://localhost:8000/api/get/";
|
2022-05-11 00:47:22 +02:00
|
|
|
var url = base_url.concat(ytid);
|
|
|
|
console.log(url);
|
2022-06-08 23:23:57 +02:00
|
|
|
send_get(url);
|
|
|
|
//fetch(url).then(res => res.json()).then(data => console.log(data));
|
2022-05-11 00:47:22 +02:00
|
|
|
//.catch(res => console.log("Failed: " + res))
|
2022-06-08 23:23:57 +02:00
|
|
|
//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()
|
|
|
|
})
|
|
|
|
|
2022-05-11 00:47:22 +02:00
|
|
|
}
|