1
1
mirror of https://github.com/neosubhamoy/neodlp.git synced 2026-03-22 19:25:49 +05:30

feat: added support for youtube po token generation

This commit is contained in:
2026-02-18 14:19:11 +05:30
Verified
parent 1292758b1e
commit dfa5cace82
24 changed files with 1088 additions and 27 deletions

View File

@@ -69,7 +69,11 @@ export default function useDownloader() {
max_sleep_interval: MAX_SLEEP_INTERVAL,
request_sleep_interval: REQUEST_SLEEP_INTERVAL,
delay_playlist_only: DELAY_PLAYLIST_ONLY,
use_potoken: USE_POTOKEN,
disable_innertube: DISABLE_INNERTUBE,
pot_server_port: POT_SERVER_PORT,
} = useSettingsPageStatesStore(state => state.settings);
const isRunningPotServer = useSettingsPageStatesStore(state => state.isRunningPotServer);
const expectedErrorDownloadIds = useDownloaderPageStatesStore((state) => state.expectedErrorDownloadIds);
const addErroredDownload = useDownloaderPageStatesStore((state) => state.addErroredDownload);
@@ -181,6 +185,16 @@ export default function useDownloader() {
args.push('--sleep-requests', REQUEST_SLEEP_INTERVAL.toString(), '--sleep-interval', MIN_SLEEP_INTERVAL.toString(), '--max-sleep-interval', MAX_SLEEP_INTERVAL.toString());
}
}
if ((!USE_CUSTOM_COMMANDS && !resumeState?.custom_command) && USE_POTOKEN) {
if (!isRunningPotServer) {
LOG.warning("NEODLP", "Looks like you want to use PO Token! But, NeoDLP POT Server is not running. PO Token generation will most likely fail!");
}
if (DISABLE_INNERTUBE) {
args.push('--extractor-args', `youtubepot-bgutilhttp:base_url=http://localhost:${POT_SERVER_PORT};disable_innertube=1`);
} else {
args.push('--extractor-args', `youtubepot-bgutilhttp:base_url=http://localhost:${POT_SERVER_PORT}`);
}
}
const command = Command.sidecar('binaries/yt-dlp', args);
@@ -525,6 +539,17 @@ export default function useDownloader() {
LOG.warning('NEODLP', `Looks like you are using aria2 for this yt-dlp download: ${downloadId}. Make sure aria2 is installed on your system if you are on macOS for this to work. Also, pause/resume might not work as expected especially on windows (using aria2 is not recommended for most downloads).`);
}
if ((!USE_CUSTOM_COMMANDS && !resumeState?.custom_command) && USE_POTOKEN) {
if (!isRunningPotServer) {
LOG.warning("NEODLP", "Looks like you want to use PO Token! But, NeoDLP POT Server is not running. PO Token generation will most likely fail!");
}
if (DISABLE_INNERTUBE) {
args.push('--extractor-args', `youtubepot-bgutilhttp:base_url=http://localhost:${POT_SERVER_PORT};disable_innertube=1`);
} else {
args.push('--extractor-args', `youtubepot-bgutilhttp:base_url=http://localhost:${POT_SERVER_PORT}`);
}
}
if (resumeState || (!USE_CUSTOM_COMMANDS && USE_ARIA2)) {
args.push('--continue');
} else {

View File

@@ -0,0 +1,52 @@
import { join, resourceDir, homeDir } from "@tauri-apps/api/path";
import * as fs from "@tauri-apps/plugin-fs";
import { useKvPairs } from "@/helpers/use-kvpairs";
import { useSettingsPageStatesStore } from "@/services/store";
interface FileMap {
source: string;
destination: string;
dir: string;
}
export function useLinuxRegisterer() {
const { saveKvPair } = useKvPairs();
const appVersion = useSettingsPageStatesStore(state => state.appVersion);
const registerToLinux = async () => {
try {
const filesToCopy: FileMap[] = [
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
];
const resourceDirPath = await resourceDir();
const homeDirPath = await homeDir();
for (const file of filesToCopy) {
const sourcePath = await join(resourceDirPath, file.source);
const destinationDir = await join(homeDirPath, file.dir);
const destinationPath = await join(homeDirPath, file.destination);
const dirExists = await fs.exists(destinationDir);
if (dirExists) {
await fs.copyFile(sourcePath, destinationPath);
console.log(`File ${file.source} copied successfully to ${destinationPath}`);
} else {
await fs.mkdir(destinationDir, { recursive: true })
console.log(`Created dir ${destinationDir}`);
await fs.copyFile(sourcePath, destinationPath);
console.log(`File ${file.source} copied successfully to ${destinationPath}`);
}
}
saveKvPair('linux_registered_version', appVersion);
return { success: true, message: 'Registered successfully' }
} catch (error) {
console.error('Error copying files:', error);
return { success: false, message: 'Failed to register' }
}
}
return { registerToLinux };
}

View File

@@ -3,27 +3,36 @@ import * as fs from "@tauri-apps/plugin-fs";
import { useKvPairs } from "@/helpers/use-kvpairs";
import { useSettingsPageStatesStore } from "@/services/store";
interface FileMap {
source: string;
destination: string;
dir: string;
}
export function useMacOsRegisterer() {
const { saveKvPair } = useKvPairs();
const appVersion = useSettingsPageStatesStore(state => state.appVersion);
const registerToMac = async () => {
try {
const filesToCopy = [
const filesToCopy: FileMap[] = [
{ source: 'neodlp-autostart.plist', destination: 'Library/LaunchAgents/com.neosubhamoy.neodlp.plist', dir: 'Library/LaunchAgents/' },
{ source: 'neodlp-msghost.json', destination: 'Library/Application Support/Google/Chrome/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Google/Chrome/NativeMessagingHosts/' },
{ source: 'neodlp-msghost.json', destination: 'Library/Application Support/Chromium/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Chromium/NativeMessagingHosts/' },
{ source: 'neodlp-msghost-moz.json', destination: 'Library/Application Support/Mozilla/NativeMessagingHosts/com.neosubhamoy.neodlp.json', dir: 'Library/Application Support/Mozilla/NativeMessagingHosts/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_cli.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
{ source: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', destination: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/getpot_bgutil_http.py', dir: 'yt-dlp-plugins/bgutil-ytdlp-pot-provider/yt_dlp_plugins/extractor/' },
];
const resourceDirPath = await resourceDir();
const homeDirPath = await homeDir();
for (const file of filesToCopy) {
const sourcePath = await join(resourceDirPath, file.source);
const destinationDir = await join(homeDirPath, file.dir);
const destinationPath = await join(homeDirPath, file.destination);
const dirExists = await fs.exists(destinationDir);
if (dirExists) {
await fs.copyFile(sourcePath, destinationPath);
@@ -44,4 +53,4 @@ export function useMacOsRegisterer() {
}
return { registerToMac };
}
}

View File

@@ -0,0 +1,86 @@
import { useSettingsPageStatesStore } from "@/services/store";
import { useLogger } from "@/helpers/use-logger";
import { Command } from "@tauri-apps/plugin-shell";
import { invoke } from "@tauri-apps/api/core";
export default function usePotServer() {
const setIsRunningPotServer = useSettingsPageStatesStore(state => state.setIsRunningPotServer);
const setIsStartingPotServer = useSettingsPageStatesStore(state => state.setIsStartingPotServer);
const potServerPid = useSettingsPageStatesStore(state => state.potServerPid);
const setPotServerPid = useSettingsPageStatesStore(state => state.setPotServerPid);
const potServerPort = useSettingsPageStatesStore(state => state.settings.pot_server_port);
const LOG = useLogger();
const stripAnsiAndLogPrefix = (line: string): string => {
const stripped = line.replace(/\x1b\[\d+m/g, '');
return stripped.replace(/^\d{4}-\d{2}-\d{2}T[\d:.]+Z\s+\w+\s+[\w:]+:\s*/, '');
};
const startPotServer = async (port?: number) => {
const runCommand = Command.sidecar('binaries/neodlp-pot', [
'server',
'--port',
port ? port.toString() : potServerPort.toString(),
]);
try {
setIsStartingPotServer(true);
LOG.info("NEODLP POT-SERVER", `Starting POT Server on port: ${port ?? potServerPort}`);
runCommand.on("close", (data) => {
if (data.code === 0) {
LOG.info("NEODLP POT-SERVER", `POT Server process exited with code: ${data.code}`);
} else {
LOG.error("NEODLP POT-SERVER", `POT Server process exited with code: ${data.code} (ignore if you manually stopped the server)`);
}
setIsRunningPotServer(false);
setPotServerPid(null);
});
runCommand.on("error", (error) => {
LOG.error("NEODLP POT-SERVER", `Error running POT Server: ${error}`);
setIsRunningPotServer(false);
setPotServerPid(null);
});
runCommand.stdout.on("data", (line) => {
const cleanedLine = stripAnsiAndLogPrefix(line).trim();
if (cleanedLine !== '') LOG.info("NEODLP POT-SERVER", cleanedLine);
if (cleanedLine.startsWith("POT server")) {
setIsRunningPotServer(true);
}
});
runCommand.stderr.on("data", (line) => {
const cleanedLine = stripAnsiAndLogPrefix(line).trim();
if (cleanedLine !== '') LOG.error("NEODLP POT-SERVER", cleanedLine);
});
const child = await runCommand.spawn();
setPotServerPid(child.pid);
} catch (error) {
LOG.error("NEODLP POT-SERVER", `Error starting POT Server: ${error}`);
} finally {
setIsStartingPotServer(false);
}
}
const stopPotServer = async () => {
if (!potServerPid) {
LOG.warning("NEODLP POT-SERVER", "No POT Server process found to stop.");
return;
}
try {
LOG.info("NEODLP POT-SERVER", `Stopping POT Server with PID: ${potServerPid}`);
await invoke('kill_all_process', { pid: potServerPid });
LOG.info("NEODLP POT-SERVER", "POT Server stopped successfully.");
setIsRunningPotServer(false);
setPotServerPid(null);
} catch (error) {
LOG.error("NEODLP POT-SERVER", `Error stopping POT Server: ${error}`);
}
}
return { startPotServer, stopPotServer};
}