added audio download failed status

This commit is contained in:
stratuma 2024-05-24 00:19:30 +02:00
parent 7e255b6fcc
commit fd480009c9
3 changed files with 90 additions and 5 deletions

View File

@ -56,7 +56,10 @@
<Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" /> <Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" />
{{ p.status }} {{ p.status }}
</div> </div>
<div v-if="p.status === 'downloading video'" class="flex flex-row items-center justify-center gap-1 text-xs capitalize p-1.5 bg-[#60501b] rounded-lg"> <div
v-if="p.status === 'downloading video'"
class="flex flex-row items-center justify-center gap-1 text-xs capitalize p-1.5 bg-[#60501b] rounded-lg"
>
<Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" /> <Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" />
{{ p.status }} {{ p.status }}
</div> </div>
@ -94,12 +97,19 @@
</div> </div>
<div v-for="a in p.audiosdownloading"> <div v-for="a in p.audiosdownloading">
<div <div
v-if="a.status && a.audio && a.status !== 'finished'" v-if="a.status && a.audio && a.status !== 'finished' && a.status !== 'failed'"
class="ml-2 flex flex-row items-center justify-center gap-1 text-xs capitalize p-1.5 bg-[#866332] rounded-lg" class="ml-2 flex flex-row items-center justify-center gap-1 text-xs capitalize p-1.5 bg-[#866332] rounded-lg"
> >
<Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" /> <Icon name="mdi:loading" class="h-3.5 w-3.5 text-white animate-spin" />
{{ a.status }} Audio {{ a.audio }} {{ a.status }} Audio {{ a.audio }}
</div> </div>
<div
v-if="a.status && a.audio && a.status === 'failed'"
class="flex flex-row items-center justify-center gap-1 text-xs capitalize p-1.5 bg-[#863232] rounded-lg"
>
<Icon name="bitcoin-icons:cross-filled" class="h-3.5 w-3.5 text-white" />
{{ a.status }} Audio {{ a.audio }}
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -445,6 +445,38 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
playlist = data playlist = data
} else { } else {
const error = await response.text() 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) messageBox('error', ['Cancel'], 2, 'Failed to get Crunchyroll Video Playlist', 'Failed to get Crunchyroll Video Playlist', error)
server.logger.log({ server.logger.log({
@ -512,7 +544,38 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
await deleteVideoToken(q, dataProx.token) await deleteVideoToken(q, dataProx.token)
} else { } 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'
})
}
} }
} }
} }

View File

@ -52,7 +52,7 @@ export async function downloadMPDAudio(
while (!downloadSuccess) { while (!downloadSuccess) {
try { try {
const stream = fs.createWriteStream(`${path}/${part.filename}`) 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 downloadSuccess = true
} catch (error) { } catch (error) {
retries++ retries++
@ -73,12 +73,18 @@ export async function downloadMPDAudio(
return await mergePartsAudio(parts, path, dir, name, downloadID, drmkeys) 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 { try {
const dn = downloading.find((i) => i.id === downloadID && i.audio === name)
const response = await fetch(url) const response = await fetch(url)
// Check if fetch was successful // Check if fetch was successful
if (!response.ok) { if (!response.ok) {
if (dn) {
dn.status = 'failed'
}
server.logger.log({ server.logger.log({
level: 'error', level: 'error',
message: 'Error while downloading an Audio Fragment', 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 // Check if the body exists and is readable
if (!body) { if (!body) {
if (dn) {
dn.status = 'failed'
}
server.logger.log({ server.logger.log({
level: 'error', level: 'error',
message: 'Error while downloading an Audio Fragment', message: 'Error while downloading an Audio Fragment',
@ -115,6 +124,9 @@ async function fetchAndPipe(url: string, stream: fs.WriteStream, index: number)
resolve() resolve()
}) })
.on('error', (error) => { .on('error', (error) => {
if (dn) {
dn.status = 'failed'
}
server.logger.log({ server.logger.log({
level: 'error', level: 'error',
message: 'Error while downloading an Audio Fragment', message: 'Error while downloading an Audio Fragment',