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",
"author": "Stratum",
"description": "Crunchyroll Downloader",
"version": "1.0.0",
"version": "1.0.1",
"private": true,
"main": ".output/src/electron/background.js",
"scripts": {

View File

@ -64,7 +64,7 @@
<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" />
</div>
<!-- <div class="relative flex flex-col">
<div class="relative flex flex-col">
<input
@click="getFolderPath()"
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"
readonly
/>
</div> -->
</div>
<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">
<div class="flex flex-row items-center justify-center transition-all" :class="isFetchingSeasons ? 'opacity-0' : 'opacity-100'">
@ -318,11 +318,12 @@ const handleInputChange = () => {
debounceFetchSearch()
}
if (process.client) {
onMounted(() => {
;(window as any).myAPI.getFolder().then((result: any) => {
path.value = result
})
}
})
const getFolderPath = () => {
if (process.client) {
;(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.season_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) {
const folderPath = path.join(app.getPath('documents'), name)
async function checkDirectoryExistence(dir: string) {
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 {
await fs.promises.access(folderPath)
@ -322,7 +342,18 @@ var downloading: Array<{
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({
id: downloadID,
downloadedParts: 0,
@ -361,7 +392,7 @@ export async function downloadPlaylist(e: string, dubs: Array<string>, subs: Arr
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<{
audio_locale: string