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