added open in mpv on anime for electron ver
This commit is contained in:
@@ -116,7 +116,6 @@ export async function getWatchStream(req: WatchStreamRequest, reply: FastifyRepl
|
||||
|
||||
export async function openInMPV(req: any, reply: any) {
|
||||
try {
|
||||
|
||||
const { title, video, subtitles = [], chapters = [], animeId, episode, entrySource, token } = req.body;
|
||||
|
||||
if (!video?.url) return { error: 'Missing video url' };
|
||||
@@ -132,7 +131,7 @@ export async function openInMPV(req: any, reply: any) {
|
||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`;
|
||||
|
||||
const proxySubs = subtitles.map((s: any) =>
|
||||
`${proxyBase}?url=${encodeURIComponent(s.url)}` +
|
||||
`${proxyBase}?url=${encodeURIComponent(s.src)}` +
|
||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`
|
||||
@@ -142,20 +141,26 @@ export async function openInMPV(req: any, reply: any) {
|
||||
|
||||
let chaptersArg: string[] = [];
|
||||
if (chapters.length) {
|
||||
chapters.sort((a: any, b: any) => a.interval.startTime - b.interval.startTime);
|
||||
|
||||
chapters.sort((a: any, b: any) => a.startTime - b.startTime);
|
||||
|
||||
const lines = [';FFMETADATA1'];
|
||||
|
||||
for (let i = 0; i < chapters.length; i++) {
|
||||
const c = chapters[i];
|
||||
const start = Math.floor(c.interval.startTime * 1000);
|
||||
const end = Math.floor(c.interval.endTime * 1000);
|
||||
|
||||
const start = Math.floor(c.startTime * 1000);
|
||||
const end = Math.floor(c.endTime * 1000);
|
||||
|
||||
const title = (c.type || 'chapter').toUpperCase();
|
||||
|
||||
lines.push(
|
||||
`[CHAPTER]`, `TIMEBASE=1/1000`, `START=${start}`, `END=${end}`, `title=${c.skipType.toUpperCase()}`
|
||||
`[CHAPTER]`, `TIMEBASE=1/1000`, `START=${start}`, `END=${end}`, `title=${title}`
|
||||
);
|
||||
|
||||
if (i < chapters.length - 1) {
|
||||
const nextStart = Math.floor(chapters[i + 1].interval.startTime * 1000);
|
||||
const nextStart = Math.floor(chapters[i + 1].startTime * 1000);
|
||||
|
||||
if (nextStart - end > 1000) {
|
||||
lines.push(
|
||||
`[CHAPTER]`, `TIMEBASE=1/1000`, `START=${end}`, `END=${nextStart}`, `title=Episode`
|
||||
@@ -293,9 +298,17 @@ export async function openInMPV(req: any, reply: any) {
|
||||
|
||||
commands.forEach(cmd => socket.write(JSON.stringify(cmd) + '\n'));
|
||||
|
||||
for (const sub of proxySubs) {
|
||||
socket.write(JSON.stringify({ command: ['sub-add', sub, 'auto'] }) + '\n');
|
||||
}
|
||||
subtitles.forEach((s: any, i: number) => {
|
||||
socket.write(JSON.stringify({
|
||||
command: [
|
||||
'sub-add',
|
||||
proxySubs[i],
|
||||
'auto',
|
||||
s.label || 'Subtitle',
|
||||
s.srclang || ''
|
||||
]
|
||||
}) + '\n');
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user