mirror of
https://github.com/KevinMidboe/zoff.git
synced 2025-12-08 20:48:48 +00:00
Got automatic detection working for changing song when they are similar enough (higher than 0.75)
This commit is contained in:
@@ -84,6 +84,7 @@ function add_function(arr, coll, guid, offline, socket) {
|
|||||||
db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": start, "end": end}, {upsert: true}, function(err, docs){
|
db.collection(coll).update({id: id}, {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": start, "end": end}, {upsert: true}, function(err, docs){
|
||||||
if(np)
|
if(np)
|
||||||
{
|
{
|
||||||
|
var new_song = {"added": added,"guids":guids,"id":id,"now_playing":np,"title":title,"votes":votes, "duration":duration, "start": start, "end": end};
|
||||||
List.send_list(coll, undefined, false, true, false);
|
List.send_list(coll, undefined, false, true, false);
|
||||||
db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}});
|
db.collection(coll).update({views:{$exists:true}}, {$set:{startTime: Functions.get_time()}});
|
||||||
List.send_play(coll, undefined);
|
List.send_play(coll, undefined);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function get_correct_info(song_generated, channel, broadcast) {
|
|||||||
"title": song_generated.title,
|
"title": song_generated.title,
|
||||||
}
|
}
|
||||||
}, function(err, docs) {
|
}, function(err, docs) {
|
||||||
if(broadcast) {
|
if(broadcast && docs.nModified == 1) {
|
||||||
song_generated.new_id = song_generated.id;
|
song_generated.new_id = song_generated.id;
|
||||||
io.to(channel).emit("channel", {type: "changed_values", value: song_generated});
|
io.to(channel).emit("channel", {type: "changed_values", value: song_generated});
|
||||||
}
|
}
|
||||||
@@ -52,19 +52,14 @@ function check_error_video(msg, channel) {
|
|||||||
|
|
||||||
}, function(error, response, body) {
|
}, function(error, response, body) {
|
||||||
var resp = JSON.parse(body);
|
var resp = JSON.parse(body);
|
||||||
//console.log(resp.pageInfo.totalResults);
|
|
||||||
if(resp.pageInfo.totalResults == 0) {
|
if(resp.pageInfo.totalResults == 0) {
|
||||||
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + encodeURIComponent(msg.title);
|
var yt_url = "https://www.googleapis.com/youtube/v3/search?key="+key+"&videoEmbeddable=true&part=id&type=video&order=viewCount&safeSearch=none&maxResults=5&q=" + encodeURIComponent(msg.title);
|
||||||
//console.log(yt_url);
|
|
||||||
request({
|
request({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: yt_url,
|
url: yt_url,
|
||||||
}, function(error, response, body){
|
}, function(error, response, body){
|
||||||
var resp = JSON.parse(body);
|
var resp = JSON.parse(body);
|
||||||
|
|
||||||
if(resp.items.length > 0) {
|
if(resp.items.length > 0) {
|
||||||
//console.log(resp.items);
|
|
||||||
|
|
||||||
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+key+"&id=";
|
var vid_url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails,snippet,id&key="+key+"&id=";
|
||||||
for(var i = 0; i < resp.items.length; i++) {
|
for(var i = 0; i < resp.items.length; i++) {
|
||||||
vid_url += resp.items[i].id.videoId + ",";
|
vid_url += resp.items[i].id.videoId + ",";
|
||||||
@@ -91,14 +86,14 @@ function check_error_video(msg, channel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(found) {
|
if(found) {
|
||||||
console.log("time to change", msg.id, element);
|
|
||||||
db.collection(channel).update({"id": msg.id}, {
|
db.collection(channel).update({"id": msg.id}, {
|
||||||
$set: element
|
$set: element
|
||||||
}, function(err, docs) {
|
}, function(err, docs) {
|
||||||
console.log(err, docs);
|
if(docs.nModified == 1) {
|
||||||
element.new_id = element.id;
|
element.new_id = element.id;
|
||||||
element.id = msg.id;
|
element.id = msg.id;
|
||||||
io.to(channel).emit("channel", {type: "changed_values", value: element});
|
io.to(channel).emit("channel", {type: "changed_values", value: element});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -153,18 +153,21 @@ var List = {
|
|||||||
|
|
||||||
changedValues: function(song) {
|
changedValues: function(song) {
|
||||||
var i = List.getIndexOfSong(song.id);
|
var i = List.getIndexOfSong(song.id);
|
||||||
full_playlist[i].title = song.title;
|
if(i >= 0) {
|
||||||
full_playlist[i].duration = song.duration;
|
full_playlist[i].title = song.title;
|
||||||
full_playlist[i].start = song.start;
|
full_playlist[i].duration = song.duration;
|
||||||
full_playlist[i].end = song.end;
|
full_playlist[i].start = song.start;
|
||||||
full_playlist[i].id = song.new_id;
|
full_playlist[i].end = song.end;
|
||||||
|
full_playlist[i].id = song.new_id;
|
||||||
|
|
||||||
$("#" + song.id).find(".vote-container").attr("title", song.title);
|
$("#" + song.id).find(".vote-container").attr("title", song.title);
|
||||||
$("#" + song.id).find(".list-title").attr("title", song.title);
|
$("#" + song.id).find(".list-title").attr("title", song.title);
|
||||||
$("#" + song.id).find(".list-title").text(song.title);
|
$("#" + song.id).find(".list-title").text(song.title);
|
||||||
var _temp_duration = Helper.secondsToOther(song.duration);
|
var _temp_duration = Helper.secondsToOther(song.duration);
|
||||||
$("#" + song.id).find(".card-duration").text(Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]));
|
$("#" + song.id).find(".card-duration").text(Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]));
|
||||||
$("#" + song.id).attr("id", song.new_id);
|
$("#" + song.id).find(".list-image").attr("style", "background-image:url('//img.youtube.com/vi/"+song.new_id+"/mqdefault.jpg');");
|
||||||
|
$("#" + song.id).attr("id", song.new_id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
insertAtBeginning: function(song_info, transition) {
|
insertAtBeginning: function(song_info, transition) {
|
||||||
@@ -936,7 +939,8 @@ var List = {
|
|||||||
var video_id = _song_info.id;
|
var video_id = _song_info.id;
|
||||||
var video_title = _song_info.title;
|
var video_title = _song_info.title;
|
||||||
var video_votes = _song_info.votes;
|
var video_votes = _song_info.votes;
|
||||||
var video_thumb = "background-image:url('//img.youtube.com/vi/"+video_id+"/mqdefault.jpg');";
|
var video_thumb_url = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg";
|
||||||
|
var video_thumb = "background-image:url('" + video_thumb_url + "');";
|
||||||
var song = $("<div>"+list_html+"</div>");
|
var song = $("<div>"+list_html+"</div>");
|
||||||
var image_attr = "style";
|
var image_attr = "style";
|
||||||
if(_song_info.hasOwnProperty("start") && _song_info.hasOwnProperty("end")) {
|
if(_song_info.hasOwnProperty("start") && _song_info.hasOwnProperty("end")) {
|
||||||
@@ -968,13 +972,18 @@ var List = {
|
|||||||
attr = ".vote-container";
|
attr = ".vote-container";
|
||||||
del_attr = "delete_button";
|
del_attr = "delete_button";
|
||||||
|
|
||||||
var img = new Image();
|
var url = "https://zoff.me:8081/https://img.youtube.com/vi/"+video_id+"/mqdefault.jpg";
|
||||||
img.onerror = function() {
|
$.ajax({
|
||||||
setTimeout(function() {
|
type: "HEAD",
|
||||||
socket.emit("error_video", {channel: chan.toLowerCase(), id: video_id, title: video_title});
|
url: url,
|
||||||
}, 500);
|
error: function(e) {
|
||||||
};
|
if(e.status == 404) {
|
||||||
img.src = "//img.youtube.com/vi/"+video_id+"/mqdefault.jpg";
|
setTimeout(function() {
|
||||||
|
socket.emit("error_video", {channel: chan.toLowerCase(), id: video_id, title: video_title});
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var _temp_duration = Helper.secondsToOther(_song_info.duration);
|
var _temp_duration = Helper.secondsToOther(_song_info.duration);
|
||||||
song.find(".card-duration").text(Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]));
|
song.find(".card-duration").text(Helper.pad(_temp_duration[0]) + ":" + Helper.pad(_temp_duration[1]));
|
||||||
@@ -1011,6 +1020,7 @@ var List = {
|
|||||||
song.find(".list-title").attr("title", video_title);
|
song.find(".list-title").attr("title", video_title);
|
||||||
song.find(attr).attr("data-video-id", video_id);
|
song.find(attr).attr("data-video-id", video_id);
|
||||||
song.find(".list-image").attr(image_attr,video_thumb);
|
song.find(".list-image").attr(image_attr,video_thumb);
|
||||||
|
song.find(".list-image-placeholder").attr("src", video_thumb_url);
|
||||||
song.find(".list-suggested-image").attr(image_attr,video_thumb);
|
song.find(".list-suggested-image").attr(image_attr,video_thumb);
|
||||||
song.find("."+del_attr).attr("data-video-id", video_id);
|
song.find("."+del_attr).attr("data-video-id", video_id);
|
||||||
return song.html();
|
return song.html();
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
<div id="list-song" class="card left-align list-song playlist-element waves-effect waves-light">
|
<div id="list-song" class="card left-align list-song playlist-element waves-effect waves-light">
|
||||||
<div class="clickable vote-container" title="Vote!">
|
<div class="clickable vote-container" title="Vote!">
|
||||||
<a class="clickable center-align votebg">
|
<a class="clickable center-align votebg">
|
||||||
<span class="lazy card-image cardbg list-image" style="background-image:url('/assets/images/loading.png');">
|
<span class="card-image cardbg list-image" style="background-image:url('/assets/images/loading.png');"></span>
|
||||||
</span>
|
|
||||||
<span class="card-duration">
|
<span class="card-duration">
|
||||||
01:00
|
01:00
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user