diff --git a/channel.js b/channel.js index 4d24ac02..d799bfa3 100644 --- a/channel.js +++ b/channel.js @@ -218,7 +218,18 @@ Channel.prototype.unbanIP = function(actor, ip) { return Database.removeChannelBan(this.name, ip); } -Channel.prototype.search = function(query) { +Channel.prototype.search = function(query, callback) { + // Search youtube + if(callback) { + if(query.trim() == "") { + return; + } + InfoGetter.getYTSearchResults(query, function(vids) { + callback(vids); + }); + return; + } + query = query.toLowerCase(); var results = []; for(var id in this.library) { @@ -232,6 +243,7 @@ Channel.prototype.search = function(query) { return (x == y) ? 0 : (x < y ? -1 : 1); }); + return results; } @@ -678,8 +690,10 @@ Channel.prototype.jumpTo = function(pos) { } Channel.prototype.tryJumpTo = function(user, data) { - if(!Rank.hasPermission(user, "jump") && - this.leader != user) { + if(!Rank.hasPermission(user, "queue") && + this.leader != user && + (!this.openqueue || + this.openqueue && !this.opts.qopen_allow_playnext)) { return; } diff --git a/get-info.js b/get-info.js index 0fb9dd65..c4b2fa4d 100644 --- a/get-info.js +++ b/get-info.js @@ -87,8 +87,55 @@ exports.getYTPlaylist = function(id, callback, url) { timeout: 1000}, callback); } +exports.searchYT = function(terms, callback) { + getJSON({ + host: "gdata.youtube.com", + port: 80, + path: "/feeds/api/videos/-/" + terms.join("/") + "?v=2&alt=json", + method: "GET", + dataType: "jsonp", + timeout: 1000}, callback); +} + +exports.getYTSearchResults = function(query, callback) { + var cback = function(res, data) { + if(res != 200) { + return; + } + + var vids = []; + try { + + for(var i = 0; i < data.feed.entry.length; i++) { + try { + var item = data.feed.entry[i]; + + var id = item.media$group.yt$videoid.$t; + var title = item.title.$t; + var seconds = item.media$group.yt$duration.seconds; + var media = new Media(id, title, seconds, "yt"); + media.thumb = item.media$group.media$thumbnail[0]; + vids.push(media); + } + catch(e) { + Logger.errlog.log("getYTSearchResults failed: "); + Logger.errlog.log(e); + } + } + + } + catch(e) { + Logger.errlog.log("getYTSearchResults failed: "); + Logger.errlog.log(e); + } + callback(vids); + } + + exports.searchYT(query.split(" "), cback); +} + // Look up Soundcloud metadata -// Whoever designed this should rethink it. I"ll submit a feedback +// Whoever designed this should rethink it. I'll submit a feedback // form on their website. exports.getSCInfo = function(url, callback) { const SC_CLIENT = "2e0c82ab5a020f3a7509318146128abd"; diff --git a/server.js b/server.js index 90a2b644..02f8f39f 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,7 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -const VERSION = "1.0.1"; +const VERSION = "1.1.0"; var fs = require("fs"); var Logger = require("./logger.js"); diff --git a/user.js b/user.js index a494f333..3e8ed243 100644 --- a/user.js +++ b/user.js @@ -151,9 +151,19 @@ User.prototype.initCallbacks = function() { this.socket.on("searchLibrary", function(data) { if(this.channel != null) { - this.socket.emit("librarySearchResults", { - results: this.channel.search(data.query) - }); + if(data.yt) { + var callback = function(vids) { + this.socket.emit("librarySearchResults", { + results: vids + }); + }.bind(this); + this.channel.search(data.query, callback); + } + else { + this.socket.emit("librarySearchResults", { + results: this.channel.search(data.query) + }); + } } }.bind(this)); diff --git a/www/assets/js/client.js b/www/assets/js/client.js index 1bd8e686..d42a5d07 100644 --- a/www/assets/js/client.js +++ b/www/assets/js/client.js @@ -323,10 +323,17 @@ function searchLibrary() { } $("#library_search").click(searchLibrary); $("#library_query").keydown(function(ev) { - if(ev.key == 13) + if(ev.keyCode == 13) searchLibrary(); }); +$("#youtube_search").click(function() { + socket.emit("searchLibrary", { + query: $("#library_query").val(), + yt: true + }); +}); + $("#largelayout").click(largeLayout); $("#hugelayout").click(hugeLayout); $("#narrowlayout").click(narrowLayout); diff --git a/www/assets/js/functions.js b/www/assets/js/functions.js index 013cd062..2198a4c1 100644 --- a/www/assets/js/functions.js +++ b/www/assets/js/functions.js @@ -156,11 +156,17 @@ function formatChatMessage(data) { function makeQueueEntry(video) { var li = $("
"); li.attr("class", "well"); - var title = $("").attr("class", "qe_title").appendTo(li); + if(video.thumb) { + $("