From 844edbe2f41ce8da59fe930c3bac956a25fdddcf Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 01:46:14 +0300 Subject: [PATCH 01/11] fix metadata when downloading unplayed song --- plugins/downloader/back.js | 7 +++++-- plugins/downloader/front.js | 13 +++++++++---- plugins/downloader/youtube-dl.js | 20 +++++++++++++++++++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/plugins/downloader/back.js b/plugins/downloader/back.js index 49b5eea5..2e2ad01f 100644 --- a/plugins/downloader/back.js +++ b/plugins/downloader/back.js @@ -7,6 +7,7 @@ const { dialog, ipcMain } = require("electron"); const getSongInfo = require("../../providers/song-info"); const { injectCSS, listenAction } = require("../utils"); const { ACTIONS, CHANNEL } = require("./actions.js"); +const { getImage } = require("../../providers/song-info"); const sendError = (win, err) => { const dialogOpts = { @@ -41,10 +42,12 @@ function handle(win) { } }); - ipcMain.on("add-metadata", (event, filePath, songBuffer, currentMetadata) => { + ipcMain.on("add-metadata", async (event, filePath, songBuffer, currentMetadata) => { let fileBuffer = songBuffer; const songMetadata = { ...metadata, ...currentMetadata }; - + if (!songMetadata.image && songMetadata.imageSrc) { + songMetadata.image = await getImage(songMetadata.imageSrc) + } try { const coverBuffer = songMetadata.image.toPNG(); const writer = new ID3Writer(songBuffer); diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index e4930f09..b023965c 100644 --- a/plugins/downloader/front.js +++ b/plugins/downloader/front.js @@ -38,13 +38,18 @@ const baseUrl = defaultConfig.url; // contextBridge.exposeInMainWorld("downloader", { // download: () => { global.download = () => { + let metadata; let videoUrl = getSongMenu() .querySelector("ytmusic-menu-navigation-item-renderer") .querySelector("#navigation-endpoint") .getAttribute("href"); - videoUrl = !videoUrl - ? global.songInfo.url || window.location.href - : baseUrl + "/" + videoUrl; + if (videoUrl) { + videoUrl = baseUrl + "/" + videoUrl; + metadata = null; + } else { + videoUrl = global.songInfo.url || window.location.href; + metadata = global.songInfo; + } downloadVideoToMP3( videoUrl, @@ -61,7 +66,7 @@ global.download = () => { }, reinit, pluginOptions, - global.songInfo + metadata ); }; // }); diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index 1a212aaf..97d49ef2 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -24,7 +24,14 @@ const ffmpeg = createFFmpeg({ }); const ffmpegMutex = new Mutex(); -const downloadVideoToMP3 = ( +function noTopic(channelName) { + if (channelName && channelName.endsWith(" - Topic")) { + channelName = channelName.slice(0, -8); + } + return channelName; +} + +const downloadVideoToMP3 = async ( videoUrl, sendFeedback, sendError, @@ -35,6 +42,16 @@ const downloadVideoToMP3 = ( ) => { sendFeedback("Downloading…"); + if (metadata === null) { + const info = await ytdl.getInfo(videoUrl); + const thumbnails = info.videoDetails?.author?.thumbnails; + metadata = { + artist: info.videoDetails?.media?.artist || noTopic(info.videoDetails?.author?.name) || "", + title: info.videoDetails?.media?.song || info.videoDetails?.title || "", + imageSrc: thumbnails ? thumbnails[thumbnails.length - 1].url : "" + } + } + let videoName = "YouTube Music - Unknown title"; let videoReadableStream; try { @@ -135,6 +152,7 @@ const toMP3 = async ( ipcRenderer.send("add-metadata", filePath, fileBuffer, { artist: metadata.artist, title: metadata.title, + imageSrc: metadata.imageSrc || "" }); ipcRenderer.once("add-metadata-done", reinit); } catch (e) { From ca41c12f7c4e7ac2f0000540447243443ed8df48 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 02:05:48 +0300 Subject: [PATCH 02/11] use media propery if exist in song-info --- providers/song-info.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/song-info.js b/providers/song-info.js index a7aa651d..02ba6dec 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -57,8 +57,8 @@ const songInfo = { const handleData = async (responseText, win) => { let data = JSON.parse(responseText); - songInfo.title = data?.videoDetails?.title; - songInfo.artist = await getArtist(win) || data?.videoDetails?.author; + songInfo.title = data.videoDetails?.media?.song || data?.videoDetails?.title; + songInfo.artist = data.videoDetails?.media?.artist || await getArtist(win) || data?.videoDetails?.author; songInfo.views = data?.videoDetails?.viewCount; songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url; songInfo.songDuration = data?.videoDetails?.lengthSeconds; From f190b51dcca1f8bcd1391c86b88da9089da64fb6 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 02:17:48 +0300 Subject: [PATCH 03/11] lint --- plugins/downloader/back.js | 2 ++ plugins/downloader/front.js | 2 +- plugins/downloader/youtube-dl.js | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/downloader/back.js b/plugins/downloader/back.js index 2e2ad01f..2fe84d56 100644 --- a/plugins/downloader/back.js +++ b/plugins/downloader/back.js @@ -45,9 +45,11 @@ function handle(win) { ipcMain.on("add-metadata", async (event, filePath, songBuffer, currentMetadata) => { let fileBuffer = songBuffer; const songMetadata = { ...metadata, ...currentMetadata }; + if (!songMetadata.image && songMetadata.imageSrc) { songMetadata.image = await getImage(songMetadata.imageSrc) } + try { const coverBuffer = songMetadata.image.toPNG(); const writer = new ID3Writer(songBuffer); diff --git a/plugins/downloader/front.js b/plugins/downloader/front.js index b023965c..200a7e15 100644 --- a/plugins/downloader/front.js +++ b/plugins/downloader/front.js @@ -47,8 +47,8 @@ global.download = () => { videoUrl = baseUrl + "/" + videoUrl; metadata = null; } else { - videoUrl = global.songInfo.url || window.location.href; metadata = global.songInfo; + videoUrl = metadata.url || window.location.href; } downloadVideoToMP3( diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index 97d49ef2..27b9b3a5 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -152,7 +152,7 @@ const toMP3 = async ( ipcRenderer.send("add-metadata", filePath, fileBuffer, { artist: metadata.artist, title: metadata.title, - imageSrc: metadata.imageSrc || "" + imageSrc: metadata.imageSrc }); ipcRenderer.once("add-metadata-done", reinit); } catch (e) { From e18b7c101351a1060e91d6a08c3789ab87e47fc5 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 02:28:35 +0300 Subject: [PATCH 04/11] allow unlimited playlist size --- plugins/downloader/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index b4800808..fad696b2 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -35,7 +35,7 @@ module.exports = (win, options, refreshMenu) => { return; } - const playlist = await ytpl(playlistID); + const playlist = await ytpl(playlistID, { limit: Infinity }); const playlistTitle = playlist.title; const folder = getFolder(options.downloadFolder); From d96fefbc24217399ff8ebfb825613b388ba3d6c4 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 02:51:10 +0300 Subject: [PATCH 05/11] fix error thrown when downloading playlist --- plugins/downloader/back.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/downloader/back.js b/plugins/downloader/back.js index 2fe84d56..31a929aa 100644 --- a/plugins/downloader/back.js +++ b/plugins/downloader/back.js @@ -51,18 +51,20 @@ function handle(win) { } try { - const coverBuffer = songMetadata.image.toPNG(); + const coverBuffer = songMetadata.image ? songMetadata.image.toPNG() : null; const writer = new ID3Writer(songBuffer); // Create the metadata tags writer .setFrame("TIT2", songMetadata.title) - .setFrame("TPE1", [songMetadata.artist]) - .setFrame("APIC", { + .setFrame("TPE1", [songMetadata.artist]); + if (coverBuffer) { + writer.setFrame("APIC", { type: 3, data: coverBuffer, description: "", }); + } writer.addTag(); fileBuffer = Buffer.from(writer.arrayBuffer); } catch (error) { From 61c549458815290dd3fc129885d5e41384c07f22 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 03:02:06 +0300 Subject: [PATCH 06/11] custom metadata on playlist-download --- plugins/downloader/menu.js | 6 ++++-- plugins/downloader/youtube-dl.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index fad696b2..124abb2e 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -35,7 +35,9 @@ module.exports = (win, options, refreshMenu) => { return; } - const playlist = await ytpl(playlistID, { limit: Infinity }); + const playlist = await ytpl(playlistID, + { limit: options.playlistMaxItems || Infinity } + ); const playlistTitle = playlist.title; const folder = getFolder(options.downloadFolder); @@ -63,7 +65,7 @@ module.exports = (win, options, refreshMenu) => { ); } - playlist.items.slice(0, options.playlistMaxItems).forEach((song) => { + playlist.items.forEach((song) => { win.webContents.send( "downloader-download-playlist", song, diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index 27b9b3a5..d0a8f997 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -198,7 +198,7 @@ ipcRenderer.on( }, reinit, options, - songMetadata, + null, playlistFolder ); } From 13fb686188b6a39c16e565e9b87bad14638f86ca Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 03:33:49 +0300 Subject: [PATCH 07/11] started playlist downlaod messageBox --- plugins/downloader/menu.js | 12 ++++++++++-- plugins/downloader/youtube-dl.js | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index 124abb2e..ed2a06ad 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -35,7 +35,7 @@ module.exports = (win, options, refreshMenu) => { return; } - const playlist = await ytpl(playlistID, + const playlist = await ytpl(playlistID, { limit: options.playlistMaxItems || Infinity } ); const playlistTitle = playlist.title; @@ -59,6 +59,14 @@ module.exports = (win, options, refreshMenu) => { downloadLabel = `Downloading "${playlistTitle}"`; refreshMenu(); + dialog.showMessageBox({ + type: "info", + buttons: ["OK"], + title: "Started Download", + message: `Downloading Playlist "${playlistTitle}"`, + detail: `(${playlist.items.length} songs)`, + }); + if (is.dev()) { console.log( `Downloading playlist "${playlistTitle}" (${playlist.items.length} songs)` @@ -68,7 +76,7 @@ module.exports = (win, options, refreshMenu) => { playlist.items.forEach((song) => { win.webContents.send( "downloader-download-playlist", - song, + song.url, playlistTitle, options ); diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index d0a8f997..53f20135 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -183,12 +183,12 @@ module.exports = { ipcRenderer.on( "downloader-download-playlist", - (_, songMetadata, playlistFolder, options) => { + (_, url, playlistFolder, options) => { const reinit = () => ipcRenderer.send("downloader-feedback", defaultMenuDownloadLabel); downloadVideoToMP3( - songMetadata.url, + url, (feedback) => { ipcRenderer.send("downloader-feedback", feedback); }, From 53bf7c5068fdc14f5aa469d47b3174d27f40e05c Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 04:41:58 +0300 Subject: [PATCH 08/11] playlist download progressBar using `chokidar` --- package.json | 1 + plugins/downloader/menu.js | 26 ++++++++++----- plugins/downloader/youtube-dl.js | 10 ++---- yarn.lock | 57 +++++++++++++++++++++++++++++--- 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 1ab2c648..e8152e7b 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0", "async-mutex": "^0.3.1", "browser-id3-writer": "^4.4.0", + "chokidar": "^3.5.1", "custom-electron-titlebar": "^3.2.6", "discord-rpc": "^3.2.0", "electron-debug": "^3.2.0", diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index ed2a06ad..490a1975 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -5,6 +5,7 @@ const { URL } = require("url"); const { dialog, ipcMain } = require("electron"); const is = require("electron-is"); const ytpl = require("ytpl"); +const chokidar = require('chokidar'); const { setOptions } = require("../../config/plugins"); const getSongInfo = require("../../providers/song-info"); @@ -51,14 +52,6 @@ module.exports = (win, options, refreshMenu) => { } mkdirSync(playlistFolder, { recursive: true }); - ipcMain.on("downloader-feedback", (_, feedback) => { - downloadLabel = feedback; - refreshMenu(); - }); - - downloadLabel = `Downloading "${playlistTitle}"`; - refreshMenu(); - dialog.showMessageBox({ type: "info", buttons: ["OK"], @@ -73,6 +66,23 @@ module.exports = (win, options, refreshMenu) => { ); } + const steps = 1 / playlist.items.length; + let progress = 0; + + win.setProgressBar(2); // starts with indefinite bar + + let dirWatcher = chokidar.watch(playlistFolder); + dirWatcher.on('add', () => { + console.log(`progress:${progress} + steps:${steps} = newProgress:${progress+steps}`) + progress += steps; + if (progress >= 0.999) { + win.setProgressBar(-1); // close progress bar + dirWatcher.close().then(() => dirWatcher = null); + } else { + win.setProgressBar(progress); + } + }); + playlist.items.forEach((song) => { win.webContents.send( "downloader-download-playlist", diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index 53f20135..1a79f5fa 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -184,19 +184,13 @@ module.exports = { ipcRenderer.on( "downloader-download-playlist", (_, url, playlistFolder, options) => { - const reinit = () => - ipcRenderer.send("downloader-feedback", defaultMenuDownloadLabel); - downloadVideoToMP3( url, - (feedback) => { - ipcRenderer.send("downloader-feedback", feedback); - }, + () => {}, (error) => { triggerAction(CHANNEL, ACTIONS.ERROR, error); - reinit(); }, - reinit, + () => {}, options, null, playlistFolder diff --git a/yarn.lock b/yarn.lock index 7f6265bd..139c3749 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1638,6 +1638,14 @@ anymatch@^3.0.3: normalize-path "^3.0.0" picomatch "^2.0.4" +anymatch@~3.1.1: + version "3.1.2" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-3.1.2.tgz#c0557c096af32f106198f4f4e2a383537e378716" + integrity sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg== + dependencies: + normalize-path "^3.0.0" + picomatch "^2.0.4" + app-builder-bin@3.5.12: version "3.5.12" resolved "https://registry.yarnpkg.com/app-builder-bin/-/app-builder-bin-3.5.12.tgz#bbe174972cc1f481f73d6d92ad47a8b4c7eb4530" @@ -1991,6 +1999,11 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +binary-extensions@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" + integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== + binaryextensions@^4.15.0: version "4.15.0" resolved "https://registry.yarnpkg.com/binaryextensions/-/binaryextensions-4.15.0.tgz#c63a502e0078ff1b0e9b00a9f74d3c2b0f8bd32e" @@ -2075,7 +2088,7 @@ braces@^2.3.1: split-string "^3.0.2" to-regex "^3.0.1" -braces@^3.0.1: +braces@^3.0.1, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" integrity sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== @@ -2404,6 +2417,21 @@ charenc@0.0.2: resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667" integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc= +chokidar@^3.5.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.1.tgz#ee9ce7bbebd2b79f49f304799d5468e31e14e68a" + integrity sha512-9+s+Od+W0VJJzawDma/gvBNQqkTiqYTWLuZoyAsivsI4AaWTCzHG06/TMjsf1cYe9Cb97UCEhjz7HvnPk2p/tw== + dependencies: + anymatch "~3.1.1" + braces "~3.0.2" + glob-parent "~5.1.0" + is-binary-path "~2.1.0" + is-glob "~4.0.1" + normalize-path "~3.0.0" + readdirp "~3.5.0" + optionalDependencies: + fsevents "~2.3.1" + chownr@^1.1.1: version "1.1.4" resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b" @@ -4257,7 +4285,7 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= -fsevents@^2.1.2: +fsevents@^2.1.2, fsevents@~2.3.1: version "2.3.2" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== @@ -4370,6 +4398,13 @@ glob-parent@^5.0.0, glob-parent@^5.1.0: dependencies: is-glob "^4.0.1" +glob-parent@~5.1.0: + version "5.1.2" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" + integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow== + dependencies: + is-glob "^4.0.1" + glob-to-regexp@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.3.0.tgz#8c5a1494d2066c570cc3bfe4496175acc4d502ab" @@ -4902,6 +4937,13 @@ is-arrayish@^0.2.1: resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" integrity sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= +is-binary-path@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09" + integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== + dependencies: + binary-extensions "^2.0.0" + is-buffer@^1.1.5, is-buffer@~1.1.6: version "1.1.6" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be" @@ -5032,7 +5074,7 @@ is-glob@^3.1.0: dependencies: is-extglob "^2.1.0" -is-glob@^4.0.0, is-glob@^4.0.1: +is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.1.tgz#7567dbe9f2f5e2467bc77ab83c4a29482407a5dc" integrity sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== @@ -6581,7 +6623,7 @@ normalize-path@^2.1.1: dependencies: remove-trailing-separator "^1.0.1" -normalize-path@^3.0.0: +normalize-path@^3.0.0, normalize-path@~3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== @@ -7477,6 +7519,13 @@ readdir-glob@^1.0.0: dependencies: minimatch "^3.0.4" +readdirp@~3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.5.0.tgz#9ba74c019b15d365278d2e91bb8c48d7b4d42c9e" + integrity sha512-cMhu7c/8rdhkHXWsY+osBhfSy0JikwpHK/5+imo+LpeasTF8ouErHrlYkwT0++njiyuDvc7OFY5T3ukvZ8qmFQ== + dependencies: + picomatch "^2.2.1" + redent@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-3.0.0.tgz#e557b7998316bb53c9f1f56fa626352c6963059f" From 2d6e858e8fd00ec3ece60e81e794f74245ed51d7 Mon Sep 17 00:00:00 2001 From: Araxeus Date: Thu, 6 May 2021 04:43:31 +0300 Subject: [PATCH 09/11] lint --- plugins/downloader/menu.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index 490a1975..fb378606 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -73,9 +73,8 @@ module.exports = (win, options, refreshMenu) => { let dirWatcher = chokidar.watch(playlistFolder); dirWatcher.on('add', () => { - console.log(`progress:${progress} + steps:${steps} = newProgress:${progress+steps}`) progress += steps; - if (progress >= 0.999) { + if (progress >= 0.9999) { win.setProgressBar(-1); // close progress bar dirWatcher.close().then(() => dirWatcher = null); } else { From 8b471c07726f0b8317469b3b9426c860b088e47a Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 7 May 2021 04:47:24 +0300 Subject: [PATCH 10/11] create `cleanupArtistName()` in song-info --- config/defaults.js | 1 - plugins/downloader/menu.js | 3 ++- plugins/downloader/youtube-dl.js | 12 +++--------- plugins/last-fm/back.js | 21 ++++----------------- providers/song-info.js | 17 ++++++++++++++++- 5 files changed, 25 insertions(+), 29 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index 2a084737..12f6a248 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -41,7 +41,6 @@ const defaultConfig = { api_root: "http://ws.audioscrobbler.com/2.0/", api_key: "04d76faaac8726e60988e14c105d421a", // api key registered by @semvis123 secret: "a5d2a36fdf64819290f6982481eaffa2", - suffixesToRemove: [' - Topic', 'VEVO'] // removes suffixes of the artist name, for better recognition }, discord: { enabled: false, diff --git a/plugins/downloader/menu.js b/plugins/downloader/menu.js index fb378606..f5b99d73 100644 --- a/plugins/downloader/menu.js +++ b/plugins/downloader/menu.js @@ -16,7 +16,7 @@ let downloadLabel = defaultMenuDownloadLabel; let metadataURL = undefined; let callbackIsRegistered = false; -module.exports = (win, options, refreshMenu) => { +module.exports = (win, options) => { if (!callbackIsRegistered) { const registerCallback = getSongInfo(win); registerCallback((info) => { @@ -36,6 +36,7 @@ module.exports = (win, options, refreshMenu) => { return; } + console.log("trying to get playlist ID" +playlistID); const playlist = await ytpl(playlistID, { limit: options.playlistMaxItems || Infinity } ); diff --git a/plugins/downloader/youtube-dl.js b/plugins/downloader/youtube-dl.js index 1a79f5fa..814d9924 100644 --- a/plugins/downloader/youtube-dl.js +++ b/plugins/downloader/youtube-dl.js @@ -14,7 +14,8 @@ const ytdl = require("ytdl-core"); const { triggerAction, triggerActionSync } = require("../utils"); const { ACTIONS, CHANNEL } = require("./actions.js"); -const { defaultMenuDownloadLabel, getFolder } = require("./utils"); +const { getFolder } = require("./utils"); +const { cleanupArtistName } = require("../../providers/song-info"); const { createFFmpeg } = FFmpeg; const ffmpeg = createFFmpeg({ @@ -24,13 +25,6 @@ const ffmpeg = createFFmpeg({ }); const ffmpegMutex = new Mutex(); -function noTopic(channelName) { - if (channelName && channelName.endsWith(" - Topic")) { - channelName = channelName.slice(0, -8); - } - return channelName; -} - const downloadVideoToMP3 = async ( videoUrl, sendFeedback, @@ -46,7 +40,7 @@ const downloadVideoToMP3 = async ( const info = await ytdl.getInfo(videoUrl); const thumbnails = info.videoDetails?.author?.thumbnails; metadata = { - artist: info.videoDetails?.media?.artist || noTopic(info.videoDetails?.author?.name) || "", + artist: info.videoDetails?.media?.artist || cleanupArtistName(info.videoDetails?.author?.name) || "", title: info.videoDetails?.media?.song || info.videoDetails?.title || "", imageSrc: thumbnails ? thumbnails[thumbnails.length - 1].url : "" } diff --git a/plugins/last-fm/back.js b/plugins/last-fm/back.js index a34a0a19..efa4f41e 100644 --- a/plugins/last-fm/back.js +++ b/plugins/last-fm/back.js @@ -5,21 +5,10 @@ const { setOptions } = require('../../config/plugins'); const getSongInfo = require('../../providers/song-info'); const defaultConfig = require('../../config/defaults'); -const cleanupArtistName = (config, artist) => { - // removes the suffixes of the artist name for more recognition by last.fm - const { suffixesToRemove } = config; - if (suffixesToRemove === undefined) return artist; - - for (suffix of suffixesToRemove) { - artist = artist.replace(suffix, ''); - } - return artist; -} - const createFormData = params => { // creates the body for in the post request const formData = new URLSearchParams(); - for (key in params) { + for (const key in params) { formData.append(key, params[key]); } return formData; @@ -28,7 +17,7 @@ const createQueryString = (params, api_sig) => { // creates a querystring const queryData = []; params.api_sig = api_sig; - for (key in params) { + for (const key in params) { queryData.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`); } return '?'+queryData.join('&'); @@ -37,12 +26,12 @@ const createQueryString = (params, api_sig) => { const createApiSig = (params, secret) => { // this function creates the api signature, see: https://www.last.fm/api/authspec const keys = []; - for (key in params) { + for (const key in params) { keys.push(key); } keys.sort(); let sig = ''; - for (key of keys) { + for (const key of keys) { if (String(key) === 'format') continue sig += `${key}${params[key]}`; @@ -157,8 +146,6 @@ const lastfm = async (win, config) => { registerCallback( songInfo => { // set remove the old scrobble timer clearTimeout(scrobbleTimer); - // make the artist name a bit cleaner - songInfo.artist = cleanupArtistName(config, songInfo.artist); if (!songInfo.isPaused) { setNowPlaying(songInfo, config); // scrobble when the song is half way through, or has passed the 4 minute mark diff --git a/providers/song-info.js b/providers/song-info.js index 02ba6dec..6833fb8f 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -58,7 +58,7 @@ const songInfo = { const handleData = async (responseText, win) => { let data = JSON.parse(responseText); songInfo.title = data.videoDetails?.media?.song || data?.videoDetails?.title; - songInfo.artist = data.videoDetails?.media?.artist || await getArtist(win) || data?.videoDetails?.author; + songInfo.artist = data.videoDetails?.media?.artist || await getArtist(win) || cleanupArtistName(data?.videoDetails?.author); songInfo.views = data?.videoDetails?.viewCount; songInfo.imageSrc = data?.videoDetails?.thumbnail?.thumbnails?.pop()?.url; songInfo.songDuration = data?.videoDetails?.lengthSeconds; @@ -102,5 +102,20 @@ const registerProvider = (win) => { return registerCallback; }; +const suffixesToRemove = [' - Topic', 'VEVO']; +function cleanupArtistName(artist) { + if (!artist) { + return artist; + } + for (const suffix of suffixesToRemove) { + if (artist.endsWith(suffix)) { + return artist.slice(0, -suffix.length) + } + } + return artist; +} + module.exports = registerProvider; module.exports.getImage = getImage; +module.exports.cleanupArtistName = cleanupArtistName; + From 1140c3e2e7924d054df51b61147ddb47131f167c Mon Sep 17 00:00:00 2001 From: Araxeus Date: Fri, 7 May 2021 23:40:14 +0300 Subject: [PATCH 11/11] lint --- plugins/downloader/back.js | 2 +- providers/song-info.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/downloader/back.js b/plugins/downloader/back.js index 31a929aa..ac32623d 100644 --- a/plugins/downloader/back.js +++ b/plugins/downloader/back.js @@ -47,7 +47,7 @@ function handle(win) { const songMetadata = { ...metadata, ...currentMetadata }; if (!songMetadata.image && songMetadata.imageSrc) { - songMetadata.image = await getImage(songMetadata.imageSrc) + songMetadata.image = await getImage(songMetadata.imageSrc); } try { diff --git a/providers/song-info.js b/providers/song-info.js index 6833fb8f..15b51459 100644 --- a/providers/song-info.js +++ b/providers/song-info.js @@ -38,7 +38,7 @@ const getArtist = async (win) => { artistName.textContent; } ` - ) + ); } // Fill songInfo with empty values @@ -109,7 +109,7 @@ function cleanupArtistName(artist) { } for (const suffix of suffixesToRemove) { if (artist.endsWith(suffix)) { - return artist.slice(0, -suffix.length) + return artist.slice(0, -suffix.length); } } return artist;