coomer-downloader 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +305 -248
- package/package.json +1 -1
- package/src/api/bunkr.ts +16 -17
- package/src/api/coomer-api.ts +23 -24
- package/src/api/gofile.ts +18 -14
- package/src/api/index.ts +16 -16
- package/src/api/nsfw.xxx.ts +9 -10
- package/src/api/plain-curl.ts +7 -11
- package/src/args-handler.ts +1 -4
- package/src/index.ts +13 -15
- package/src/types/index.ts +0 -22
- package/src/utils/downloader.ts +81 -75
- package/src/utils/file.ts +75 -0
- package/src/utils/filters.ts +11 -14
- package/src/utils/index.ts +3 -3
- package/src/utils/multibar.ts +3 -3
- package/src/utils/strings.ts +0 -9
- /package/src/utils/{files.ts → io.ts} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { MediaType } from '../types';
|
|
4
|
+
import { filterString, testMediaType } from './filters';
|
|
5
|
+
|
|
6
|
+
interface ICoomerFile {
|
|
7
|
+
name: string;
|
|
8
|
+
url: string;
|
|
9
|
+
filepath?: string;
|
|
10
|
+
size?: number;
|
|
11
|
+
downloaded?: number;
|
|
12
|
+
content?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class CoomerFile {
|
|
16
|
+
public state: 'downloading' | 'pause' = 'pause';
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
public name: string,
|
|
20
|
+
public url: string,
|
|
21
|
+
public filepath?: string,
|
|
22
|
+
public size?: number,
|
|
23
|
+
public downloaded?: number,
|
|
24
|
+
public content?: string,
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
get textContent() {
|
|
28
|
+
const text = `${this.name || ''} ${this.content || ''}`.toLowerCase();
|
|
29
|
+
return text;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static from(f: ICoomerFile) {
|
|
33
|
+
return new CoomerFile(f.name, f.url, f.filepath, f.size, f.downloaded, f.content);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class CoomerFileList {
|
|
38
|
+
public dirPath?: string;
|
|
39
|
+
public dirName?: string;
|
|
40
|
+
|
|
41
|
+
constructor(public files: CoomerFile[] = []) {}
|
|
42
|
+
|
|
43
|
+
public setDirPath(dir: string, dirName?: string) {
|
|
44
|
+
dirName = dirName || (this.dirName as string);
|
|
45
|
+
|
|
46
|
+
if (dir === './') {
|
|
47
|
+
this.dirPath = path.resolve(dir, dirName);
|
|
48
|
+
} else {
|
|
49
|
+
this.dirPath = path.join(os.homedir(), path.join(dir, dirName));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
this.files.forEach((file) => {
|
|
53
|
+
file.filepath = path.join(this.dirPath as string, file.name);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public filterByText(include: string, exclude: string) {
|
|
60
|
+
this.files = this.files.filter((f) => filterString(f.textContent, include, exclude));
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public filterByMediaType(media?: string) {
|
|
65
|
+
if (media) {
|
|
66
|
+
this.files = this.files.filter((f) => testMediaType(f.name, media as MediaType));
|
|
67
|
+
}
|
|
68
|
+
return this;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public skip(n: number) {
|
|
72
|
+
this.files = this.files.slice(n);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/utils/filters.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MediaType } from '../types';
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function isImage(name: string) {
|
|
4
|
+
return /\.(jpg|jpeg|png|gif|bmp|tiff|webp|avif)$/i.test(name);
|
|
5
|
+
}
|
|
4
6
|
|
|
5
|
-
export
|
|
6
|
-
/\.(mp4|m4v|avi|mov|mkv|webm|flv|wmv|mpeg|mpg|3gp)$/i.test(name);
|
|
7
|
+
export function isVideo(name: string) {
|
|
8
|
+
return /\.(mp4|m4v|avi|mov|mkv|webm|flv|wmv|mpeg|mpg|3gp)$/i.test(name);
|
|
9
|
+
}
|
|
7
10
|
|
|
8
|
-
export
|
|
9
|
-
type === 'all' ? true : type === 'image' ? isImage(name) : isVideo(name);
|
|
11
|
+
export function testMediaType(name: string, type: MediaType) {
|
|
12
|
+
return type === 'all' ? true : type === 'image' ? isImage(name) : isVideo(name);
|
|
13
|
+
}
|
|
10
14
|
|
|
11
15
|
function includesAllWords(str: string, words: string[]) {
|
|
12
16
|
if (!words.length) return true;
|
|
@@ -25,13 +29,6 @@ function parseQuery(query: string) {
|
|
|
25
29
|
.filter((_) => _);
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
function filterString(text: string, include: string, exclude: string): boolean {
|
|
32
|
+
export function filterString(text: string, include: string, exclude: string): boolean {
|
|
29
33
|
return includesAllWords(text, parseQuery(include)) && includesNoWords(text, parseQuery(exclude));
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
export function filterKeywords(files: File[], include: string, exclude: string) {
|
|
33
|
-
return files.filter((f) => {
|
|
34
|
-
const text = `${f.name || ''} ${f.content || ''}`.toLowerCase();
|
|
35
|
-
return filterString(text, include, exclude);
|
|
36
|
-
});
|
|
37
|
-
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export { Downloader } from './downloader';
|
|
2
|
+
export { isImage, isVideo, testMediaType } from './filters';
|
|
3
|
+
export { getFileSize, mkdir } from './io';
|
|
4
4
|
export { createMultibar } from './multibar';
|
|
5
5
|
export {
|
|
6
6
|
fetchByteRange,
|
package/src/utils/multibar.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MultiBar, type Options, type SingleBar } from 'cli-progress';
|
|
2
|
-
import {
|
|
2
|
+
import type { Downloader } from './downloader';
|
|
3
3
|
import { b2mb, formatNameStdout } from './strings';
|
|
4
4
|
|
|
5
5
|
const config: Options = {
|
|
@@ -10,14 +10,14 @@ const config: Options = {
|
|
|
10
10
|
format: '{percentage}% | {filename} | {value}/{total}{size}',
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export function createMultibar() {
|
|
13
|
+
export function createMultibar(downloader: Downloader) {
|
|
14
14
|
const multibar = new MultiBar(config);
|
|
15
15
|
let bar: SingleBar;
|
|
16
16
|
let minibar: SingleBar;
|
|
17
17
|
let filename: string;
|
|
18
18
|
let index = 0;
|
|
19
19
|
|
|
20
|
-
subject.subscribe({
|
|
20
|
+
downloader.subject.subscribe({
|
|
21
21
|
next: ({ type, filesCount, file }) => {
|
|
22
22
|
switch (type) {
|
|
23
23
|
case 'FILES_DOWNLOADING_START':
|
package/src/utils/strings.ts
CHANGED
|
@@ -2,15 +2,6 @@ export function b2mb(bytes: number) {
|
|
|
2
2
|
return Number.parseFloat((bytes / 1048576).toFixed(2));
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function sanitizeString(str: string) {
|
|
6
|
-
return (
|
|
7
|
-
str
|
|
8
|
-
.match(/(\w| |-)/g)
|
|
9
|
-
?.join('')
|
|
10
|
-
.replace(/ +/g, ' ') || ''
|
|
11
|
-
);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
export function formatNameStdout(pathname: string) {
|
|
15
6
|
const name = pathname.split('/').pop() || '';
|
|
16
7
|
const consoleWidth = process.stdout.columns;
|
|
File without changes
|