diff --git a/pages/index.vue b/pages/index.vue
index 01cdb3e..2b81e3e 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -56,7 +56,10 @@
{{ p.status }}
-
+
{{ p.status }}
@@ -94,12 +97,19 @@
{{ a.status }} Audio {{ a.audio }}
+
+
+ {{ a.status }} Audio {{ a.audio }}
+
diff --git a/src/api/routes/crunchyroll/crunchyroll.service.ts b/src/api/routes/crunchyroll/crunchyroll.service.ts
index e24478a..d70dd44 100644
--- a/src/api/routes/crunchyroll/crunchyroll.service.ts
+++ b/src/api/routes/crunchyroll/crunchyroll.service.ts
@@ -445,6 +445,38 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
playlist = data
} else {
const error = await response.text()
+ const errorJSON: {
+ activeStreams: {
+ accountId: string
+ active: boolean
+ assetId: string
+ clientId: string
+ contentId: string
+ country: string
+ createdTimestamp: string
+ deviceSubtype: string
+ deviceType: string
+ episodeIdentity: string
+ id: string
+ token: string
+ }[]
+ } = await JSON.parse(error)
+
+ if (errorJSON && errorJSON.activeStreams && errorJSON.activeStreams.length !== 0) {
+ for (const e of errorJSON.activeStreams) {
+ await deleteVideoToken(e.contentId, e.token)
+ }
+
+ server.logger.log({
+ level: 'error',
+ message: 'Refetching Crunchyroll Video Playlist & Deleting all Video Token because too many streams',
+ error: errorJSON,
+ timestamp: new Date().toISOString(),
+ section: 'playlistCrunchyrollFetch'
+ })
+
+ return await crunchyGetPlaylist(q, geo)
+ }
messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll Video Playlist', 'Failed to get Crunchyroll Video Playlist', error)
server.logger.log({
@@ -512,7 +544,38 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
await deleteVideoToken(q, dataProx.token)
} else {
- decrementPlaylistCounter();
+ decrementPlaylistCounter()
+ const error = await responseProx.text()
+ const errorJSON: {
+ activeStreams: {
+ accountId: string
+ active: boolean
+ assetId: string
+ clientId: string
+ contentId: string
+ country: string
+ createdTimestamp: string
+ deviceSubtype: string
+ deviceType: string
+ episodeIdentity: string
+ id: string
+ token: string
+ }[]
+ } = await JSON.parse(error)
+
+ if (errorJSON && errorJSON.activeStreams && errorJSON.activeStreams.length !== 0) {
+ for (const e of errorJSON.activeStreams) {
+ await deleteVideoToken(e.contentId, e.token)
+ }
+
+ server.logger.log({
+ level: 'error',
+ message: 'Refetching Crunchyroll Video Playlist & Deleting all Video Token because too many streams',
+ error: errorJSON,
+ timestamp: new Date().toISOString(),
+ section: 'playlistCrunchyrollFetch'
+ })
+ }
}
}
}
diff --git a/src/api/services/audio.ts b/src/api/services/audio.ts
index 1f7cb0d..0137ea8 100644
--- a/src/api/services/audio.ts
+++ b/src/api/services/audio.ts
@@ -52,7 +52,7 @@ export async function downloadMPDAudio(
while (!downloadSuccess) {
try {
const stream = fs.createWriteStream(`${path}/${part.filename}`)
- await fetchAndPipe(part.url, stream, index + 1)
+ await fetchAndPipe(part.url, stream, index + 1, downloadID, name)
downloadSuccess = true
} catch (error) {
retries++
@@ -73,12 +73,18 @@ export async function downloadMPDAudio(
return await mergePartsAudio(parts, path, dir, name, downloadID, drmkeys)
}
-async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number) {
+async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number, downloadID: number, name: string) {
try {
+
+ const dn = downloading.find((i) => i.id === downloadID && i.audio === name)
+
const response = await fetch(url)
// Check if fetch was successful
if (!response.ok) {
+ if (dn) {
+ dn.status = 'failed'
+ }
server.logger.log({
level: 'error',
message: 'Error while downloading an Audio Fragment',
@@ -94,6 +100,9 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number)
// Check if the body exists and is readable
if (!body) {
+ if (dn) {
+ dn.status = 'failed'
+ }
server.logger.log({
level: 'error',
message: 'Error while downloading an Audio Fragment',
@@ -115,6 +124,9 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number)
resolve()
})
.on('error', (error) => {
+ if (dn) {
+ dn.status = 'failed'
+ }
server.logger.log({
level: 'error',
message: 'Error while downloading an Audio Fragment',