Add TikTok player embed
Some checks failed
Some checks failed
Use TikTok's supported iframe player and safely invoke yt-dlp for YouTube streams.
This commit is contained in:
2
cinny
2
cinny
Submodule cinny updated: b16263b481...862307ee7d
@@ -1425,49 +1425,54 @@ ipcMain.handle('play-notification-sound', async (event, soundType = 'message') =
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get YouTube stream using yt-dlp
|
// Get a direct YouTube stream using yt-dlp.
|
||||||
ipcMain.handle('get-youtube-stream', async (event, url) => {
|
async function getYouTubeStream(url) {
|
||||||
try {
|
try {
|
||||||
// Check if yt-dlp is available
|
|
||||||
try {
|
try {
|
||||||
await execAsync('yt-dlp --version');
|
await execFileAsync('yt-dlp', ['--version']);
|
||||||
} catch {
|
} catch {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: 'yt-dlp is not installed. Please install yt-dlp to use YouTube features.'
|
error: 'yt-dlp is not installed. Please install yt-dlp to use YouTube features.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get title
|
|
||||||
let title = 'YouTube Video';
|
let title = 'YouTube Video';
|
||||||
try {
|
try {
|
||||||
const titleResult = await execAsync(`yt-dlp --get-title "${url}"`);
|
const titleResult = await execFileAsync('yt-dlp', ['--no-playlist', '--get-title', url]);
|
||||||
title = titleResult.stdout.trim();
|
title = titleResult.stdout.trim();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Failed to get video title:', e.message);
|
console.warn('Failed to get video title:', e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get video URL
|
const result = await execFileAsync('yt-dlp', [
|
||||||
const result = await execAsync(
|
'--no-playlist',
|
||||||
`yt-dlp -g -f "best[height<=1080]/bestvideo[height<=1080]+bestaudio/best" "${url}"`
|
'-g',
|
||||||
);
|
'-f',
|
||||||
|
'best[height<=1080]/bestvideo[height<=1080]+bestaudio/best',
|
||||||
|
url,
|
||||||
|
]);
|
||||||
const videoUrl = result.stdout.trim().split('\n')[0];
|
const videoUrl = result.stdout.trim().split('\n')[0];
|
||||||
|
|
||||||
if (!videoUrl) {
|
if (!videoUrl) {
|
||||||
return { success: false, error: 'yt-dlp returned empty URL' };
|
return { success: false, error: 'yt-dlp returned empty URL' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: { video_url: videoUrl, title }
|
data: { video_url: videoUrl, title },
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: `yt-dlp error: ${error.message}`
|
error: `yt-dlp error: ${error.message}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get YouTube stream using yt-dlp
|
||||||
|
ipcMain.handle('get-youtube-stream', async (event, url) => {
|
||||||
|
return getYouTubeStream(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Background sync stubs (desktop doesn't need it)
|
// Background sync stubs (desktop doesn't need it)
|
||||||
|
|||||||
Reference in New Issue
Block a user