Exemple #1
0
                                                    db.collection(channel + "_settings").update({id: "config"}, {$set: {startTime: Functions.get_time()}}, function(e,d) {
                                                        if(to_set_np) {
                                                            var to_change = {
                                                                _id: channel,
                                                                count: count,
                                                                frontpage: true,
                                                                accessed: Functions.get_time(),
                                                            }
                                                            db.collection(channel).find({now_playing: true}, function(e, np_docs) {
                                                                to_change.id = np_docs[0].id;
                                                                to_change.title = np_docs[0].title;
                                                                db.collection("frontpage_lists").find({_id: channel}, function(e, doc) {
                                                                    if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1)) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) {
                                                                        to_change.thumbnail = np_docs[0].thumbnail;
                                                                    }

                                                                    db.collection("frontpage_lists").update({_id: channel}, {$set: to_change}, function(e, d) {
                                                                        List.send_list(channel, undefined, false, true, false);
                                                                        List.send_play(channel, undefined);
                                                                        socket.emit("toast", "addedplaylist");
                                                                        _db.close();
                                                                    });
                                                                });
                                                            });
                                                        } else {
                                                            db.collection("frontpage_lists").update({_id: channel}, {$set: {count: count}}, function(e, d) {
                                                                List.send_list(channel, undefined, false, true, false);
                                                                List.send_play(channel, undefined);
                                                                socket.emit("toast", "addedplaylist");
                                                                _db.close();
                                                            })
                                                        }
                                                        Search.get_genres_list_recursive(arr.songs, channel);
                                                    });
Exemple #2
0
 db.collection(coll).find({id:id, type:{$ne:"suggested"}}, function(err, docs){
     if(docs !== null && docs.length === 0) {
         var guids = [guid];
         var added = Functions.get_time();
         var votes = 1;
         db.collection(coll).find({now_playing:true}, function(err, docs){
             if((docs !== null && docs.length === 0)){
                 np = true;
             } else {
                 np = false;
             }
             var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"tags":tags,"votes":votes, "duration":duration, "start": parseInt(start), "end": parseInt(end), "type": "video", "source": source};
             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) {
                     List.send_list(coll, undefined, false, true, false);
                     db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
                     List.send_play(coll, undefined);
                     var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined;
                     Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source);
                     if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
                     else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
                 } else {
                     io.to(coll).emit("channel", {type: "added", value: new_song});
                     if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
                     else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
                 }
                 db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
                 List.getNextSong(coll, undefined);
             });
             socket.emit("toast", "addedsong");
         });
     } else {
         vote(coll, id, guid, socket);
     }
 });
Exemple #3
0
 db.collection(coll).find({id: id}, function(err, docs) {
     if(docs.length === 0) {
         var suggestedAdd = {
             "added":Functions.get_time(),
             "guids": [guid],
             "id":id,
             "now_playing": false,
             "title":title,
             "votes":1,
             "duration":duration,
             "start": start,
             "end": end,
             "type":"suggested",
             "tags":tags
         };
         var source = arr.source;
         if(source == "soundcloud") {
             suggestedAdd.thumbnail = arr.thumbnail;
             suggestedAdd.source = source;
         } else {
             suggestedAdd.source = "youtube";
         }
         db.collection(coll).update({id: id}, {$set: suggestedAdd}, {upsert:true}, function(err, docs){
             socket.emit("toast", "suggested");
             var toSend = suggestedAdd;
             toSend.guids = [];
             if(source == "soundcloud") toSend.thumbnail = arr.thumbnail;
             io.to(coll).emit("suggested", toSend);
         });
     } else if(docs[0].now_playing === true){
         socket.emit("toast", "alreadyplay");
     } else{
         if(conf[0].vote === false) vote(coll, id, guid, socket);
         else socket.emit("toast", "listhaspass");
     }
 });
Exemple #4
0
            db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs)
            {
                socket.emit("toast", "voted");
                io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()});

                List.getNextSong(coll, undefined);
            });
Exemple #5
0
    db.collection(coll).find({id:id, now_playing: false, type:"video"}, function(err, docs){
        if(docs !== null && docs.length > 0 && !Functions.contains(docs[0].guids, guid))
        {
            db.collection(coll).update({id:id}, {$inc:{votes:1}, $set:{added:Functions.get_time()}, $push :{guids: guid}}, function(err, docs)
            {
                socket.emit("toast", "voted");
                io.to(coll).emit("channel", {type: "vote", value: id, time: Functions.get_time()});

                List.getNextSong(coll, undefined);
            });
        }else
        {
            socket.emit("toast", "alreadyvoted");
        }
    });
Exemple #6
0
 db.collection(coll).remove({views: {$exists: false}, type: "video"}, {multi: true}, function(err, succ) {
     List.send_list(coll, false, true, true, true);
     db.collection("frontpage_lists").update({_id: coll}, {$set: {count: 0, accessed: Functions.get_time()}}, {upsert: true}, function(err, docs) {});
     socket.emit("toast", "deleted_songs");
 });
