added adn sub download support
This commit is contained in:
parent
898742b9f0
commit
3a3e5f278c
@ -198,7 +198,7 @@
|
||||
>
|
||||
JP
|
||||
</button>
|
||||
<button
|
||||
<!-- <button
|
||||
v-if="ADNselectedShow.languages.find((l) => l === 'vde')"
|
||||
@click="toggleDub({ locale: 'de-DE', name: 'DE' })"
|
||||
class="flex flex-row items-center justify-center gap-3 py-2 rounded-xl text-sm"
|
||||
@ -213,7 +213,7 @@
|
||||
:class="selectedDubs.find((i) => i.locale === 'fr-FR') ? 'bg-[#585858]' : 'hover:bg-[#747474]'"
|
||||
>
|
||||
FR
|
||||
</button>
|
||||
</button> -->
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="service === 'crunchyroll'" class="relative flex flex-col select-none">
|
||||
|
@ -42,7 +42,6 @@ export async function adnLogin(user: string, passw: string) {
|
||||
|
||||
async function adnLoginFetch(user: string, passw: string) {
|
||||
const headers = {
|
||||
'x-target-distribution': 'de',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
@ -103,7 +102,7 @@ export async function getEpisodeADN(q: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPlayerConfigADN(id: number) {
|
||||
export async function getPlayerConfigADN(id: number, geo: 'de' | 'fr') {
|
||||
|
||||
const account = await loggedInCheck('ADN')
|
||||
|
||||
@ -117,7 +116,7 @@ export async function getPlayerConfigADN(id: number) {
|
||||
const response = await fetch(`https://gw.api.animationdigitalnetwork.fr/player/video/${id}/configuration`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'x-target-distribution': 'de',
|
||||
'x-target-distribution': geo,
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token.data.accessToken}`
|
||||
}
|
||||
@ -135,8 +134,8 @@ export async function getPlayerConfigADN(id: number) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getPlayerToken(id: number) {
|
||||
const r = await getPlayerConfigADN(id)
|
||||
async function getPlayerToken(id: number, geo: 'de' | 'fr') {
|
||||
const r = await getPlayerConfigADN(id, geo)
|
||||
|
||||
if (!r) return
|
||||
|
||||
@ -144,7 +143,7 @@ async function getPlayerToken(id: number) {
|
||||
const response = await fetch(`https://gw.api.animationdigitalnetwork.fr/player/refresh/token`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'x-target-distribution': 'de',
|
||||
'x-target-distribution': geo,
|
||||
'Content-Type': 'application/json',
|
||||
'X-Player-Refresh-Token': r.player.options.user.refreshToken
|
||||
}
|
||||
@ -175,8 +174,8 @@ function randomHexaString(length: number) {
|
||||
return result
|
||||
}
|
||||
|
||||
async function getPlayerEncryptedToken(id: number) {
|
||||
const token = await getPlayerToken(id)
|
||||
async function getPlayerEncryptedToken(id: number, geo: 'de' | 'fr') {
|
||||
const token = await getPlayerToken(id, geo)
|
||||
|
||||
if (!token) return
|
||||
|
||||
@ -199,8 +198,8 @@ async function getPlayerEncryptedToken(id: number) {
|
||||
return { data: encryptedData, random: random }
|
||||
}
|
||||
|
||||
export async function adnGetPlaylist(animeid: number) {
|
||||
const token = await getPlayerEncryptedToken(animeid)
|
||||
export async function adnGetPlaylist(animeid: number, geo: 'de' | 'fr') {
|
||||
const token = await getPlayerEncryptedToken(animeid, geo)
|
||||
|
||||
if (!token) return
|
||||
|
||||
@ -208,7 +207,7 @@ export async function adnGetPlaylist(animeid: number) {
|
||||
const response = await fetch(`https://gw.api.animationdigitalnetwork.fr/player/video/${animeid}/link`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'x-target-distribution': 'de',
|
||||
'x-target-distribution': geo,
|
||||
'X-Player-Token': token.data
|
||||
}
|
||||
})
|
||||
|
@ -45,7 +45,6 @@ export async function getPlaylist() {
|
||||
return episodes
|
||||
}
|
||||
|
||||
|
||||
// Delete Playlist and TEMP folders After Start
|
||||
async function deletePlaylistandTMP() {
|
||||
await Playlist.truncate()
|
||||
@ -104,23 +103,24 @@ export async function getDownloading(id: number) {
|
||||
return null
|
||||
}
|
||||
|
||||
function updateProgress(): void {
|
||||
const totalParts = downloading.reduce((total, item) => total + item.partsToDownload, 0);
|
||||
let downloadedParts = 0;
|
||||
// Download Progress Bar Updater
|
||||
function updateProgress() {
|
||||
const totalParts = downloading.reduce((total, item) => total + item.partsToDownload, 0)
|
||||
let downloadedParts = 0
|
||||
|
||||
downloading.forEach((item) => {
|
||||
downloadedParts += item.downloadedParts;
|
||||
});
|
||||
downloadedParts += item.downloadedParts
|
||||
})
|
||||
|
||||
const progress = totalParts > 0 ? downloadedParts / totalParts : 0;
|
||||
const progress = totalParts > 0 ? downloadedParts / totalParts : 0
|
||||
|
||||
setProgressBar(progress);
|
||||
setProgressBar(progress)
|
||||
|
||||
const allDownloaded = downloading.every((item) => item.downloadedParts === item.partsToDownload);
|
||||
const allDownloaded = downloading.every((item) => item.downloadedParts === item.partsToDownload)
|
||||
|
||||
if (allDownloaded) {
|
||||
setProgressBar(0);
|
||||
return;
|
||||
setProgressBar(0)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,12 +198,12 @@ export async function downloadADNPlaylist(
|
||||
})
|
||||
|
||||
if (!season) {
|
||||
season = "1"
|
||||
season = '1'
|
||||
}
|
||||
|
||||
await updatePlaylistByID(downloadID, 'downloading')
|
||||
|
||||
var playlist = await adnGetPlaylist(e)
|
||||
// var playlist = await adnGetPlaylist(e)
|
||||
|
||||
const subFolder = await createFolder()
|
||||
|
||||
@ -212,23 +212,42 @@ export async function downloadADNPlaylist(
|
||||
const seasonFolder = await createFolderName(`${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season}`, downloadPath)
|
||||
|
||||
const subDownload = async () => {
|
||||
if (!playlist) {
|
||||
await updatePlaylistByID(downloadID, 'failed')
|
||||
return
|
||||
}
|
||||
const sbs: Array<string> = []
|
||||
const name = await downloadADNSub(playlist.data.links.subtitles.all, subFolder, playlist.secret)
|
||||
sbs.push(name)
|
||||
|
||||
if (subs.find((i) => i === 'de-DE')) {
|
||||
const dePlaylist = await adnGetPlaylist(e, 'de')
|
||||
|
||||
if (!dePlaylist) return
|
||||
|
||||
const name = await downloadADNSub(dePlaylist.data.links.subtitles.all, subFolder, dePlaylist.secret, 'de-DE')
|
||||
sbs.push(name)
|
||||
}
|
||||
if (subs.find((i) => i === 'fr-FR')) {
|
||||
const frPlaylist = await adnGetPlaylist(e, 'fr')
|
||||
|
||||
if (!frPlaylist) return
|
||||
|
||||
const name = await downloadADNSub(frPlaylist.data.links.subtitles.all, subFolder, frPlaylist.secret, 'fr-FR')
|
||||
sbs.push(name)
|
||||
}
|
||||
return sbs
|
||||
}
|
||||
|
||||
const downloadVideo = async () => {
|
||||
var playlist
|
||||
|
||||
playlist = await adnGetPlaylist(e, 'de')
|
||||
|
||||
if (!playlist) {
|
||||
playlist = await adnGetPlaylist(e, 'fr')
|
||||
}
|
||||
|
||||
if (!playlist) {
|
||||
await updatePlaylistByID(downloadID, 'failed')
|
||||
return
|
||||
}
|
||||
|
||||
var link: string = '';
|
||||
var link: string = ''
|
||||
|
||||
switch (quality) {
|
||||
case 1080:
|
||||
@ -271,14 +290,19 @@ export async function downloadADNPlaylist(
|
||||
return
|
||||
}
|
||||
|
||||
await mergeVideoFile(file as string, [], subss, String(playlist?.data.video.guid), seasonFolder, `${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season} Episode ${episode}`, format)
|
||||
await mergeVideoFile(
|
||||
file as string,
|
||||
[],
|
||||
subss,
|
||||
seasonFolder,
|
||||
`${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season} Episode ${episode}`,
|
||||
format
|
||||
)
|
||||
|
||||
await updatePlaylistByID(downloadID, 'completed')
|
||||
|
||||
await deleteFolder(subFolder)
|
||||
await deleteFolder(videoFolder)
|
||||
|
||||
return playlist
|
||||
}
|
||||
|
||||
// Download Crunchyroll Playlist
|
||||
@ -542,7 +566,7 @@ export async function downloadCrunchyrollPlaylist(
|
||||
|
||||
if (!audios) return
|
||||
|
||||
await mergeVideoFile(file as string, audios, subss, String(playlist.assetId), seasonFolder, `${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season} Episode ${episode}`, format)
|
||||
await mergeVideoFile(file as string, audios, subss, seasonFolder, `${name.replace(/[/\\?%*:|"<>]/g, '')} Season ${season} Episode ${episode}`, format)
|
||||
|
||||
await updatePlaylistByID(downloadID, 'completed')
|
||||
|
||||
@ -631,7 +655,7 @@ async function mergeParts(parts: { filename: string; url: string }[], downloadID
|
||||
}
|
||||
}
|
||||
|
||||
async function mergeVideoFile(video: string, audios: Array<string>, subs: Array<string>, name: string, path: string, filename: string, format: 'mp4' | 'mkv') {
|
||||
async function mergeVideoFile(video: string, audios: Array<string>, subs: Array<string>, path: string, filename: string, format: 'mp4' | 'mkv') {
|
||||
const locales: Array<{
|
||||
locale: string
|
||||
name: string
|
||||
|
@ -141,7 +141,7 @@ function resamplePOSSubtitle(subtitle: string, ox: number, oy: number, nx: numbe
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
export async function downloadADNSub(link: string, dir: string, secret: string) {
|
||||
export async function downloadADNSub(link: string, dir: string, secret: string, language: string) {
|
||||
var templateASS = `[Script Info]
|
||||
; Script generated by Aegisub 3.2.2
|
||||
; http://www.aegisub.org/
|
||||
@ -167,7 +167,7 @@ Style: Default,Arial,56,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100
|
||||
|
||||
[Events]
|
||||
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text\n`
|
||||
const path = `${dir}/de-DE.ass`
|
||||
const path = `${dir}/${language}.ass`
|
||||
|
||||
const stream = fs.createWriteStream(path)
|
||||
const subURLFetch = await fetch(link)
|
||||
|
Reference in New Issue
Block a user