Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to download rejected songs #4

Merged
merged 2 commits into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,27 @@ ipcMain.handle("showDialog", async () => {
return filePaths[0];
});

let client: Daunroda;

// Download
ipcMain.handle("download", (e, config) => {
const client = new Daunroda(config);
client = new Daunroda(config);

client.on("info", (info) => e.sender.send("info", info));
client.on("debug", (debug) => e.sender.send("debug", debug));
client.on("error", (error) => e.sender.send("error", error));
client.on("progress", (prog) => e.sender.send("progress", prog));
client.on("downloadMaybe", (download) =>
e.sender.send("downloadMaybe", JSON.stringify(download))
);

client.run().catch((err) => e.sender.send("error", err));
});

ipcMain.handle("downloadSingle", (e, download) => {
client.downloadSingle(JSON.parse(download));
});

ipcMain.handle("version", () => {
return app.getVersion();
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "daunroda-app",
"version": "0.0.1-alpha.9",
"version": "0.0.1-alpha.10",
"private": true,
"description": "The official Daunroda app to easily download Spotify playlists.",
"author": "Alex Kovacs <[email protected]>",
Expand All @@ -13,7 +13,7 @@
"main": "dist/electron/main/index.js",
"dependencies": {
"@sapphire/fetch": "^2.4.1",
"daunroda": "https://github.com/daunroda/daunroda-app-package#7775c66116853de58d6a94a161cae137f878fe32",
"daunroda": "https://github.com/daunroda/daunroda-app-package#20228f8d9c09736f93f5d3afcb8909522a6a9e0b",
"electron-updater": "^5.2.1",
"fluent-ffmpeg": "https://github.com/alexthemaster/node-fluent-ffmpeg.git#commit=86418dd02dfb9554ce2becaafda20c66447b0d84",
"spotify-web-api-node": "^5.0.2"
Expand Down
48 changes: 47 additions & 1 deletion src/components/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,35 @@
</div>
</div>

<div class="modal" :class="downloadMaybeQueue.length >= 1 ? 'is-active' : ''">
<div class="modal-background"></div>
<div class="modal-content">
<p class="has-text-white">
Found {{ downloadMaybeQueue[0]?.res.name }} on YouTube (named
{{
downloadMaybeQueue[0]?.res.name ??
downloadMaybeQueue[0]?.res.title ??
""
}}) but it was rejected because of {{ downloadMaybeQueue[0]?.reason }}.
Do you want to download
<a
@click="
open(
`https://music.youtube.com/watch?v=${downloadMaybeQueue[0]?.res.id}`
)
"
>
this
</a>
anyway?
</p>
</div>
<button class="button is-success" @click="downloadSingle()">
Download
</button>
<button class="button" @click="downloadMaybeQueue.shift()">Cancel</button>
</div>

<div :hidden="Array.from(progress.values()).some((prog) => !prog.finished)">
<router-link to="/" class="button is-primary">
<font-awesome-icon class="icon" icon="fa-solid fa-house" />
Expand All @@ -78,7 +107,7 @@
/// <reference types="spotify-api" />

import { defineComponent } from "@vue/runtime-core";
import { ipcRenderer } from "electron";
import { ipcRenderer, shell } from "electron";
import { inspect } from "util";
import type { StoreConfig } from "../store.js";
import { loadConfig, store } from "../store.js";
Expand All @@ -94,13 +123,18 @@ export default defineComponent({
{ downloaded: number; total: number; finished: boolean }
>;
info: string;
downloadMaybeQueue: {
res: { name?: string; id?: string; title?: string };
reason: string;
}[];
} {
return {
playlists: [],
store,
download: [],
progress: new Map(),
info: "",
downloadMaybeQueue: [],
};
},
methods: {
Expand All @@ -115,6 +149,13 @@ export default defineComponent({

ipcRenderer.invoke("download", config);
},
async downloadSingle() {
const download = this.downloadMaybeQueue.shift();
ipcRenderer.invoke("downloadSingle", JSON.stringify(download));
},
open(url: string) {
shell.openExternal(url);
},
selectAll() {
this.download = this.playlists.map((playlist) => playlist.id);
},
Expand All @@ -133,9 +174,14 @@ export default defineComponent({
finished: prog.finished,
})
);

ipcRenderer.on("info", (e, info) => (this.info += `\n${info}`));
ipcRenderer.on("error", (e, error) => (this.info += `\n${inspect(error)}`));
ipcRenderer.on("debug", (e, debug) => console.log(debug));
ipcRenderer.on("downloadMaybe", (e, download) => {
download = JSON.parse(download);
this.downloadMaybeQueue.push(download);
});
},
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ __metadata:
"@vitejs/plugin-vue": ^3.1.0
"@vue/eslint-config-prettier": ^7.0.0
"@vue/eslint-config-typescript": ^11.0.2
daunroda: "https://github.com/daunroda/daunroda-app-package#7775c66116853de58d6a94a161cae137f878fe32"
daunroda: "https://github.com/daunroda/daunroda-app-package#20228f8d9c09736f93f5d3afcb8909522a6a9e0b"
electron: ^20.3.0
electron-builder: ^23.5.1
electron-updater: ^5.2.1
Expand All @@ -1692,9 +1692,9 @@ __metadata:
languageName: unknown
linkType: soft

"daunroda@https://github.com/daunroda/daunroda-app-package#7775c66116853de58d6a94a161cae137f878fe32":
"daunroda@https://github.com/daunroda/daunroda-app-package#20228f8d9c09736f93f5d3afcb8909522a6a9e0b":
version: 1.1.3
resolution: "daunroda@https://github.com/daunroda/daunroda-app-package.git#commit=7775c66116853de58d6a94a161cae137f878fe32"
resolution: "daunroda@https://github.com/daunroda/daunroda-app-package.git#commit=20228f8d9c09736f93f5d3afcb8909522a6a9e0b"
dependencies:
"@sapphire/stopwatch": ^1.4.1
"@skyra/jaro-winkler": ^1.1.0
Expand All @@ -1705,7 +1705,7 @@ __metadata:
undici: ^5.10.0
youtubei.js: ^2.2.1
ytdl-core: ^4.11.2
checksum: 7ed1514924d43ad8bca936057320072ee19eb8a3c0f1123b0be3454723a88b32b5fd87f3d5ee4a512cb050390a2ef2f153b6033aee11bc93bdc8a8e323d04547
checksum: e112fc2454486ad43626217929753974b7bfa67d98a254f1a7ac62569a66f1724f93d7061bbae279e91fd75f356da4496f23223a48fcd9746126da9dd5c5b34f
languageName: node
linkType: hard

Expand Down