Skip to content

Commit

Permalink
1..4.1 - minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DrKain committed May 14, 2022
1 parent ae8703b commit 9d0f309
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/help.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const help_text = "\nUsage: subclean [options]\nExample: subclean subtitle.srt -w\nBulk: subclean --sweep \"path/to/media\"\n\nOptions:\n -i, --input The file you want to clean\n -o, --output Where to write the cleaned file (defaults to input)\n -w, --overwrite Overwrite the output file if it already exists \n -c, --clean Delete the input file before writing the output \n -v, --version Display current version\n -n, --no-check Don't check for a new package version\n -s, --silent Silent mode. Nothing logged to console\n --debug Display extra debugging information\n --update Download the latest filters from GitHub\n This will not update subclean, only the filters!\n\n --sweep Bulk subtitle cleaning. Searches for subtitles\n in multiple directories (and sub-directories)\n This will enable --overwrite!\n\n --depth How many sub-directories to look when sweep cleaning\n --help Show the text you're reading now\n";
export declare const help_text = "\nUsage: subclean [options]\nExample: subclean subtitle.srt -w\nBulk: subclean --sweep \"path/to/media\"\n\nOptions:\n -i, --input The file you want to clean\n -o, --output Where to write the cleaned file (defaults to input)\n -w, --overwrite Overwrite the output file if it already exists \n -c, --clean Delete the input file before writing the output \n -v, --version Display current version\n -n, --no-check Don't check for a new package version\n -s, --silent Silent mode. Nothing logged to console\n --update Download the latest filters from GitHub\n This will not update subclean, only the filters!\n\n --sweep Bulk subtitle cleaning. Searches for subtitles\n in multiple directories (and sub-directories)\n This will enable --overwrite!\n\n v- You likely do not need to use these -v\n\n --depth How many sub-directories to look when sweep cleaning\n --debug Display extra debugging information\n --help Show the text you're reading now\n --ne No Empty (nodes). Deletes empty nodes after cleaning.\n --testing Testing mode. Will not modify files.\n --uf Use Filter: internal or appdata\n";
2 changes: 1 addition & 1 deletion lib/help.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 19 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ var SubClean = /** @class */ (function () {
this.nodes_count = 0;
this.filter_count = 0;
this.log_data = '';
console.time(this.timer);
this.args = {
input: argv._.shift() || argv.i || argv['input'] || '',
output: argv.o || argv['output'] || '',
Expand All @@ -85,7 +84,8 @@ var SubClean = /** @class */ (function () {
sweep: argv.sweep || '',
depth: (_a = argv.depth) !== null && _a !== void 0 ? _a : 10,
ne: argv['ne'] || false,
testing: argv.testing || false
testing: argv.testing || false,
uf: argv.uf || 'default'
};
if (typeof this.args.sweep !== 'string') {
this.args.sweep = '.';
Expand Down Expand Up @@ -314,11 +314,16 @@ var SubClean = /** @class */ (function () {
return;
try {
// We want to use appdata for this if possible
var internal = false;
var target = path_1.join(this.getPath(), 'filters', filter + ".json");
// Let people know where subclean is looking for
if (this.args.debug && this.args.uf === 'appdata') {
this.log('[Debug] Checking: ' + target);
}
// If the appdata file doesn't exist, use the internal filters
if (!fs_1.existsSync(target) || this.args.debug === true) {
this.log('[Info] Using internal filters');
if (!fs_1.existsSync(target) || this.args.uf === 'internal') {
target = path_1.join(this.fd, filter + ".json");
internal = true;
}
// If it still doesn't exist, return
if (!fs_1.existsSync(target)) {
Expand All @@ -332,7 +337,7 @@ var SubClean = /** @class */ (function () {
this.loaded.push(filter);
if (this.args.debug) {
this.filter_count += items.length;
this.log("[Filter] Added " + items.length + " items from filter " + filter);
this.log("[Filter] [" + (internal ? 'int' : 'app') + "] Added " + items.length + " items from filter '" + filter + "'");
}
}
catch (e) {
Expand Down Expand Up @@ -392,7 +397,10 @@ var SubClean = /** @class */ (function () {
delete nodes_1[index];
}
});
_this.log("[Info] Removed empty nodes: " + deleted_nodes_1.join(', '));
// Only log if we actually deleted nodes
if (deleted_nodes_1.length > 0) {
_this.log("[Info] Removed empty nodes: " + deleted_nodes_1.join(', '));
}
}
// Remove input file
if (item.clean && _this.args.testing == false) {
Expand All @@ -409,8 +417,7 @@ var SubClean = /** @class */ (function () {
else
_this.log('[Done] No advertising found\n');
if (_this.args.debug) {
console.timeEnd(_this.timer);
_this.log('[Debug] ' + _this.actions_count.toLocaleString() + ' actions performed');
_this.log('[Debug] ' + _this.actions_count.toLocaleString() + ' checks');
_this.log('[Debug] ' + _this.filter_count.toLocaleString() + ' filters applied');
_this.log('[Debug] ' + _this.nodes_count.toLocaleString() + ' text nodes');
_this.writeLogs();
Expand Down Expand Up @@ -541,7 +548,10 @@ var SubClean = /** @class */ (function () {
name_1 = path_1.basename(item.input);
if (this.args.debug)
name_1 = item.input;
this.log("[Clean] [" + (+index + 1) + "/" + this.queue.length + "] Cleaning \"" + name_1 + "\"");
// If we are only cleaning one file, don't log the queue details
if (this.queue.length > 1) {
this.log("[Clean] [" + (+index + 1) + "/" + this.queue.length + "] Cleaning \"" + name_1 + "\"");
}
_c.label = 3;
case 3:
_c.trys.push([3, 5, , 6]);
Expand Down
4 changes: 4 additions & 0 deletions lib/interface.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ export interface IArguments {
* subtitle file every time.
*/
testing: boolean;
/**
* Use filters: appdata or internal
*/
uf: 'default' | 'appdata' | 'internal';
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "subclean",
"version": "1.4.0",
"version": "1.4.1",
"description": "A CLI package to clean subtitle files of advertising",
"main": "lib/index.js",
"scripts": {
"ver": "nvm use 14.18.0",
"test": "ts-node src/index.ts subtitle.srt --ne -w --testing",
"test": "ts-node src/index.ts subtitle.srt --ne -w --uf=internal",
"build": "tsc && pkg . && npm run tidy",
"tidy": "ts-node postbuild.ts"
},
Expand Down
5 changes: 4 additions & 1 deletion src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ Options:
-v, --version Display current version
-n, --no-check Don't check for a new package version
-s, --silent Silent mode. Nothing logged to console
--debug Display extra debugging information
--update Download the latest filters from GitHub
This will not update subclean, only the filters!
--sweep Bulk subtitle cleaning. Searches for subtitles
in multiple directories (and sub-directories)
This will enable --overwrite!
v- You likely do not need to use these -v
--depth How many sub-directories to look when sweep cleaning
--debug Display extra debugging information
--help Show the text you're reading now
--ne No Empty (nodes). Deletes empty nodes after cleaning.
--testing Testing mode. Will not modify files.
--uf Use Filter: internal or appdata
`;
31 changes: 22 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class SubClean {
private log_data: string = '';

constructor() {
console.time(this.timer);
this.args = {
input: argv._.shift() || argv.i || argv['input'] || '',
output: argv.o || argv['output'] || '',
Expand All @@ -41,7 +40,9 @@ class SubClean {
sweep: argv.sweep || '',
depth: argv.depth ?? 10,
ne: argv['ne'] || false,
testing: argv.testing || false

testing: argv.testing || false,
uf: argv.uf || 'default'
} as IArguments;

if (typeof this.args.sweep !== 'string') {
Expand Down Expand Up @@ -251,12 +252,18 @@ class SubClean {
if (this.loaded.includes(filter)) return;
try {
// We want to use appdata for this if possible
let internal = false;
let target = join(this.getPath(), 'filters', `${filter}.json`);

// Let people know where subclean is looking for
if (this.args.debug && this.args.uf === 'appdata') {
this.log('[Debug] Checking: ' + target);
}

// If the appdata file doesn't exist, use the internal filters
if (!existsSync(target) || this.args.debug === true) {
this.log('[Info] Using internal filters');
if (!existsSync(target) || this.args.uf === 'internal') {
target = join(this.fd, `${filter}.json`);
internal = true;
}

// If it still doesn't exist, return
Expand All @@ -274,7 +281,7 @@ class SubClean {

if (this.args.debug) {
this.filter_count += items.length;
this.log(`[Filter] Added ${items.length} items from filter ${filter}`);
this.log(`[Filter] [${internal ? 'int' : 'app'}] Added ${items.length} items from filter '${filter}'`);
}
} catch (e) {
this.log('[Error] Failed to load a filter: ' + filter);
Expand Down Expand Up @@ -336,7 +343,10 @@ class SubClean {
delete nodes[index];
}
});
this.log(`[Info] Removed empty nodes: ${deleted_nodes.join(', ')}`);
// Only log if we actually deleted nodes
if (deleted_nodes.length > 0) {
this.log(`[Info] Removed empty nodes: ${deleted_nodes.join(', ')}`);
}
}

// Remove input file
Expand All @@ -356,8 +366,7 @@ class SubClean {
else this.log('[Done] No advertising found\n');

if (this.args.debug) {
console.timeEnd(this.timer);
this.log('[Debug] ' + this.actions_count.toLocaleString() + ' actions performed');
this.log('[Debug] ' + this.actions_count.toLocaleString() + ' checks');
this.log('[Debug] ' + this.filter_count.toLocaleString() + ' filters applied');
this.log('[Debug] ' + this.nodes_count.toLocaleString() + ' text nodes');
this.writeLogs();
Expand Down Expand Up @@ -464,7 +473,11 @@ class SubClean {
let name = basename(item.input);
if (this.args.debug) name = item.input;

this.log(`[Clean] [${+index + 1}/${this.queue.length}] Cleaning "${name}"`);
// If we are only cleaning one file, don't log the queue details
if (this.queue.length > 1) {
this.log(`[Clean] [${+index + 1}/${this.queue.length}] Cleaning "${name}"`);
}

try {
await this.cleanFile(item);
} catch (error) {
Expand Down
4 changes: 4 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ export interface IArguments {
* subtitle file every time.
*/
testing: boolean;
/**
* Use filters: appdata or internal
*/
uf: 'default' | 'appdata' | 'internal';
}

0 comments on commit 9d0f309

Please sign in to comment.