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' };
|
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 PORT = 54322;
|
||||||
const proxyBase = `http://localhost:${PORT}/api/proxy`;
|
const proxyBase = `http://localhost:${PORT}/api/proxy`;
|
||||||
const mediaTitle = title || 'Anime';
|
const mediaTitle = title || 'Anime';
|
||||||
|
|
||||||
const proxyVideo =
|
const videoUrl = isLocalPath(video.url)
|
||||||
`${proxyBase}?url=${encodeURIComponent(video.url)}` +
|
? toFileUrl(video.url)
|
||||||
|
: `${proxyBase}?url=${encodeURIComponent(video.url)}` +
|
||||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`;
|
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`;
|
||||||
|
|
||||||
const proxySubs = subtitles.map((s: any) =>
|
|
||||||
`${proxyBase}?url=${encodeURIComponent(s.src)}` +
|
const subsUrls = subtitles.map((s: any) =>
|
||||||
|
isLocalPath(s.src)
|
||||||
|
? toFileUrl(s.src)
|
||||||
|
: `${proxyBase}?url=${encodeURIComponent(s.src)}` +
|
||||||
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
`&referer=${encodeURIComponent(video.headers?.Referer ?? '')}` +
|
||||||
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
`&origin=${encodeURIComponent(video.headers?.Origin ?? '')}` +
|
||||||
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`
|
`&userAgent=${encodeURIComponent(video.headers?.['User-Agent'] ?? '')}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
const pipe = `\\\\.\\pipe\\mpv-${Date.now()}`;
|
const pipe = `\\\\.\\pipe\\mpv-${Date.now()}`;
|
||||||
const { values } = loadConfig();
|
const { values } = loadConfig();
|
||||||
|
|
||||||
@@ -303,7 +318,7 @@ export async function openInMPV(req: any, reply: any) {
|
|||||||
{ command: ['observe_property', 1, 'duration'] },
|
{ command: ['observe_property', 1, 'duration'] },
|
||||||
{ command: ['observe_property', 2, 'time-pos'] },
|
{ command: ['observe_property', 2, 'time-pos'] },
|
||||||
{ command: ['observe_property', 3, 'pause'] },
|
{ command: ['observe_property', 3, 'pause'] },
|
||||||
{ command: ['loadfile', proxyVideo, 'replace'] }
|
{ command: ['loadfile', videoUrl, 'replace'] }
|
||||||
];
|
];
|
||||||
|
|
||||||
commands.forEach(cmd => socket.write(JSON.stringify(cmd) + '\n'));
|
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({
|
socket.write(JSON.stringify({
|
||||||
command: [
|
command: [
|
||||||
'sub-add',
|
'sub-add',
|
||||||
proxySubs[i],
|
subsUrls[i],
|
||||||
'auto',
|
'auto',
|
||||||
s.label || 'Subtitle',
|
s.label || 'Subtitle',
|
||||||
s.srclang || ''
|
s.srclang || ''
|
||||||
|
|||||||
Reference in New Issue
Block a user