Soundcloud-player + soundcloud-search added

This commit is contained in:
Kasper Rynning-Tønnesen
2018-05-03 14:27:54 +02:00
parent 93fc30dada
commit 9b1e91783e
19 changed files with 863 additions and 356 deletions

View File

@@ -19,6 +19,24 @@ function remove_name_from_db(guid, name) {
});
}
function isUrl(str) {
var pattern = new RegExp("\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
"|mil|biz|info|mobi|name|aero|jobs|museum" +
"|travel|[a-z]{2}))(:[\\d]{1,5})?" +
"(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" +
"((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" +
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
if(!pattern.test(str)) {
return false;
} else {
return true;
}
}
function getSession(socket) {
try {
/*var cookieParser = require("cookie-parser");
@@ -273,6 +291,7 @@ function removeSessionAdminPass(id, channel, callback) {
});
}
module.exports.isUrl = isUrl;
module.exports.removeEmojis = removeEmojis;
module.exports.getSessionChatPass = getSessionChatPass;
module.exports.setSessionChatPass = setSessionChatPass;

View File

@@ -84,7 +84,9 @@ function list(msg, guid, coll, offline, socket) {
db.collection(coll + "_settings").insert(configs, function(err, docs){
socket.join(coll);
List.send_list(coll, socket, true, false, true);
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1});
db.collection("frontpage_lists").insert({"_id": coll, "count" : 0, "frontpage": true, "accessed": Functions.get_time(), "viewers": 1}, function(e,d){
console.log("added new channel", coll);
});
Functions.check_inlist(coll, guid, socket, offline);
});
});

View File

@@ -298,7 +298,9 @@ function add_function(arr, coll, guid, offline, socket) {
if(typeof(arr.id) != "string" || typeof(arr.start) != "number" ||
typeof(arr.end) != "number" || typeof(arr.title) != "string" ||
typeof(arr.list) != "string" || typeof(arr.duration) != "number") {
typeof(arr.list) != "string" || typeof(arr.duration) != "number" ||
typeof(arr.source) != "string" ||
(arr.source == "soundcloud" && (!arr.hasOwnProperty("thumbnail") || !Functions.isUrl(arr.thumbnail)))) {
var result = {
start: {
expected: "number or string that can be cast to int",
@@ -327,6 +329,14 @@ function add_function(arr, coll, guid, offline, socket) {
adminpass: {
expected: "string",
got: arr.hasOwnProperty("adminpass") ? typeof(arr.adminpass) : undefined
},
source: {
expected: "string (youtube or soundcloud)",
got: arr.hasOwnProperty("source") ? typeof(arr.source) : undefined
},
thumbnail: {
expected: "url if source == soundcloud",
got: arr.hasOwnProperty("thumbnail") ? typeof(arr.thumbnail) : undefined
}
};
socket.emit('update_required', result);
@@ -350,6 +360,7 @@ function add_function(arr, coll, guid, offline, socket) {
var title = arr.title;
var hash = Functions.hash_pass(Functions.hash_pass(Functions.decrypt_string(arr.adminpass), true));
var duration = parseInt(arr.duration);
var source = arr.source;
/*db.collection(coll + "_settings").find(function(err, docs)
{*/
conf = docs;
@@ -366,7 +377,10 @@ function add_function(arr, coll, guid, offline, socket) {
} else {
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"};
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;
console.log(new_song);
//return;
db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
new_song._id = "asd";
if(np) {
@@ -374,10 +388,10 @@ function add_function(arr, coll, guid, offline, socket) {
db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
List.send_play(coll, undefined);
Frontpage.update_frontpage(coll, id, title);
Search.get_correct_info(new_song, coll, false);
if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
} else {
io.to(coll).emit("channel", {type: "added", value: new_song});
Search.get_correct_info(new_song, coll, true);
if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
}
db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
List.getNextSong(coll);

View File

@@ -82,6 +82,7 @@ function check_error_video(msg, channel) {
};
return;
}
if(msg.source == "soundcloud") return;
channel = channel.replace(/ /g,'');
request({
type: "GET",

View File

@@ -1,23 +1,7 @@
function isUrl(str) {
var pattern = new RegExp("\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" +
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
"|mil|biz|info|mobi|name|aero|jobs|museum" +
"|travel|[a-z]{2}))(:[\\d]{1,5})?" +
"(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" +
"((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)*)*" +
"(#([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)?\\b");
if(!pattern.test(str)) {
return false;
} else {
return true;
}
}
function thumbnail(msg, coll, guid, offline, socket) {
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && isUrl(msg.thumbnail)){
if(msg.thumbnail != undefined && msg.channel && msg.channel != undefined && Functions.isUrl(msg.thumbnail)){
if(typeof(msg.channel) != "string" || typeof(msg.thumbnail) != "string")
{
var result = {