diff --git a/components/Settings/Main.vue b/components/Settings/Main.vue index 44fcf1f..5ba6781 100644 --- a/components/Settings/Main.vue +++ b/components/Settings/Main.vue @@ -18,6 +18,10 @@ +
+
Max Concurrent Downloads
+ +
Default Dubs
@@ -115,6 +119,7 @@ const locales = ref>([ const selectedVideoQuality = ref() const selectedAudioQuality = ref() const selectedVideoFormat = ref() +const selectedMaxDownloads = ref() const toggleDub = (lang: { locale: string; name: string }) => { const index = dubLocales.value.findIndex((i) => i.locale === lang.locale) @@ -218,6 +223,18 @@ const selectOutputFormat = () => { } } +watch(selectedMaxDownloads, () => { + if (selectedMaxDownloads.value !== undefined && selectedMaxDownloads.value !== null) { + selectMaxDownloads() + } +}) + +const selectMaxDownloads = () => { + if (process.client) { + ;(window as any).myAPI.setDefaultMaxDownloads(selectedMaxDownloads.value) + } +} + onMounted(() => { ;(window as any).myAPI.getArray('defdubarray').then((result: any) => { dubLocales.value = JSON.parse(result) @@ -234,6 +251,9 @@ onMounted(() => { ;(window as any).myAPI.getDefaultOutputFormat().then((result: any) => { selectedVideoFormat.value = result }) + ;(window as any).myAPI.getDefaultMaxDownloads().then((result: any) => { + selectedMaxDownloads.value = result + }) }) diff --git a/src/api/routes/service/service.service.ts b/src/api/routes/service/service.service.ts index 3dbf4f1..0d1291f 100644 --- a/src/api/routes/service/service.service.ts +++ b/src/api/routes/service/service.service.ts @@ -269,14 +269,21 @@ export async function getDownloading(id: number) { // Define IsDownloading Count var isDownloading: number = 0 +var maxDownloading: number = 3 // Check Playlist every 2 seconds for new items async function checkPlaylists() { try { const eps = await Playlist.findAll({ where: { status: 'waiting' } }) + const maxd = await settings.get('DefaultMaxDownloads') as number + + if (maxd !== undefined && maxd !== null) { + maxDownloading = maxd + } + for (const e of eps) { - if (isDownloading < 3 && e.dataValues.status === 'waiting') { + if (isDownloading < maxDownloading && e.dataValues.status === 'waiting') { updatePlaylistByID(e.dataValues.id, 'preparing') isDownloading++ server.logger.log({ @@ -536,7 +543,12 @@ export async function downloadCrunchyrollPlaylist( var downloadDir: string = downloadPath - var isSeasonFolderActive = (await settings.get('seasonFolderActive')) as string + var isSeasonFolderActive = (await settings.get('seasonFolderActive')) as boolean + + if (isSeasonFolderActive === undefined || isSeasonFolderActive === null) { + await settings.set('seasonFolderActive', true) + isSeasonFolderActive = true + } if (isSeasonFolderActive) { var seasonFolderNaming = (await settings.get('SeasonTemp')) as string diff --git a/src/electron/background.ts b/src/electron/background.ts index 404457e..5f726dc 100644 --- a/src/electron/background.ts +++ b/src/electron/background.ts @@ -406,6 +406,24 @@ ipcMain.handle('dialog:getDefaultOutputFormatTemplate', async (events) => { return seTP }) +ipcMain.handle('dialog:setDefaultMaxDownloadsTemplate', async (events, max: number) => { + await settings.set('DefaultMaxDownloads', max) + + return max +}) + +ipcMain.handle('dialog:getDefaultMaxDownloadsTemplate', async (events) => { + const seTP = await settings.get('DefaultMaxDownloads') + + if (!seTP) { + await settings.set('DefaultMaxDownloads', 3) + + return 3 + } + + return seTP +}) + const openWindows = new Map() // Open New Window diff --git a/src/electron/preload.ts b/src/electron/preload.ts index fc969f1..8806b4d 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -32,5 +32,7 @@ contextBridge.exposeInMainWorld('myAPI', { setDefaultOutputFormat: (format: string) => ipcRenderer.invoke('dialog:setDefaultOutputFormatTemplate', format), getDefaultOutputFormat: () => ipcRenderer.invoke('dialog:getDefaultOutputFormatTemplate'), setDefaultCrunchyrollLanguage: (lang: string) => ipcRenderer.invoke('dialog:setDefaultCrunchyrollLanguageTemplate', lang), - getDefaultCrunchyrollLanguage: () => ipcRenderer.invoke('dialog:getDefaultCrunchyrollLanguageTemplate') + getDefaultCrunchyrollLanguage: () => ipcRenderer.invoke('dialog:getDefaultCrunchyrollLanguageTemplate'), + setDefaultMaxDownloads: (max: number) => ipcRenderer.invoke('dialog:setDefaultMaxDownloadsTemplate', max), + getDefaultMaxDownloads: () => ipcRenderer.invoke('dialog:getDefaultMaxDownloadsTemplate') })