fetching crunchyroll video versions now independently
This commit is contained in:
parent
245a5b141c
commit
1914cb1bc6
@ -231,6 +231,66 @@ async function crunchyLoginFetch(user: string, passw: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function crunchyVersionsFetch(q: string) {
|
||||||
|
|
||||||
|
const account = await loggedInCheck('CR')
|
||||||
|
|
||||||
|
if (!account) return
|
||||||
|
|
||||||
|
const login = await crunchyLogin(account.username, account.password, 'LOCAL')
|
||||||
|
|
||||||
|
if (!login) return
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
Authorization: `Bearer ${login.access_token}`
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://beta-api.crunchyroll.com/content/v2/cms/objects/${q}?ratings=true&locale=en-US`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: headers,
|
||||||
|
credentials: 'same-origin'
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const data: {
|
||||||
|
data: {
|
||||||
|
episode_metadata: {
|
||||||
|
versions: {
|
||||||
|
audio_locale: string,
|
||||||
|
guid: string,
|
||||||
|
is_premium_only: boolean,
|
||||||
|
media_guid: string,
|
||||||
|
original: boolean,
|
||||||
|
season_guid: string,
|
||||||
|
variant: string,
|
||||||
|
geo: string
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}[]
|
||||||
|
} = JSON.parse(await response.text())
|
||||||
|
|
||||||
|
return data.data[0].episode_metadata.versions
|
||||||
|
} else {
|
||||||
|
const error = {
|
||||||
|
status: response.status,
|
||||||
|
message: await response.text()
|
||||||
|
}
|
||||||
|
throw new Error(JSON.stringify(error))
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
messageBox('error', ['Cancel'], 2, 'Failed to Fetch Crunchyroll Episode', 'Failed to Fetch Crunchyroll Episode', String(e))
|
||||||
|
server.logger.log({
|
||||||
|
level: 'error',
|
||||||
|
message: 'Failed to Fetch Crunchyroll Episode',
|
||||||
|
error: String(e),
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
section: 'episodeCrunchyrollFetch'
|
||||||
|
})
|
||||||
|
throw new Error(e as string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let counter = 0
|
let counter = 0
|
||||||
var maxLimit = 0
|
var maxLimit = 0
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { concatenateTSFiles } from '../../services/concatenate'
|
|||||||
import { checkFileExistence, createFolder, createFolderName, deleteFolder, deleteTemporaryFolders, getFilename } from '../../services/folder'
|
import { checkFileExistence, createFolder, createFolderName, deleteFolder, deleteTemporaryFolders, getFilename } from '../../services/folder'
|
||||||
import { downloadADNSub, downloadCRSub } from '../../services/subs'
|
import { downloadADNSub, downloadCRSub } from '../../services/subs'
|
||||||
import { CrunchyEpisode } from '../../types/crunchyroll'
|
import { CrunchyEpisode } from '../../types/crunchyroll'
|
||||||
import { checkAccountMaxStreams, crunchyGetMetadata, crunchyGetPlaylist, crunchyGetPlaylistMPD } from '../crunchyroll/crunchyroll.service'
|
import { checkAccountMaxStreams, crunchyGetMetadata, crunchyGetPlaylist, crunchyGetPlaylistMPD, crunchyVersionsFetch } from '../crunchyroll/crunchyroll.service'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
var cron = require('node-cron')
|
var cron = require('node-cron')
|
||||||
import { Readable } from 'stream'
|
import { Readable } from 'stream'
|
||||||
@ -536,6 +536,19 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
) {
|
) {
|
||||||
await updatePlaylistByID(downloadID, 'waiting for playlist')
|
await updatePlaylistByID(downloadID, 'waiting for playlist')
|
||||||
|
|
||||||
|
const versions = await crunchyVersionsFetch(e);
|
||||||
|
|
||||||
|
if (!versions) {
|
||||||
|
messageBox('error', ['Cancel'], 2, 'Failed to get versions', 'Failed to get versions', 'Failed to get versions')
|
||||||
|
server.logger.log({
|
||||||
|
level: 'error',
|
||||||
|
message: `Failed to get versions ${downloadID}`,
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
section: 'crunchyrollDownloadProcess'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var playlist = await crunchyGetPlaylist(e, geo)
|
var playlist = await crunchyGetPlaylist(e, geo)
|
||||||
|
|
||||||
if (!playlist) {
|
if (!playlist) {
|
||||||
@ -551,9 +564,9 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlist.data.versions && playlist.data.versions.length !== 0) {
|
if (versions && versions.length !== 0) {
|
||||||
if (playlist.data.audioLocale !== subs[0]) {
|
if (playlist.data.audioLocale !== subs[0]) {
|
||||||
const found = playlist.data.versions.find((v) => v.audio_locale === 'ja-JP')
|
const found = versions.find((v) => v.audio_locale === 'ja-JP')
|
||||||
if (found) {
|
if (found) {
|
||||||
playlist = await crunchyGetPlaylist(found.guid, found.geo)
|
playlist = await crunchyGetPlaylist(found.guid, found.geo)
|
||||||
} else {
|
} else {
|
||||||
@ -676,7 +689,7 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
var subPlaylist
|
var subPlaylist
|
||||||
|
|
||||||
if (playlist.data.audioLocale !== 'ja-JP') {
|
if (playlist.data.audioLocale !== 'ja-JP') {
|
||||||
const foundStream = playlist.data.versions.find((v) => v.audio_locale === 'ja-JP')
|
const foundStream = versions.find((v) => v.audio_locale === 'ja-JP')
|
||||||
if (foundStream) {
|
if (foundStream) {
|
||||||
subPlaylist = await crunchyGetPlaylist(foundStream.guid, foundStream.geo)
|
subPlaylist = await crunchyGetPlaylist(foundStream.guid, foundStream.geo)
|
||||||
}
|
}
|
||||||
@ -729,8 +742,8 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
|
|
||||||
for (const d of dubs) {
|
for (const d of dubs) {
|
||||||
var found
|
var found
|
||||||
if (playlist.data.versions) {
|
if (versions) {
|
||||||
found = playlist.data.versions.find((p) => p.audio_locale === d)
|
found = versions.find((p) => p.audio_locale === d)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
@ -745,7 +758,7 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
}
|
}
|
||||||
dubDownloadList.push(found)
|
dubDownloadList.push(found)
|
||||||
console.log(`Audio ${d}.aac found, adding to download`)
|
console.log(`Audio ${d}.aac found, adding to download`)
|
||||||
} else if (playlist.data.versions.length === 0) {
|
} else if (versions.length === 0) {
|
||||||
const foundSub = playlist.data.subtitles.find((sub) => sub.language === d)
|
const foundSub = playlist.data.subtitles.find((sub) => sub.language === d)
|
||||||
if (foundSub) {
|
if (foundSub) {
|
||||||
subDownloadList.push({ ...foundSub, isDub: true })
|
subDownloadList.push({ ...foundSub, isDub: true })
|
||||||
@ -768,7 +781,7 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (dubDownloadList.length === 0) {
|
if (dubDownloadList.length === 0) {
|
||||||
const jpVersion = playlist.data.versions.find((v) => v.audio_locale === 'ja-JP')
|
const jpVersion = versions.find((v) => v.audio_locale === 'ja-JP')
|
||||||
|
|
||||||
if (jpVersion) {
|
if (jpVersion) {
|
||||||
console.log('Using ja-JP Audio because no Audio in download list')
|
console.log('Using ja-JP Audio because no Audio in download list')
|
||||||
@ -951,11 +964,11 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
|
|
||||||
if (!playlist) return
|
if (!playlist) return
|
||||||
|
|
||||||
if (playlist.data.versions && playlist.data.versions.length !== 0) {
|
if (versions && versions.length !== 0) {
|
||||||
if (playlist.data.versions.find((p) => p.audio_locale === dubs[0])) {
|
if (versions.find((p) => p.audio_locale === dubs[0])) {
|
||||||
code = playlist.data.versions.find((p) => p.audio_locale === dubs[0])?.guid
|
code = versions.find((p) => p.audio_locale === dubs[0])?.guid
|
||||||
} else {
|
} else {
|
||||||
code = playlist.data.versions.find((p) => p.audio_locale === 'ja-JP')?.guid
|
code = versions.find((p) => p.audio_locale === 'ja-JP')?.guid
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
code = e
|
code = e
|
||||||
@ -1000,7 +1013,7 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
var hardsubGEO: string | undefined
|
var hardsubGEO: string | undefined
|
||||||
|
|
||||||
if (hardsub.format === 'dub') {
|
if (hardsub.format === 'dub') {
|
||||||
const found = play.data.versions.find((h) => h.audio_locale === hardsub.locale)
|
const found = versions.find((h) => h.audio_locale === hardsub.locale)
|
||||||
if (!found) {
|
if (!found) {
|
||||||
hardsubURL = undefined
|
hardsubURL = undefined
|
||||||
} else {
|
} else {
|
||||||
@ -1016,7 +1029,7 @@ export async function downloadCrunchyrollPlaylist(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (hardsub.format === 'sub') {
|
if (hardsub.format === 'sub') {
|
||||||
const found = play.data.versions.find((h) => h.audio_locale === 'ja-JP')
|
const found = versions.find((h) => h.audio_locale === 'ja-JP')
|
||||||
if (!found) {
|
if (!found) {
|
||||||
hardsubURL = undefined
|
hardsubURL = undefined
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user