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:
Kasper Rynning-Tønnesen
2018-05-29 15:02:09 +02:00
parent 51a5cc2b13
commit adc55ee420
5 changed files with 42 additions and 23 deletions

View File

@@ -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) {

View File

@@ -245,7 +245,9 @@ var List = {
check_error_videos: function(i) {
//Helper.log("Empty-checker at " + i);
if(full_playlist.length == 0 || full_playlist[i].source == "soundcloud") return;
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
@@ -261,7 +263,8 @@ var List = {
List.check_error_videos(i + 1);
}
}
})
});
}
},
dynamicContentPageJumpTo: function(page) {

View File

@@ -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");

View File

@@ -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);

View File

@@ -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));