open in mpv now supports local files
This commit is contained in:
@@ -122,23 +122,38 @@ export async function openInMPV(req: any, reply: any) {
|
||||
|
||||
if (!video?.url) return { error: 'Missing video url' };
|
||||
|
||||
const isLocalPath = (p: string) =>
|
||||
p.startsWith('file://') ||
|
||||
p.startsWith('/') ||
|
||||
/^[a-zA-Z]:\\/.test(p);
|
||||
|
||||
const toFileUrl = (p: string) =>
|
||||
p.startsWith('file://')
|
||||
? p
|
||||
: `file://${p.replace(/\\/g, '/')}`;
|
||||
|
||||
const PORT = 54322;
|
||||
const proxyBase = `http://localhost:${PORT}/api/proxy`;
|
||||
const mediaTitle = title || 'Anime';
|
||||
|
||||
const proxyVideo =
|
||||
`${proxyBase}?url=${encodeURIComponent(video.url)}` +
|
||||
const videoUrl = isLocalPath(video.url)
|
||||
? toFileUrl(video.url)
|
||||
: `${proxyBase}?url=${encodeURIComponent(video.url)}` +
|
||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`;
|
||||
|
||||
const proxySubs = subtitles.map((s: any) =>
|
||||
`${proxyBase}?url=${encodeURIComponent(s.src)}` +
|
||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`
|
||||
|
||||
const subsUrls = subtitles.map((s: any) =>
|
||||
isLocalPath(s.src)
|
||||
? toFileUrl(s.src)
|
||||
: `${proxyBase}?url=${encodeURIComponent(s.src)}` +
|
||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`
|
||||
);
|
||||
|
||||
|
||||
const pipe = `\\\\.\\pipe\\mpv-${Date.now()}`;
|
||||
const { values } = loadConfig();
|
||||
|
||||
@@ -303,7 +318,7 @@ export async function openInMPV(req: any, reply: any) {
|
||||
{ command: ['observe_property', 1, 'duration'] },
|
||||
{ command: ['observe_property', 2, 'time-pos'] },
|
||||
{ command: ['observe_property', 3, 'pause'] },
|
||||
{ command: ['loadfile', proxyVideo, 'replace'] }
|
||||
{ command: ['loadfile', videoUrl, 'replace'] }
|
||||
];
|
||||
|
||||
commands.forEach(cmd => socket.write(JSON.stringify(cmd) + '\n'));
|
||||
@@ -312,7 +327,7 @@ export async function openInMPV(req: any, reply: any) {
|
||||
socket.write(JSON.stringify({
|
||||
command: [
|
||||
'sub-add',
|
||||
proxySubs[i],
|
||||
subsUrls[i],
|
||||
'auto',
|
||||
s.label || 'Subtitle',
|
||||
s.srclang || ''
|
||||
|
||||
Reference in New Issue
Block a user