added download dir selector

This commit is contained in:
Daniel Haller 2024-04-21 14:46:59 +02:00
parent ab4bdf9f79
commit df16ee7a1e
3 changed files with 42 additions and 10 deletions

View File

@ -2,7 +2,7 @@
"name": "crunchyroll-downloader", "name": "crunchyroll-downloader",
"author": "Stratum", "author": "Stratum",
"description": "Crunchyroll Downloader", "description": "Crunchyroll Downloader",
"version": "1.0.0", "version": "1.0.1",
"private": true, "private": true,
"main": ".output/src/electron/background.js", "main": ".output/src/electron/background.js",
"scripts": { "scripts": {

View File

@ -64,7 +64,7 @@
<div class="relative flex flex-col"> <div class="relative flex flex-col">
<input v-model="url" type="text" name="text" placeholder="URL" class="bg-[#5c5b5b] focus:outline-none px-3 py-2 rounded-xl text-sm text-center" /> <input v-model="url" type="text" name="text" placeholder="URL" class="bg-[#5c5b5b] focus:outline-none px-3 py-2 rounded-xl text-sm text-center" />
</div> </div>
<!-- <div class="relative flex flex-col"> <div class="relative flex flex-col">
<input <input
@click="getFolderPath()" @click="getFolderPath()"
v-model="path" v-model="path"
@ -74,7 +74,7 @@
class="bg-[#5c5b5b] focus:outline-none px-3 py-2 rounded-xl text-sm text-center cursor-pointer" class="bg-[#5c5b5b] focus:outline-none px-3 py-2 rounded-xl text-sm text-center cursor-pointer"
readonly readonly
/> />
</div> --> </div>
<div class="relative flex flex-col mt-auto"> <div class="relative flex flex-col mt-auto">
<button @click="switchToSeason" class="relative py-3 border-2 rounded-xl flex flex-row items-center justify-center"> <button @click="switchToSeason" class="relative py-3 border-2 rounded-xl flex flex-row items-center justify-center">
<div class="flex flex-row items-center justify-center transition-all" :class="isFetchingSeasons ? 'opacity-0' : 'opacity-100'"> <div class="flex flex-row items-center justify-center transition-all" :class="isFetchingSeasons ? 'opacity-0' : 'opacity-100'">
@ -318,11 +318,12 @@ const handleInputChange = () => {
debounceFetchSearch() debounceFetchSearch()
} }
if (process.client) { onMounted(() => {
;(window as any).myAPI.getFolder().then((result: any) => { ;(window as any).myAPI.getFolder().then((result: any) => {
path.value = result path.value = result
}) })
} })
const getFolderPath = () => { const getFolderPath = () => {
if (process.client) { if (process.client) {
;(window as any).myAPI.selectFolder().then((result: any) => { ;(window as any).myAPI.selectFolder().then((result: any) => {

View File

@ -197,7 +197,8 @@ async function checkPlaylists() {
e.dataValues.media.series_title, e.dataValues.media.series_title,
e.dataValues.media.season_number, e.dataValues.media.season_number,
e.dataValues.media.episode_number, e.dataValues.media.episode_number,
e.dataValues.quality e.dataValues.quality,
e.dataValues.dir
) )
} }
} }
@ -262,8 +263,27 @@ async function createFolder() {
} }
} }
async function createFolderName(name: string) { async function checkDirectoryExistence(dir: string) {
const folderPath = path.join(app.getPath('documents'), name) try {
await fs.promises.access(dir)
console.log(`Directory ${dir} exists.`)
return true
} catch (error) {
console.log(`Directory ${dir} does not exist.`)
return false
}
}
async function createFolderName(name: string, dir: string) {
var folderPath
const dirExists = await checkDirectoryExistence(dir)
if (dirExists) {
folderPath = path.join(dir, name)
} else {
folderPath = path.join(app.getPath('documents'), name)
}
try { try {
await fs.promises.access(folderPath) await fs.promises.access(folderPath)
@ -322,7 +342,18 @@ var downloading: Array<{
downloadSpeed: number downloadSpeed: number
}> = [] }> = []
export async function downloadPlaylist(e: string, dubs: Array<string>, subs: Array<string>, hardsub: boolean, downloadID: number, name: string, season: number, episode: number, quality: 1080 | 720 | 480 | 360 | 240) { export async function downloadPlaylist(
e: string,
dubs: Array<string>,
subs: Array<string>,
hardsub: boolean,
downloadID: number,
name: string,
season: number,
episode: number,
quality: 1080 | 720 | 480 | 360 | 240,
downloadPath: string
) {
downloading.push({ downloading.push({
id: downloadID, id: downloadID,
downloadedParts: 0, downloadedParts: 0,
@ -361,7 +392,7 @@ export async function downloadPlaylist(e: string, dubs: Array<string>, subs: Arr
const videoFolder = await createFolder() const videoFolder = await createFolder()
const seasonFolder = await createFolderName(`${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season}`) const seasonFolder = await createFolderName(`${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season}`, downloadPath)
const dubDownloadList: Array<{ const dubDownloadList: Array<{
audio_locale: string audio_locale: string