Exemple #7
0
 db.collection(coll).remove({id:params.id}, function(err, docs){
     socket.emit("toast", "deletesong");
     io.to(coll).emit("channel", {type:"deleted", value: params.id});
     if(!dont_increment) db.collection("frontpage_lists").update({_id: coll, count: {$gt: 0}}, {$inc: {count: -1}, $set:{accessed: Functions.get_time()}}, {upsert: true}, function(err, docs){});
 });
Exemple #8
0
 db.collection(coll).update({id: id}, new_song, {upsert: true}, function(err, docs){
     new_song._id = "asd";
     if(np) {
         List.send_list(coll, undefined, false, true, false);
         db.collection(coll + "_settings").update({ id: "config" }, {$set:{startTime: Functions.get_time()}});
         List.send_play(coll, undefined);
         var thumbnail = arr.thumbnail != undefined ? arr.thumbnail : undefined;
         Frontpage.update_frontpage(coll, id, title, thumbnail, arr.source);
         if(source != "soundcloud") Search.get_correct_info(new_song, coll, false);
         else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
     } else {
         io.to(coll).emit("channel", {type: "added", value: new_song});
         if(source != "soundcloud") Search.get_correct_info(new_song, coll, true);
         else if(source == "soundcloud") Search.get_genres_soundcloud(new_song, coll);
     }
     db.collection("frontpage_lists").update({_id:coll}, {$inc:{count:1}, $set:{accessed: Functions.get_time()}}, {upsert:true}, function(err, docs){});
     List.getNextSong(coll, undefined);
 });
Exemple #9
0
                                        MongoClient.connect(url, function(err, _db) {
                                            var dbo = _db.db(mongo_config.config);
                                            var number_elements = arr.songs.length + 1;
                                            var time = Functions.get_time() - number_elements;
                                            var to_set_np = now_playing;
                                            var bulk = dbo.collection(channel).initializeUnorderedBulkOp({useLegacyOps: true});
                                            for(var i = 0; i < arr.songs.length; i++) {
                                                var this_element = arr.songs[i];
                                                if(!this_element.hasOwnProperty("duration") || !this_element.hasOwnProperty("id") || !this_element.hasOwnProperty("title")) {
                                                    continue;
                                                }
                                                this_element.id = this_element.id + "";
                                                this_element.added = time;
                                                this_element.now_playing = now_playing;
                                                this_element.votes = 0;
                                                this_element.guids = [];
                                                if(!this_element.hasOwnProperty("start")) this_element.start = 0;
                                                if(!this_element.hasOwnProperty("end")) this_element.end = this_element.duration;
                                                this_element.start = parseInt(this_element.start);
                                                this_element.end = parseInt(this_element.end);
                                                this_element.type = "video";
                                                if(this_element.tags == undefined) this_element.tags = [];
                                                this_element.duration = parseInt(this_element.duration);
                                                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;
                                                }
                                                bulk.insert(this_element);
                                            }
                                            bulk.execute(function(err, results) {
                                                db.collection(channel).count({type: {$ne: "suggested"}}, function(err, count) {
                                                    db.collection(channel + "_settings").update({id: "config"}, {$set: {startTime: Functions.get_time()}}, function(e,d) {
                                                        if(to_set_np) {
                                                            var to_change = {
                                                                _id: channel,
                                                                count: count,
                                                                frontpage: true,
                                                                accessed: Functions.get_time(),
                                                            }
                                                            db.collection(channel).find({now_playing: true}, function(e, np_docs) {
                                                                to_change.id = np_docs[0].id;
                                                                to_change.title = np_docs[0].title;
                                                                db.collection("frontpage_lists").find({_id: channel}, function(e, doc) {
                                                                    if(doc.length > 0 && ((doc[0].thumbnail != "" && doc[0].thumbnail != undefined && (doc[0].thumbnail.indexOf("https://i1.sndcdn.com") > -1 || doc[0].thumbnail.indexOf("https://w1.sndcdn.com") > -1)) || (doc[0].thumbnail == "" || doc[0].thumbnail == undefined))) {
                                                                        to_change.thumbnail = np_docs[0].thumbnail;
                                                                    }

                                                                    db.collection("frontpage_lists").update({_id: channel}, {$set: to_change}, function(e, d) {
                                                                        List.send_list(channel, undefined, false, true, false);
                                                                        List.send_play(channel, undefined);
                                                                        socket.emit("toast", "addedplaylist");
                                                                        _db.close();
                                                                    });
                                                                });
                                                            });
                                                        } else {
                                                            db.collection("frontpage_lists").update({_id: channel}, {$set: {count: count}}, function(e, d) {
                                                                List.send_list(channel, undefined, false, true, false);
                                                                List.send_play(channel, undefined);
                                                                socket.emit("toast", "addedplaylist");
                                                                _db.close();
                                                            })
                                                        }
                                                        Search.get_genres_list_recursive(arr.songs, channel);
                                                    });
                                                });
                                            });
                                        });