chapters fix and removed useless request headers

This commit is contained in:
stratuma 2024-06-21 19:37:14 +02:00
parent 3ed664132c
commit fdf76f1ef1
3 changed files with 42 additions and 28 deletions

View File

@ -419,8 +419,6 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
const headersLoc = { const headersLoc = {
Authorization: `Bearer ${login.access_token}`, Authorization: `Bearer ${login.access_token}`,
'X-Cr-Disable-Drm': 'true',
'x-cr-stream-limits': 'false',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
} }
@ -515,7 +513,6 @@ export async function crunchyGetPlaylist(q: string, geo: string | undefined) {
const headers = { const headers = {
Authorization: `Bearer ${logindata.access_token}`, Authorization: `Bearer ${logindata.access_token}`,
'X-Cr-Disable-Drm': 'true',
'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27' 'User-Agent': 'Crunchyroll/1.8.0 Nintendo Switch/12.3.12.0 UE4/4.27'
} }

View File

@ -715,7 +715,7 @@ export async function downloadCrunchyrollPlaylist(
return null return null
} }
const chapterPath = await createChapterFile(metadata, chapterFolder, format) const chapterPath = await createChapterFile(metadata, chapterFolder, format, e)
return chapterPath return chapterPath
} }
@ -1101,7 +1101,7 @@ export async function downloadCrunchyrollPlaylist(
await deleteFolder(videoFolder) await deleteFolder(videoFolder)
await deleteFolder(subFolder) await deleteFolder(subFolder)
await deleteFolder(audioFolder) await deleteFolder(audioFolder)
await deleteFolder(chapterFolder) // await deleteFolder(chapterFolder)
return playlist return playlist
} }

View File

@ -7,44 +7,61 @@ function formatTimeFFMPEG(seconds: number) {
return seconds * 1000 return seconds * 1000
} }
export async function createChapterFile(rawchapters: VideoMetadata, dir: string, format: string) { async function createChapter(chapter: VideoMetadataSingle, format: string, name: string) {
var chapters: string[] = []
if (format === 'mkv') {
chapters.push('[CHAPTER]')
chapters.push('TIMEBASE=1/1000')
chapters.push(`START=${formatTimeFFMPEG(chapter.start)}`)
chapters.push(`END=${formatTimeFFMPEG(chapter.start)}`)
chapters.push(`title=${name}`)
chapters.push(``)
chapters.push('[CHAPTER]')
chapters.push('TIMEBASE=1/1000')
chapters.push(`START=${formatTimeFFMPEG(chapter.end)}`)
chapters.push(`END=${formatTimeFFMPEG(chapter.end)}`)
chapters.push(`title=${name} End`)
chapters.push(``)
} else {
chapters.push('[CHAPTER]')
chapters.push('TIMEBASE=1/1000')
chapters.push(`START=${formatTimeFFMPEG(chapter.start)}`)
chapters.push(`END=${formatTimeFFMPEG(chapter.end)}`)
chapters.push(`title=${name}`)
chapters.push(``)
}
return chapters
}
export async function createChapterFile(rawchapters: VideoMetadata, dir: string, format: string, mediaid: string) {
const filepath = path.join(dir, 'chapters.txt') const filepath = path.join(dir, 'chapters.txt')
var chapters: string[] = [] var chapters: string[] = []
const addChapter = (chapter: VideoMetadataSingle) => { chapters.push(';FFMETADATA1')
if (format === 'mkv') { chapters.push(`title=${mediaid}`)
chapters.push('[CHAPTER]') chapters.push(`artist=Crunchyroll`)
chapters.push('TIMEBASE=1/1000') chapters.push(``)
chapters.push(`START=${formatTimeFFMPEG(chapter.start)}`)
chapters.push(`title=${chapter.title}`)
chapters.push('[CHAPTER]')
chapters.push('TIMEBASE=1/1000')
chapters.push(`START=${formatTimeFFMPEG(chapter.end)}`)
chapters.push(`title=Chapter`)
} else {
chapters.push('[CHAPTER]')
chapters.push('TIMEBASE=1/1000')
chapters.push(`START=${formatTimeFFMPEG(chapter.start)}`)
chapters.push(`END=${formatTimeFFMPEG(chapter.end)}`)
chapters.push(`title=${chapter.title}`)
}
}
if (rawchapters.intro && rawchapters.intro.type && rawchapters.intro.start && rawchapters.intro.end) { if (rawchapters.intro && rawchapters.intro.type && rawchapters.intro.start && rawchapters.intro.end) {
addChapter(rawchapters.intro) chapters.push(...await createChapter(rawchapters.intro, format, 'Intro'));
console.log(chapters)
} }
if (rawchapters.credits && rawchapters.credits.type && rawchapters.credits.start && rawchapters.credits.end) { if (rawchapters.credits && rawchapters.credits.type && rawchapters.credits.start && rawchapters.credits.end) {
addChapter(rawchapters.credits) chapters.push(...await createChapter(rawchapters.credits, format, 'Credits'));
console.log(chapters)
} }
if (rawchapters.preview && rawchapters.preview.type && rawchapters.preview.start && rawchapters.preview.end) { if (rawchapters.preview && rawchapters.preview.type && rawchapters.preview.start && rawchapters.preview.end) {
addChapter(rawchapters.preview) chapters.push(...await createChapter(rawchapters.preview, format, 'Preview'));
console.log(chapters)
} }
if (rawchapters.recap && rawchapters.recap.type && rawchapters.recap.start && rawchapters.recap.end) { if (rawchapters.recap && rawchapters.recap.type && rawchapters.recap.start && rawchapters.recap.end) {
addChapter(rawchapters.recap) chapters.push(...await createChapter(rawchapters.recap, format, 'Recap'));
console.log(chapters)
} }
try { try {