Better handling of errors in videos, only removing if an error is found, else a regular skip is performed

This commit is contained in:
Kasper Rynning-Tønnesen
2019-04-06 14:28:18 +02:00
parent 9725f1d7f1
commit 50704be17b
3 changed files with 160 additions and 117 deletions

View File

@@ -5,6 +5,7 @@ var Frontpage = require(pathThumbnails + '/handlers/frontpage.js');
var projects = require(pathThumbnails + "/handlers/aggregates.js");
var crypto = require('crypto');
var Filter = require('bad-words');
var Search = require(pathThumbnails + '/handlers/search.js');
var filter = new Filter({ placeHolder: 'x'});
/*var filter = {
clean: function(str) {
@@ -187,15 +188,16 @@ function skip(list, guid, coll, offline, socket, callback) {
if(docs.length > 0 && (docs[0].userpass == undefined || docs[0].userpass == "" || (list.hasOwnProperty('userpass') && docs[0].userpass == list.userpass))) {
Functions.check_inlist(coll, guid, socket, offline, undefined, "place 12");
var video_id;
adminpass = "";
video_id = list.id;
err = list.error;
Search.check_if_error_or_blocked(video_id, coll, err == "5" || err == "100" || err == "101" || err == "150", function(trueError) {
var error = false;
var video_id;
if(err != "5" && err != "100" && err != "101" && err != "150")
if(!trueError)
{
adminpass = list.pass;
}else if(err == "5" || err == "100" || err == "101" || err == "150"){
}else if(trueError){
error = true;
}
hash = adminpass;
@@ -261,6 +263,7 @@ function skip(list, guid, coll, offline, socket, callback) {
}else
socket.emit("toast", "noskip");
}
});
//});
} else {
socket.emit("auth_required");
@@ -307,13 +310,11 @@ function change_song(coll, error, id, conf, callback, socket) {
console.log("empty list", coll, callback, id, conf);
}
if(now_playing_doc.length > 0 && ((id && id == now_playing_doc[0].id) || !id)) {
if(error && now_playing_doc[0].source == "youtube"){
request('http://img.youtube.com/vi/'+now_playing_doc[0].id+'/mqdefault.jpg', function (err, response, body) {
if (err || response.statusCode == 404) {
if(error){
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
change_song_post(coll, next_song, conf, callback, socket);
change_song_post(coll, next_song, conf, callback, socket, error);
if(!callback) {
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
}
@@ -321,30 +322,11 @@ function change_song(coll, error, id, conf, callback, socket) {
db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
}
});
} else {
if((conf[0].skipped_time != undefined && conf[0].skipped_time != Functions.get_time()) ||conf[0].skipped_time == undefined) {
db.collection(coll + "_settings").update({id: "config"}, {$set: {skipped_time: Functions.get_time()}}, function(err, updated){
db.collection(coll).update({now_playing:true, id:id}, {
$set:{
now_playing:false,
votes:0,
guids:[]
}
},{multi:true}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
if(docs.n >= 1) change_song_post(coll, next_song, conf, callback, socket);
});
});
}
}
});
} else if(conf[0].removeplay === true){
db.collection(coll).remove({now_playing:true, id:id}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
change_song_post(coll, next_song, conf, callback, socket);
change_song_post(coll, next_song, conf, callback, socket, error);
if(!callback) {
io.to(coll).emit("channel", {type: "deleted", value: now_playing_doc[0].id, removed: true});
}
@@ -353,7 +335,6 @@ function change_song(coll, error, id, conf, callback, socket) {
}
});
} else {
if((conf[0].skipped_time != undefined && conf[0].skipped_time != Functions.get_time()) ||conf[0].skipped_time == undefined) {
db.collection(coll).update({now_playing:true, id:id}, {
$set:{
@@ -364,14 +345,14 @@ function change_song(coll, error, id, conf, callback, socket) {
},{multi:true}, function(err, docs){
var next_song;
if(now_playing_doc.length == 2) next_song = now_playing_doc[1].id;
change_song_post(coll, next_song, conf, callback, socket);
change_song_post(coll, next_song, conf, callback, socket, error);
});
}
}
} else {
if(now_playing_doc.length > 0 && now_playing_doc[0].now_playing == true && now_playing_doc.length > 1 && now_playing_doc[1].id == id) {
db.collection(coll).update({id: now_playing_doc[0].id}, {$set: {now_playing: false}}, function(e, d) {
change_song(coll, error, id, conf, callback, socket);
change_song(coll, error, id, conf, callback, socket, error);
})
} else {
return;
@@ -382,7 +363,7 @@ function change_song(coll, error, id, conf, callback, socket) {
//});
}
function change_song_post(coll, next_song, conf, callback, socket) {
function change_song_post(coll, next_song, conf, callback, socket, removed) {
//coll = coll.replace(/ /g,'');
db.collection(coll).aggregate([{
$match:{
@@ -425,13 +406,13 @@ function change_song_post(coll, next_song, conf, callback, socket) {
}, function(err, returnDocs){
//db.collection(coll + "_settings").find({id: "config"}, function(err, conf){
if(!callback) {
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay || removed});
send_play(coll);
} else {
if(socket == undefined) {
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
io.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay || removed});
} else {
socket.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay});
socket.to(coll).emit("channel", {type: "song_change", time: Functions.get_time(), remove: conf[0].removeplay || removed});
}
send_play(coll, socket, true);
callback();

View File

@@ -12,6 +12,60 @@ try {
var request = require('request');
var db = require(pathThumbnails + '/handlers/db.js');
function check_if_error_or_blocked(id, channel, errored, callback) {
if(!errored) {
callback(false);
return;
}
db.collection(channel).find({id: id, now_playing: true}, function(err, song) {
if(song.length == 0) {
callback(false);
return;
}
var song_info = song[0];
if(song_info.source != "soundcloud") {
request({
type: "GET",
url: "https://www.googleapis.com/youtube/v3/videos?part=id,status,contentDetails&key="+key+"&id=" + song_info.id,
}, function(error, response, body) {
try {
var resp = JSON.parse(body);
if(resp.pageInfo.totalResults == 0) {
callback(true);
return;
} else if(!resp.status.embeddable) {
callback(true);
return;
}
callback(false);
return;
} catch(e){
callback(true);
return;
}
});
} else {
request({
type: "GET",
url: "http://api.soundcloud.com/tracks/" + song_info.id + "?client_id=" + soundcloudKey,
}, function(error, response, body) {
try {
var resp = JSON.parse(body);
if(resp.sharing != "public" || resp.embeddable_by != "all") {
callback(true);
return;
}
callback(false);
return;
} catch(e){
callback(true);
return;
}
});
}
});
}
function filterFunction(el) {
return el != null &&
el != "" &&
@@ -162,14 +216,11 @@ function get_genres_youtube_recursive(arr, channel, i, callback) {
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key="+key+"&id=" + ids.join(","),
}, function(error, response, body) {
if(error) {
console.log(arr, channel, i, arr[i]);
console.log("error start 1", error, ids, "error end");
get_genres_youtube_recursive(arr, channel, i + ids.length, callback);
return;
}
var resp = JSON.parse(body);
if(!resp.hasOwnProperty("items")) {
console.log("error start 2", resp, ids, "error end");
get_genres_youtube_recursive(arr, channel, i + ids.length, callback);
return;
}
@@ -203,12 +254,10 @@ function get_genres_youtube(ids, channel) {
url: "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id,topicDetails&key="+key+"&id=" + ids,
}, function(error, response, body) {
if(error) {
console.log("error start", error, ids, "error end");
return;
}
var resp = JSON.parse(body);
if(!resp.hasOwnProperty("items")) {
console.log("error start", resp, ids, "error end");
return;
}
if(resp.items.length > 0) {
@@ -445,6 +494,7 @@ function durationToSeconds(duration) {
return hours*60*60+minutes*60+seconds;
}
module.exports.check_if_error_or_blocked = check_if_error_or_blocked;
module.exports.get_genres_list_recursive = get_genres_list_recursive;
module.exports.get_genres_soundcloud = get_genres_soundcloud;
module.exports.get_genres_youtube = get_genres_youtube;

View File

@@ -345,6 +345,7 @@ var Player = {
Player.soundcloud_player.bind("finish", Player.soundcloudFinish);
Player.soundcloud_player.bind("pause", Player.soundcloudPause);
Player.soundcloud_player.bind("play", Player.soundcloudPlay);
Player.soundcloud_player.bind("error", Player.soundcloudError);
window.player = player;
Player.soundcloud_dead = false;
SC_player.get('/tracks', {
@@ -355,16 +356,19 @@ var Player = {
document.querySelector("#soundcloud_listen_link").href = sound.permalink_url;
document.querySelector(".soundcloud_info_container .green").href = sound.user.permalink_url;
//document.querySelector(".soundcloud_info_container .red").href = sound.user.permalink_url;
}).catch(function(){});
}).catch(function(e){});
if(_autoplay) {
player.play().then(function(){
Player.soundcloud_player.setVolume(embed ? 1 : Crypt.get_volume() / 100);
Player.soundcloud_player.seek((seekTo) * 1000);
}).catch(function(e){
});
}).catch(function(e){});
}
}).catch(function(error) {
if(error.status == 404) {
Player.errorHandler({data: 5});
} else {
Player.initializeSCWidget(_autoplay, id);
}
});
//Player.initializeSCWidget(_autoplay, id);
//Player.initializeSCWidget(_autoplay, id);
@@ -401,6 +405,7 @@ var Player = {
Player.soundcloud_player.unbind("finish", Player.soundcloudFinish);
Player.soundcloud_player.unbind("pause", Player.soundcloudPause);
Player.soundcloud_player.unbind("play", Player.soundcloudPlay);
Player.soundcloud_player.unbind("error", Player.soundcloudError);
//Player.soundcloud_player.unbind("seek", Player.soundcloudSeek);
}catch(e){}
var this_autoplay = "";
@@ -418,10 +423,15 @@ var Player = {
Player.soundcloud_player.bind("finish", Player.soundcloudFinish);
Player.soundcloud_player.bind("pause", Player.soundcloudPause);
Player.soundcloud_player.bind("play", Player.soundcloudPlay);
Player.soundcloud_player.bind("error", Player.soundcloudError);
Player.soundcloud_player.load('https://api.soundcloud.com/tracks/' + id + this_autoplay, {single_active: false});
}
},
soundcloudError: function() {
Player.errorHandler({data: "5"});
},
addSCWidgetElements: function() {
try {
Player.soundcloud_player = SC_widget.Widget(document.querySelector("#scplayerElement"));
@@ -429,6 +439,7 @@ var Player = {
Player.soundcloud_player.bind("finish", Player.soundcloudFinish);
Player.soundcloud_player.bind("pause", Player.soundcloudPause);
Player.soundcloud_player.bind("play", Player.soundcloudPlay);
Player.soundcloud_player.bind("error", Player.soundcloudError);
SC_player.get('/tracks', {
ids: id
@@ -438,7 +449,8 @@ var Player = {
document.querySelector("#soundcloud_listen_link").href = sound.permalink_url;
document.querySelector(".soundcloud_info_container .green").href = sound.user.permalink_url;
//document.querySelector(".soundcloud_info_container .red").href = sound.user.permalink_url;
}).catch(function(){});
}).catch(function(e){
});
} catch(e) {
setTimeout(function() {
Player.addSCWidgetElements();