From a3a2daff4c41402e7a965db0865bdcda5e072193 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Sun, 7 Apr 2019 16:32:58 -0700 Subject: [PATCH] Remove file extension check (#801) --- package.json | 2 +- src/ffmpeg.js | 9 +++--- www/js/ui.js | 75 +++++++++++++++++++++++++++++++++++--------------- www/js/util.js | 44 ++++++----------------------- 4 files changed, 66 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 6611a32d..db63eb79 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Calvin Montgomery", "name": "CyTube", "description": "Online media synchronizer and chat", - "version": "3.63.6", + "version": "3.64.0", "repository": { "url": "http://github.com/calzoneman/sync" }, diff --git a/src/ffmpeg.js b/src/ffmpeg.js index 64caf02d..b8bb0517 100644 --- a/src/ffmpeg.js +++ b/src/ffmpeg.js @@ -174,11 +174,10 @@ function testUrl(url, cb, params = { redirCount: 0, cookie: '' }) { } if (!/^audio|^video/.test(res.headers["content-type"])) { - return cb("Expected a content-type starting with 'audio' or 'video', but " + - "got '" + res.headers["content-type"] + "'. Only direct links " + - "to video and audio files are accepted, and the website hosting " + - "the file must be configured to send the correct MIME type. " + - "See https://git.io/vrE75 for details."); + cb("Could not detect a supported audio/video type. See " + + "https://git.io/fjtOK for a list of supported providers. " + + "(Content-Type was: '" + res.headers["content-type"] + "')"); + return; } cb(); diff --git a/www/js/ui.js b/www/js/ui.js index dedfa547..79fd47df 100644 --- a/www/js/ui.js +++ b/www/js/ui.js @@ -269,13 +269,14 @@ $("#library_query").keydown(function(ev) { $("#youtube_search").click(function () { var query = $("#library_query").val().toLowerCase(); - if(parseMediaLink(query).type !== null) { + try { + parseMediaLink(query); makeAlert("Media Link", "If you already have the link, paste it " + "in the 'Media URL' box under Playlist Controls. This "+ "searchbar works like YouTube's search function.", "alert-danger") .insertBefore($("#library")); - } + } catch (e) {} socket.emit("searchMedia", { source: "yt", @@ -368,26 +369,50 @@ function queue(pos, src) { } links.forEach(function (link) { - var data = parseMediaLink(link); + var data; + + try { + data = parseMediaLink(link); + } catch (error) { + Callbacks.queueFail({ + link: link, + msg: error.message + }); + return; + } + var duration = undefined; var title = undefined; if (data.type === "fi") { + if (data.id.match(/^http:/)) { + Callbacks.queueFail({ + link: data.id, + msg: "Raw files must begin with 'https'. Plain http is not supported." + }); + return; + } + + // Explicit checks for kissanime and mega.nz since everyone + // asks about them + if (data.id.match(/kissanime|kimcartoon|kisscartoon/i)) { + Callbacks.queueFail({ + link: data.id, + msg: "Kisscartoon and Kissanime are not supported. See https://git.io/vxS9n" + + " for more information about why these cannot be supported." + }); + return; + } else if (data.id.match(/mega\.nz/)) { + Callbacks.queueFail({ + link: data.id, + msg: "Mega.nz is not supported. See https://git.io/fx6fz" + + " for more information about why mega.nz cannot be supported." + }); + return; + } + + // Raw files allow title overrides since the ffprobe tag data + // is not always correct. title = $("#addfromurl-title-val").val(); - } else if (data.type === "vm") { - /* - * As of December 2017, vid.me is no longer in service. - * Leaving this temporarily to hopefully avoid confusion - * for people pasting old vid.me links. - * - * TODO: remove at some point in the future - */ - - Callbacks.queueFail({ - link: link, - msg: "As of December 2017, vid.me is no longer in service." - }); - - return; } if (data.id == null || data.type == null) { @@ -444,15 +469,21 @@ $("#mediaurl").keyup(function(ev) { if (ev.keyCode === 13) { queue("end", "url"); } else { - var url = $("#mediaurl").val().split("?")[0]; - if (url.match(/^https:\/\/(.*)?\.(flv|mp4|og[gv]|webm|mp3|mov|m4a)$/) || - url.match(/^fi:/)) { + var editTitle = false; + try { + if (parseMediaLink($("#mediaurl").val()).type === "fi") { + editTitle = true; + } + } catch (error) { + } + + if (editTitle) { var title = $("#addfromurl-title"); if (title.length === 0) { title = $("
") .attr("id", "addfromurl-title") .appendTo($("#addfromurl")); - $("").text("Title (optional)") + $("").text("Title (optional; for raw files only)") .appendTo(title); $("").addClass("form-control") .attr("type", "text") diff --git a/www/js/util.js b/www/js/util.js index 2603ac33..51fa47c4 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -1468,53 +1468,25 @@ function parseMediaLink(url) { /* Raw file */ var tmp = url.split("?")[0]; if (tmp.match(/^https?:\/\//)) { - if (tmp.match(/^http:/)) { - Callbacks.queueFail({ - link: url, - msg: "Raw files must begin with 'https'. Plain http is not supported." - }); - throw new Error("ERROR_QUEUE_HTTP"); - } else if (tmp.match(/\.json$/)) { + if (tmp.match(/\.json$/)) { + // Custom media manifest format return { id: url, type: "cm" }; - } else if (tmp.match(/kissanime|kimcartoon|kisscartoon/i)) { - Callbacks.queueFail({ - link: url, - msg: "Kisscartoon and Kissanime are not supported. See https://git.io/vxS9n" + - " for more information about why these cannot be supported." - }); - throw new Error("ERROR_QUEUE_KISS"); - } else if (tmp.match(/mega\.nz/)) { - Callbacks.queueFail({ - link: url, - msg: "Mega.nz is not supported. See https://git.io/fx6fz" + - " for more information about why mega.nz cannot be supported." - }); - throw new Error("ERROR_QUEUE_MEGA"); - } else if (tmp.match(/\.(mp4|flv|webm|og[gv]|mp3|mov|m4a)$/)) { + } else { + // Assume raw file (server will check) return { id: url, type: "fi" }; - } else { - Callbacks.queueFail({ - link: url, - msg: "The file you are attempting to queue does not match the supported " + - "file extensions mp4, flv, webm, ogg, ogv, mp3, mov, m4a. " + - "For more information about why other filetypes are not supported, " + - "see https://git.io/va9g9" - }); - // Lol I forgot about this hack - throw new Error("ERROR_QUEUE_UNSUPPORTED_EXTENSION"); } } - return { - id: null, - type: null - }; + throw new Error( + 'Could not determine video type. Check https://git.io/fjtOK for a list ' + + 'of supported media providers.' + ); } function sendVideoUpdate() {