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

refactor: improved search logging

This commit is contained in:
2026-02-13 21:26:06 +05:30
Verified
parent 15bd9c244f
commit 96fc27eda3
2 changed files with 34 additions and 20 deletions

View File

@@ -47,8 +47,8 @@ export default function Navbar() {
</Button> </Button>
</DialogTrigger> </DialogTrigger>
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent side="bottom">
<p>Logs</p> <p>Logs</p>
</TooltipContent> </TooltipContent>
</Tooltip> </Tooltip>
<DialogContent className="sm:max-w-150"> <DialogContent className="sm:max-w-150">

View File

@@ -103,7 +103,12 @@ export default function useDownloader() {
const fetchVideoMetadata = async (params: FetchVideoMetadataParams): Promise<RawVideoInfo | null> => { const fetchVideoMetadata = async (params: FetchVideoMetadataParams): Promise<RawVideoInfo | null> => {
const { url, formatId, playlistIndices, selectedSubtitles, resumeState, downloadConfig } = params; const { url, formatId, playlistIndices, selectedSubtitles, resumeState, downloadConfig } = params;
try { try {
const args = [url, '--dump-single-json', '--no-warnings']; const args = [url, '--dump-single-json'];
if (DEBUG_MODE && LOG_VERBOSE) {
args.push('--verbose');
} else {
args.push('--no-warnings');
}
if (formatId) { if (formatId) {
const isMultipleAudioFormatSelected = formatId.split('+').length > 2; const isMultipleAudioFormatSelected = formatId.split('+').length > 2;
args.push('--format', formatId); args.push('--format', formatId);
@@ -168,31 +173,40 @@ export default function useDownloader() {
return new Promise<RawVideoInfo | null>((resolve) => { return new Promise<RawVideoInfo | null>((resolve) => {
command.stdout.on('data', line => { command.stdout.on('data', line => {
jsonOutput += line; if (line.startsWith('{')) {
jsonOutput = line;
} else {
if (line.trim() !== '') LOG.info('YT-DLP', line);
}
});
command.stderr.on('data', line => {
if (line.trim() !== '') LOG.info('YT-DLP', line);
}); });
command.on('close', async (data) => { command.on('close', async (data) => {
if (data.code !== 0) { if (data.code !== 0) {
console.error(`yt-dlp failed to fetch metadata with code ${data.code}`); console.error(`yt-dlp exited with code ${data.code} while fetching metadata for URL: ${url}`);
LOG.error('NEODLP', `yt-dlp exited with code ${data.code} while fetching metadata for URL: ${url} (ignore if you manually cancelled)`); LOG.error('NEODLP', `yt-dlp exited with code ${data.code} while fetching metadata for URL: ${url} (ignore if you manually cancelled)`);
resolve(null);
} else { } else {
try { LOG.info('NEODLP', `yt-dlp exited with code ${data.code} while fetching metadata for URL: ${url}`);
const matchedJson = jsonOutput.match(/{.*}/); }
if (!matchedJson) {
console.error(`Failed to match JSON: ${jsonOutput}`); try {
LOG.error('NEODLP', `Failed to parse metadata JSON for URL: ${url})`); const matchedJson = jsonOutput.match(/{.*}/);
resolve(null); if (!matchedJson) {
return; console.error(`Failed to match JSON: ${jsonOutput}`);
} LOG.error('NEODLP', `Failed to parse metadata JSON for URL: ${url})`);
const parsedJson: RawVideoInfo = JSON.parse(matchedJson[0]);
resolve(parsedJson);
}
catch (e) {
console.error(`Failed to parse JSON: ${e}`);
LOG.error('NEODLP', `Failed to parse metadata JSON for URL: ${url}) with error: ${e}`);
resolve(null); resolve(null);
return;
} }
const parsedJson: RawVideoInfo = JSON.parse(matchedJson[0]);
resolve(parsedJson);
}
catch (e) {
console.error(`Failed to parse JSON: ${e}`);
LOG.error('NEODLP', `Failed to parse metadata JSON for URL: ${url}) with error: ${e}`);
resolve(null);
} }
}); });