mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-10-29 18:00:23 +00:00
Updated thumbnailchecking
- Borrowing youtube 404 image for now if someone tries to trick the server to use other thumbnail than soundlcoud thumbnail when adding soundcloud song - Setting thumbnail in db even for youtube-videos, for more consistency
This commit is contained in:
@@ -209,6 +209,13 @@ function addPlaylist(arr, guid, offline, socket) {
|
||||
if(this_element.start > this_element.end) {
|
||||
this_element.start = 0;
|
||||
}
|
||||
if(this_element.source == "soundcloud") {
|
||||
if(this_element.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || this_element.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
|
||||
this_element.thumbnail = this_element.thumbnail;
|
||||
} else {
|
||||
this_element.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
|
||||
}
|
||||
} else if(this_element.source == "youtube") this_element.thumbnail = "https://img.youtube.com/vi/" + this_element.id + "/mqdefault.jpg";
|
||||
if(now_playing) {
|
||||
now_playing = false;
|
||||
}
|
||||
@@ -392,7 +399,13 @@ function add_function(arr, coll, guid, offline, socket) {
|
||||
np = false;
|
||||
}
|
||||
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video", "source": source};
|
||||
if(source == "soundcloud") new_song.thumbnail = arr.thumbnail;
|
||||
if(source == "soundcloud") {
|
||||
if(arr.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || arr.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
|
||||
new_song.thumbnail = arr.thumbnail;
|
||||
} else {
|
||||
new_song.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
|
||||
}
|
||||
} else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
|
||||
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
|
||||
new_song._id = "asd";
|
||||
if(np) {
|
||||
|
||||
@@ -245,23 +245,26 @@ var List = {
|
||||
|
||||
check_error_videos: function(i) {
|
||||
//Helper.log("Empty-checker at " + i);
|
||||
if(full_playlist.length == 0 || full_playlist[i].source == "soundcloud") return;
|
||||
Helper.ajax({
|
||||
method: "get",
|
||||
url: 'https://www.googleapis.com/youtube/v3/videos?id=' + full_playlist[i].id
|
||||
+ "&key=" + api_key + "&part=snippet",
|
||||
success: function (data) {
|
||||
data = JSON.parse(data);
|
||||
//Helper.log("Empty-checker items " + data.items.length);
|
||||
if (data.items.length == 0) {
|
||||
Helper.log(["Emtpy-checker error at " + full_playlist[i].id + " " + full_playlist[i].title]);
|
||||
socket.emit("error_video", {channel: chan.toLowerCase(), id: full_playlist[i].id, title: full_playlist[i].title, source: full_playlist[i].source});
|
||||
if(full_playlist.length == 0) return;
|
||||
else if(full_playlist[i].source == "soundcloud" && full_playlist.length > i + 1 && window.location.pathname != "/") List.check_error_videos(i + 1);
|
||||
else {
|
||||
Helper.ajax({
|
||||
method: "get",
|
||||
url: 'https://www.googleapis.com/youtube/v3/videos?id=' + full_playlist[i].id
|
||||
+ "&key=" + api_key + "&part=snippet",
|
||||
success: function (data) {
|
||||
data = JSON.parse(data);
|
||||
//Helper.log("Empty-checker items " + data.items.length);
|
||||
if (data.items.length == 0) {
|
||||
Helper.log(["Emtpy-checker error at " + full_playlist[i].id + " " + full_playlist[i].title]);
|
||||
socket.emit("error_video", {channel: chan.toLowerCase(), id: full_playlist[i].id, title: full_playlist[i].title, source: full_playlist[i].source});
|
||||
}
|
||||
if(full_playlist.length > i + 1 && window.location.pathname != "/") {
|
||||
List.check_error_videos(i + 1);
|
||||
}
|
||||
}
|
||||
if(full_playlist.length > i + 1 && window.location.pathname != "/") {
|
||||
List.check_error_videos(i + 1);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
dynamicContentPageJumpTo: function(page) {
|
||||
|
||||
@@ -1306,7 +1306,7 @@ addListener("click", ".result-object", function(e){
|
||||
var start = parseInt(e.querySelector(".result-start").value);
|
||||
var end = parseInt(e.querySelector(".result-end").value);
|
||||
var source = "youtube";
|
||||
var thumbnail;
|
||||
var thumbnail = "https://img.youtube.com/vi/" + id + "/mqdefault.jpg";
|
||||
if(e.getAttribute("data-type-source") != undefined) {
|
||||
source = "soundcloud";
|
||||
thumbnail = e.getAttribute("data-type-thumbnail");
|
||||
|
||||
@@ -372,7 +372,7 @@ var Search = {
|
||||
|
||||
if((!not_matched)){
|
||||
matched = true;
|
||||
Search.readySubmit(true, { id: data.id, title: data.snippet.title, source: "youtube", duration: duration, totalLength: totalNumber - 1});
|
||||
Search.readySubmit(true, { id: data.id, title: data.snippet.title, source: "youtube", thumbnail: "https://img.youtube.com/vi/" + data.id + "/mqdefault.jpg", duration: duration, totalLength: totalNumber - 1});
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -615,7 +615,7 @@ addVideos: function(ids){
|
||||
enc_title= song.snippet.title;//encodeURIComponent(song.snippet.title);
|
||||
//Search.submit(song.id, enc_title, duration, playlist, i);
|
||||
x += 1;
|
||||
Search.submitYouTubeArray.push({id: song.id, title: enc_title, duration: duration});
|
||||
Search.submitYouTubeArray.push({id: song.id, title: enc_title, duration: duration, source: "youtube", thumbnail: "https://img.youtube.com/vi/" + song.id + "/mqdefault.jpg"});
|
||||
}
|
||||
}
|
||||
if(more) Search.addVideos(next_ids);
|
||||
|
||||
@@ -648,7 +648,6 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
var title = req.body.title;
|
||||
if(typeof(userpass) != "string" || typeof(adminpass) != "string" ||
|
||||
typeof(title) != "string" || isNaN(duration) || isNaN(start_time) || isNaN(end_time)) {
|
||||
console.log("this place crash");
|
||||
throw "Wrong format";
|
||||
}
|
||||
}
|
||||
@@ -726,11 +725,15 @@ router.route('/api/list/:channel_name/:video_id').post(function(req,res) {
|
||||
var new_song = {"added": Functions.get_time(),"guids":[guid],"id":video_id,"now_playing":set_np,"title":title,"votes":1, "duration":duration, "start": parseInt(start_time), "end": parseInt(end_time), "type": song_type, "source": source};
|
||||
var runFunction = Search.get_correct_info;
|
||||
if(source == "soundcloud") {
|
||||
new_song.thumbnail = req.body.thumbnail;
|
||||
if(req.body.thumbnail.thumbnail.indexOf("https://i1.sndcdn.com") > -1 || req.body.thumbnail.thumbnail.indexOf("https://w1.sndcdn.com") > -1) {
|
||||
new_song.thumbnail = req.body.thumbnail.thumbnail;
|
||||
} else {
|
||||
new_song.thumbnail = "https://img.youtube.com/vi/404_notfound/mqdefault.jpg";
|
||||
}
|
||||
runFunction = function(new_song, foo_2, foo_3, callback) {
|
||||
callback(new_song, true);
|
||||
}
|
||||
}
|
||||
} else if(source == "youtube") new_song.thumbnail = "https://img.youtube.com/vi/" + new_song.id + "/mqdefault.jpg";
|
||||
runFunction(new_song, channel_name, false, function(element, found) {
|
||||
if(!found) {
|
||||
res.status(404).send(JSON.stringify(error.not_found.youtube));
|
||||
|
||||
Reference in New Issue
Block a user