Skip to content

Commit

Permalink
Merge branch 'master' into interactive-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
th-ch authored May 2, 2021
2 parents 66517af + 2567702 commit 6082a65
Show file tree
Hide file tree
Showing 16 changed files with 1,299 additions and 633 deletions.
18 changes: 18 additions & 0 deletions config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ const defaultConfig = {
ffmpegArgs: [], // e.g. ["-b:a", "192k"] for an audio bitrate of 192kb/s
downloadFolder: undefined, // Custom download folder (absolute path)
},
"last-fm": {
enabled: false,
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,
activityTimoutEnabled: true, // if enabled, the discord rich presence gets cleared when music paused after the time specified below
Expand All @@ -46,6 +53,17 @@ const defaultConfig = {
unpauseNotification: false,
urgency: "normal", //has effect only on Linux
interactive: false //has effect only on Windows
},
"precise-volume": {
enabled: false,
steps: 1, //percentage of volume to change
arrowsShortcut: true, //enable ArrowUp + ArrowDown local shortcuts
globalShortcuts: {
enabled: false, // enable global shortcuts
volumeUp: "Shift+PageUp", // Keybind default can be changed
volumeDown: "Shift+PageDown"
},
savedVolume: undefined //plugin save volume between session here
}
},
};
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,38 @@
"npm": "Please use yarn and not npm"
},
"dependencies": {
"@cliqz/adblocker-electron": "^1.20.1",
"@cliqz/adblocker-electron": "^1.20.4",
"@ffmpeg/core": "^0.8.5",
"@ffmpeg/ffmpeg": "^0.9.7",
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.8.1",
"YoutubeNonStop": "git://github.com/lawfx/YoutubeNonStop.git#v0.9.0",
"async-mutex": "^0.3.1",
"browser-id3-writer": "^4.4.0",
"custom-electron-titlebar": "^3.2.6",
"discord-rpc": "^3.2.0",
"downloads-folder": "^3.0.1",
"electron-debug": "^3.2.0",
"electron-is": "^3.0.0",
"electron-localshortcut": "^3.2.1",
"electron-store": "^7.0.2",
"electron-store": "^7.0.3",
"electron-unhandled": "^3.0.2",
"electron-updater": "^4.3.6",
"electron-updater": "^4.3.8",
"filenamify": "^4.2.0",
"md5": "^2.3.0",
"node-fetch": "^2.6.1",
"node-notifier": "^9.0.1",
"ytdl-core": "^4.4.5",
"ytpl": "^2.0.5"
"node-notifier": "^9.0.1",
"open": "^8.0.3",
"ytdl-core": "^4.5.0",
"ytpl": "^2.1.1"
},
"devDependencies": {
"electron": "^11.2.3",
"electron-builder": "^22.9.1",
"electron": "^11.4.2",
"electron-builder": "^22.10.5",
"electron-devtools-installer": "^3.1.1",
"electron-icon-maker": "0.0.5",
"get-port": "^5.1.1",
"jest": "^26.6.3",
"rimraf": "^3.0.2",
"spectron": "^13.0.0",
"xo": "^0.37.1"
"xo": "^0.38.2"
},
"resolutions": {
"yargs-parser": "18.1.3"
Expand Down
15 changes: 7 additions & 8 deletions plugins/discord/back.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
const registerCallback = getSongInfo(win);

// If the page is ready, register the callback
win.on("ready-to-show", () => {
rpc.on("ready", () => {
win.once("ready-to-show", () => {
rpc.once("ready", () => {
// Register the callback
registerCallback((songInfo) => {
if (songInfo.title.length === 0 && songInfo.artist.length === 0) {
return;
}
// Song information changed, so lets update the rich presence
const activityInfo = {
details: songInfo.title,
Expand All @@ -36,8 +39,7 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
activityInfo.smallImageText = "idle/paused";
// Set start the timer so the activity gets cleared after a while if enabled
if (activityTimoutEnabled)
clearActivity = setTimeout(()=>rpc.clearActivity(), activityTimoutTime||10,000);

clearActivity = setTimeout(()=>rpc.clearActivity(), activityTimoutTime||10000);
} else {
// stop the clear activity timout
clearTimeout(clearActivity);
Expand All @@ -53,9 +55,6 @@ module.exports = (win, {activityTimoutEnabled, activityTimoutTime}) => {
});

// Startup the rpc client
rpc.login({
clientId,
})
.catch(console.error);
rpc.login({ clientId }).catch(console.error);
});
};
32 changes: 31 additions & 1 deletion plugins/downloader/back.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { writeFileSync } = require("fs");
const { join } = require("path");

const { dialog } = require("electron");
const ID3Writer = require("browser-id3-writer");
const { dialog, ipcMain } = require("electron");

const getSongInfo = require("../../providers/song-info");
const { injectCSS, listenAction } = require("../utils");
Expand Down Expand Up @@ -38,6 +40,34 @@ function handle(win) {
console.log("Unknown action: " + action);
}
});

ipcMain.on("add-metadata", (event, filePath, songBuffer, currentMetadata) => {
let fileBuffer = songBuffer;
const songMetadata = { ...metadata, ...currentMetadata };

try {
const coverBuffer = songMetadata.image.toPNG();
const writer = new ID3Writer(songBuffer);

// Create the metadata tags
writer
.setFrame("TIT2", songMetadata.title)
.setFrame("TPE1", [songMetadata.artist])
.setFrame("APIC", {
type: 3,
data: coverBuffer,
description: "",
});
writer.addTag();
fileBuffer = Buffer.from(writer.arrayBuffer);
} catch (error) {
sendError(win, error);
}

writeFileSync(filePath, fileBuffer);
// Notify the youtube-dl file
event.reply("add-metadata-done");
});
}

module.exports = handle;
Expand Down
2 changes: 1 addition & 1 deletion plugins/downloader/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ global.download = () => {
.getAttribute("href");
videoUrl = !videoUrl
? global.songInfo.url || window.location.href
: baseUrl + videoUrl;
: baseUrl + "/" + videoUrl;

downloadVideoToMP3(
videoUrl,
Expand Down
5 changes: 3 additions & 2 deletions plugins/downloader/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const downloadsFolder = require("downloads-folder");
const electron = require("electron");

module.exports.getFolder = (customFolder) => customFolder || downloadsFolder();
module.exports.getFolder = (customFolder) =>
customFolder || (electron.app || electron.remote.app).getPath("downloads");
module.exports.defaultMenuDownloadLabel = "Download playlist";
32 changes: 7 additions & 25 deletions plugins/downloader/youtube-dl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { randomBytes } = require("crypto");
const { writeFileSync } = require("fs");
const { join } = require("path");

const Mutex = require("async-mutex").Mutex;
const ID3Writer = require("browser-id3-writer");
const { ipcRenderer } = require("electron");
const is = require("electron-is");
const filenamify = require("filenamify");
Expand Down Expand Up @@ -126,35 +124,19 @@ const toMP3 = async (
: videoName;
const filename = filenamify(name + "." + extension, {
replacement: "_",
maxLength: 255,
});

const filePath = join(folder, subfolder, filename);
const fileBuffer = ffmpeg.FS("readFile", safeVideoName + "." + extension);

// Add the metadata
try {
const writer = new ID3Writer(fileBuffer);
if (metadata.image) {
const coverBuffer = metadata.image.toPNG();

// Create the metadata tags
writer
.setFrame("TIT2", metadata.title)
.setFrame("TPE1", [metadata.artist])
.setFrame("APIC", {
type: 3,
data: coverBuffer,
description: "",
});
writer.addTag();
}

writeFileSync(filePath, Buffer.from(writer.arrayBuffer));
} catch (error) {
sendError(error);
} finally {
reinit();
}
sendFeedback("Adding metadata…");
ipcRenderer.send("add-metadata", filePath, fileBuffer, {
artist: metadata.artist,
title: metadata.title,
});
ipcRenderer.once("add-metadata-done", reinit);
} catch (e) {
sendError(e);
} finally {
Expand Down
Loading

0 comments on commit 6082a65

Please sign in to comment.