From c9b7ec72d8c68e443edfca1d671632fc4847d4f4 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 9 Jun 2022 17:23:11 +0200 Subject: [PATCH] add hotkey Y to download current song / vid / pic --- copyparty/web/baguettebox.js | 16 ++++++++++++++-- copyparty/web/browser.js | 11 +++++++++++ copyparty/web/util.js | 8 ++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/copyparty/web/baguettebox.js b/copyparty/web/baguettebox.js index fc2b36fb..9945f789 100644 --- a/copyparty/web/baguettebox.js +++ b/copyparty/web/baguettebox.js @@ -284,6 +284,8 @@ window.baguetteBox = (function () { tglsel(); else if (k == "KeyR") rotn(e.shiftKey ? -1 : 1); + else if (k == "KeyY") + dlpic(); } function anim() { @@ -342,19 +344,29 @@ window.baguetteBox = (function () { tt.show.bind(this)(); } - function tglsel() { + function findfile() { var thumb = currentGallery[currentIndex].imageElement, name = vsplit(thumb.href)[1].split('?')[0], files = msel.getall(); for (var a = 0; a < files.length; a++) if (vsplit(files[a].vp)[1] == name) - clmod(ebi(files[a].id).closest('tr'), 'sel', 't'); + return [name, a, files, ebi(files[a].id)]; + } + function tglsel() { + var o = findfile()[3]; + clmod(o.closest('tr'), 'sel', 't'); msel.selui(); selbg(); } + function dlpic() { + var url = findfile()[3].href; + url += (url.indexOf('?') < 0 ? '?' : '&') + 'cache'; + dl_file(url); + } + function selbg() { var img = vidimg(), thumb = currentGallery[currentIndex].imageElement, diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index f74c7fcc..8b2048a7 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -1700,6 +1700,14 @@ function prev_song(e) { return song_skip(-1); } +function dl_song() { + if (!mp || !mp.au) + return; + + var url = mp.tracks[mp.au.tid]; + url += (url.indexOf('?') < 0 ? '?' : '&') + 'cache=987'; + dl_file(url); +} function playpause(e) { @@ -3943,6 +3951,9 @@ document.onkeydown = function (e) { if (n !== 0) return seek_au_rel(n) || true; + if (k == 'KeyY') + return dl_song(); + n = k == 'KeyI' ? -1 : k == 'KeyK' ? 1 : 0; if (n !== 0) return tree_neigh(n); diff --git a/copyparty/web/util.js b/copyparty/web/util.js index 480c7945..14a9e04d 100644 --- a/copyparty/web/util.js +++ b/copyparty/web/util.js @@ -815,6 +815,14 @@ function sethash(hv) { } } +function dl_file(url) { + console.log('DL [%s]', url); + var o = mknod('a'); + o.setAttribute('href', url); + o.setAttribute('download', ''); + o.click(); +} + var timer = (function () { var r = {};