Skip to content

Commit

Permalink
Filtering Illegal characters in file name
Browse files Browse the repository at this point in the history
  • Loading branch information
sudospaes committed Jul 26, 2024
1 parent dc6d979 commit 694be93
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ app
"#D04848"
)("<3")}`
)
.version(`0.0.5`, "--version")
.version(`0.0.6`, "--version")
.usage("[command]")
.option("--debug", "simple debugger, it's a joke XD")
.addOption(new Option("-h, --help").hideHelp());
Expand Down
6 changes: 3 additions & 3 deletions src/cli/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
drawBasicTable,
} from "./tables";
import { Successful, Wrong } from "./logs";
import { secondstoTime, formatBytes } from "../utils/ulits";
import { secondstoTime, formatBytes, filtering } from "../utils/ulits";
import { IVideoObject, IAudioObject } from "./interface";

export const debug = {
Expand All @@ -38,7 +38,7 @@ export async function downloadVideo(link: string, tag: string) {
Wrong.internet(err, debug.enable);
process.exit(1);
}
const title = info.videoDetails.title.replace(/\//g, "");
const title = filtering(info.videoDetails.title);
let extension = "";
let quality = "";
let codec = "";
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function downloadAudio(link: string, tag: string) {
Wrong.internet(err, debug.enable);
process.exit(1);
}
const title = info.videoDetails.title.replace(/\//g, "");
const title = filtering(info.videoDetails.title);
let extension = "";
let bitrate = 0;
let codec = "";
Expand Down
17 changes: 15 additions & 2 deletions src/utils/ulits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ export function formatBytes(bytes: number, decimals: number = 2) {

const dm = bytes % 1 === 0 ? 0 : decimals;
const units = ["B", "KB", "MB", "GB", "TB", "PB"];

return `${bytes.toFixed(dm)} ${units[i]}`;
}
}

export function filtering(text: string) {
// Define the characters to be removed
const charsToRemove = "#%&{}\\/<>*? $!'\":@+|=";

// Create a regex pattern that matches any of the characters
const pattern = new RegExp(
`[${charsToRemove.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}]`,
"g"
);

return text.replace(pattern, "");
}

0 comments on commit 694be93

Please sign in to comment.