tor-dl 1.0.1 → 1.0.3
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/AGENTS.md +6 -6
- package/README.md +22 -180
- package/dist/bin/{tordl.js → tor-dl.js} +2 -3
- package/dist/cli/display.d.ts.map +1 -1
- package/dist/cli/display.js +13 -9
- package/dist/cli/display.js.map +1 -1
- package/dist/cli/parser.d.ts.map +1 -1
- package/dist/cli/parser.js +21 -27
- package/dist/cli/parser.js.map +1 -1
- package/dist/commands/download.d.ts +1 -1
- package/dist/commands/download.d.ts.map +1 -1
- package/dist/commands/download.js +55 -49
- package/dist/commands/download.js.map +1 -1
- package/dist/download/engine.d.ts +1 -3
- package/dist/download/engine.d.ts.map +1 -1
- package/dist/download/engine.js +0 -129
- package/dist/download/engine.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/sources/nyaa.d.ts.map +1 -1
- package/dist/sources/nyaa.js +3 -0
- package/dist/sources/nyaa.js.map +1 -1
- package/dist/sources/thepiratebay.d.ts.map +1 -1
- package/dist/sources/thepiratebay.js +1 -0
- package/dist/sources/thepiratebay.js.map +1 -1
- package/dist/sources/yts.d.ts.map +1 -1
- package/dist/sources/yts.js +1 -0
- package/dist/sources/yts.js.map +1 -1
- package/dist/src/cli/display.d.ts +7 -0
- package/dist/src/cli/display.d.ts.map +1 -0
- package/dist/src/cli/display.js +59 -0
- package/dist/src/cli/display.js.map +1 -0
- package/dist/src/cli/parser.d.ts +5 -0
- package/dist/src/cli/parser.d.ts.map +1 -0
- package/dist/src/cli/parser.js +122 -0
- package/dist/src/cli/parser.js.map +1 -0
- package/dist/src/cli/progress.d.ts +15 -0
- package/dist/src/cli/progress.d.ts.map +1 -0
- package/dist/src/cli/progress.js +76 -0
- package/dist/src/cli/progress.js.map +1 -0
- package/dist/src/commands/download.d.ts +2 -0
- package/dist/src/commands/download.d.ts.map +1 -0
- package/dist/src/commands/download.js +70 -0
- package/dist/src/commands/download.js.map +1 -0
- package/dist/src/commands/search.d.ts +3 -0
- package/dist/src/commands/search.d.ts.map +1 -0
- package/dist/src/commands/search.js +46 -0
- package/dist/src/commands/search.js.map +1 -0
- package/dist/src/commands/update.d.ts +2 -0
- package/dist/src/commands/update.d.ts.map +1 -0
- package/dist/src/commands/update.js +32 -0
- package/dist/src/commands/update.js.map +1 -0
- package/dist/src/download/engine.d.ts +6 -0
- package/dist/src/download/engine.d.ts.map +1 -0
- package/dist/src/download/engine.js +163 -0
- package/dist/src/download/engine.js.map +1 -0
- package/dist/src/filters/category.d.ts +3 -0
- package/dist/src/filters/category.d.ts.map +1 -0
- package/dist/src/filters/category.js +24 -0
- package/dist/src/filters/category.js.map +1 -0
- package/dist/src/filters/index.d.ts +5 -0
- package/dist/src/filters/index.d.ts.map +1 -0
- package/dist/src/filters/index.js +13 -0
- package/dist/src/filters/index.js.map +1 -0
- package/dist/src/filters/seeds.d.ts +3 -0
- package/dist/src/filters/seeds.d.ts.map +1 -0
- package/dist/src/filters/seeds.js +7 -0
- package/dist/src/filters/seeds.js.map +1 -0
- package/dist/src/filters/size.d.ts +4 -0
- package/dist/src/filters/size.d.ts.map +1 -0
- package/dist/src/filters/size.js +36 -0
- package/dist/src/filters/size.js.map +1 -0
- package/dist/src/filters/sort.d.ts +5 -0
- package/dist/src/filters/sort.d.ts.map +1 -0
- package/dist/src/filters/sort.js +25 -0
- package/dist/src/filters/sort.js.map +1 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +30 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/sources/1337x.d.ts +11 -0
- package/dist/src/sources/1337x.d.ts.map +1 -0
- package/dist/src/sources/1337x.js +121 -0
- package/dist/src/sources/1337x.js.map +1 -0
- package/dist/src/sources/eztv.d.ts +11 -0
- package/dist/src/sources/eztv.d.ts.map +1 -0
- package/dist/src/sources/eztv.js +104 -0
- package/dist/src/sources/eztv.js.map +1 -0
- package/dist/src/sources/httpClient.d.ts +24 -0
- package/dist/src/sources/httpClient.d.ts.map +1 -0
- package/dist/src/sources/httpClient.js +42 -0
- package/dist/src/sources/httpClient.js.map +1 -0
- package/dist/src/sources/limetorrent.d.ts +11 -0
- package/dist/src/sources/limetorrent.d.ts.map +1 -0
- package/dist/src/sources/limetorrent.js +113 -0
- package/dist/src/sources/limetorrent.js.map +1 -0
- package/dist/src/sources/nyaa.d.ts +11 -0
- package/dist/src/sources/nyaa.d.ts.map +1 -0
- package/dist/src/sources/nyaa.js +119 -0
- package/dist/src/sources/nyaa.js.map +1 -0
- package/dist/src/sources/rarbg.d.ts +11 -0
- package/dist/src/sources/rarbg.d.ts.map +1 -0
- package/dist/src/sources/rarbg.js +122 -0
- package/dist/src/sources/rarbg.js.map +1 -0
- package/dist/src/sources/registry.d.ts +9 -0
- package/dist/src/sources/registry.d.ts.map +1 -0
- package/dist/src/sources/registry.js +70 -0
- package/dist/src/sources/registry.js.map +1 -0
- package/dist/src/sources/solidtorrents.d.ts +11 -0
- package/dist/src/sources/solidtorrents.d.ts.map +1 -0
- package/dist/src/sources/solidtorrents.js +105 -0
- package/dist/src/sources/solidtorrents.js.map +1 -0
- package/dist/src/sources/thepiratebay.d.ts +11 -0
- package/dist/src/sources/thepiratebay.d.ts.map +1 -0
- package/dist/src/sources/thepiratebay.js +67 -0
- package/dist/src/sources/thepiratebay.js.map +1 -0
- package/dist/src/sources/torlock.d.ts +11 -0
- package/dist/src/sources/torlock.d.ts.map +1 -0
- package/dist/src/sources/torlock.js +116 -0
- package/dist/src/sources/torlock.js.map +1 -0
- package/dist/src/sources/torrentproject.d.ts +11 -0
- package/dist/src/sources/torrentproject.d.ts.map +1 -0
- package/dist/src/sources/torrentproject.js +105 -0
- package/dist/src/sources/torrentproject.js.map +1 -0
- package/dist/src/sources/torrentscsv.d.ts +11 -0
- package/dist/src/sources/torrentscsv.d.ts.map +1 -0
- package/dist/src/sources/torrentscsv.js +62 -0
- package/dist/src/sources/torrentscsv.js.map +1 -0
- package/dist/src/sources/yts.d.ts +12 -0
- package/dist/src/sources/yts.d.ts.map +1 -0
- package/dist/src/sources/yts.js +88 -0
- package/dist/src/sources/yts.js.map +1 -0
- package/dist/src/types.d.ts +60 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/output.txt +0 -0
- package/package.json +8 -11
- package/scripts/build.js +9 -0
- package/src/cli/display.ts +63 -57
- package/src/cli/parser.ts +23 -30
- package/src/commands/download.ts +48 -15
- package/src/commands/search.ts +52 -52
- package/src/download/engine.ts +1 -144
- package/src/index.ts +0 -1
- package/src/sources/nyaa.ts +3 -0
- package/src/sources/thepiratebay.ts +1 -0
- package/src/sources/yts.ts +1 -0
- package/src/types.ts +1 -0
- package/bin/tordl.js +0 -5
- package/dist/bin/torrent-cli.js +0 -5
- package/src/cli/progress.ts +0 -78
package/src/cli/parser.ts
CHANGED
|
@@ -3,6 +3,15 @@ import { readFileSync, existsSync } from 'fs';
|
|
|
3
3
|
import { join } from 'path';
|
|
4
4
|
import { FilterConfig, SearchOptions } from '../types';
|
|
5
5
|
|
|
6
|
+
function getVersion(): string {
|
|
7
|
+
try {
|
|
8
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf-8'));
|
|
9
|
+
return pkg.version || '1.0.0';
|
|
10
|
+
} catch {
|
|
11
|
+
return '1.0.0';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
6
15
|
export function loadFilters(): FilterConfig {
|
|
7
16
|
const filtersPath = join(process.cwd(), 'filters.json');
|
|
8
17
|
if (existsSync(filtersPath)) {
|
|
@@ -24,13 +33,8 @@ export function createParser(): Command {
|
|
|
24
33
|
|
|
25
34
|
program
|
|
26
35
|
.name('tor-dl')
|
|
27
|
-
.description('CLI torrent search
|
|
28
|
-
.version('
|
|
29
|
-
.hook('preAction', (thisCommand) => {
|
|
30
|
-
if (thisCommand.name() === 'update') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
36
|
+
.description('CLI torrent search tool - search, open in browser, copy magnet links')
|
|
37
|
+
.version(getVersion(), '-v, --version');
|
|
34
38
|
|
|
35
39
|
program
|
|
36
40
|
.command('search <query>')
|
|
@@ -62,30 +66,19 @@ export function createParser(): Command {
|
|
|
62
66
|
await searchCommand(searchOptions);
|
|
63
67
|
});
|
|
64
68
|
|
|
65
|
-
program
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
await downloadCommand(parseInt(number), options.path);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
program
|
|
75
|
-
.command('update')
|
|
76
|
-
.description('Update sources from remote config')
|
|
77
|
-
.alias('u')
|
|
78
|
-
.action(async () => {
|
|
79
|
-
const { updateCommand } = await import('../commands/update');
|
|
80
|
-
await updateCommand();
|
|
81
|
-
});
|
|
69
|
+
const openCmd = program.command('open <number>', { hidden: true });
|
|
70
|
+
openCmd.description('Open .torrent in browser or copy magnet to clipboard');
|
|
71
|
+
openCmd.action(async (number: string) => {
|
|
72
|
+
const { openInBrowser } = await import('../commands/download');
|
|
73
|
+
await openInBrowser(parseInt(number));
|
|
74
|
+
});
|
|
82
75
|
|
|
83
|
-
program
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
76
|
+
const oCmd = program.command('o <number>');
|
|
77
|
+
oCmd.description('Open .torrent in browser or copy magnet to clipboard');
|
|
78
|
+
oCmd.action(async (number: string) => {
|
|
79
|
+
const { openInBrowser } = await import('../commands/download');
|
|
80
|
+
await openInBrowser(parseInt(number));
|
|
81
|
+
});
|
|
89
82
|
|
|
90
83
|
program.on('command:*', () => {
|
|
91
84
|
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args[0]);
|
package/src/commands/download.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { displayError, displaySuccess, displayInfo } from '../cli/display';
|
|
2
2
|
import { getCachedResults } from '../download/engine';
|
|
3
|
-
import
|
|
3
|
+
import { exec, execSync } from 'child_process';
|
|
4
|
+
import chalk from 'chalk';
|
|
4
5
|
|
|
5
|
-
export async function
|
|
6
|
+
export async function openInBrowser(number: number): Promise<void> {
|
|
6
7
|
const results = getCachedResults();
|
|
7
8
|
|
|
8
9
|
if (results.length === 0) {
|
|
@@ -17,20 +18,52 @@ export async function downloadCommand(number: number, savePath?: string): Promis
|
|
|
17
18
|
|
|
18
19
|
const result = results[number - 1];
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
if (!result.torrentUrl && !result.magnet) {
|
|
22
|
+
displayError('No .torrent URL or magnet available for this result.');
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
const
|
|
26
|
+
const url = result.torrentUrl || result.magnet || '';
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
if (url.startsWith('magnet:')) {
|
|
29
|
+
try {
|
|
30
|
+
if (process.platform === 'win32') {
|
|
31
|
+
execSync(`echo ${url} | clip`, { stdio: 'ignore' });
|
|
32
|
+
} else if (process.platform === 'darwin') {
|
|
33
|
+
execSync(`echo "${url}" | pbcopy`, { stdio: 'ignore' });
|
|
34
|
+
} else {
|
|
35
|
+
execSync(`echo "${url}" | xclip -selection clipboard`, { stdio: 'ignore' });
|
|
36
|
+
}
|
|
37
|
+
displaySuccess('Magnet link copied to clipboard!');
|
|
38
|
+
console.log(chalk.gray(url));
|
|
39
|
+
} catch {
|
|
40
|
+
displayInfo('Magnet link:');
|
|
41
|
+
console.log(chalk.cyan(url));
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
displayInfo('Opening: ' + url);
|
|
45
|
+
const cmd = process.platform === 'win32' ? `start "" "${url}"` :
|
|
46
|
+
process.platform === 'darwin' ? `open "${url}"` :
|
|
47
|
+
`xdg-open "${url}"`;
|
|
48
|
+
|
|
49
|
+
exec(cmd, (err) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
try {
|
|
52
|
+
if (process.platform === 'win32') {
|
|
53
|
+
execSync(`echo ${url} | clip`, { stdio: 'ignore' });
|
|
54
|
+
} else if (process.platform === 'darwin') {
|
|
55
|
+
execSync(`echo "${url}" | pbcopy`, { stdio: 'ignore' });
|
|
56
|
+
} else {
|
|
57
|
+
execSync(`echo "${url}" | xclip -selection clipboard`, { stdio: 'ignore' });
|
|
58
|
+
}
|
|
59
|
+
displaySuccess('URL copied to clipboard!');
|
|
60
|
+
} catch {
|
|
61
|
+
displayError('Failed to open. Copy this URL manually:');
|
|
62
|
+
console.log(chalk.cyan(url));
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
displaySuccess('Opened in browser');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
35
68
|
}
|
|
36
69
|
}
|
package/src/commands/search.ts
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import ora from 'ora';
|
|
2
|
-
import { SearchOptions, TorrentResult } from '../types';
|
|
3
|
-
import { getEnabledSources } from '../sources/registry';
|
|
4
|
-
import { filterByCategory, filterBySize, filterBySeeds, sortResults } from '../filters';
|
|
5
|
-
import { displayResults, displayError } from '../cli/display';
|
|
6
|
-
import { cacheResults } from '../download/engine';
|
|
7
|
-
|
|
8
|
-
export async function searchCommand(options: SearchOptions): Promise<void> {
|
|
9
|
-
const spinner = ora('Searching torrent sources...').start();
|
|
10
|
-
|
|
11
|
-
let sources = getEnabledSources();
|
|
12
|
-
|
|
13
|
-
if (options.sources && options.sources.length > 0) {
|
|
14
|
-
const requested = options.sources.map(s => s.toLowerCase());
|
|
15
|
-
sources = sources.filter(s => requested.includes(s.name.toLowerCase()));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const allResults: TorrentResult[] = [];
|
|
19
|
-
|
|
20
|
-
for (const source of sources) {
|
|
21
|
-
try {
|
|
22
|
-
spinner.text = `Searching ${source.name}...`;
|
|
23
|
-
const results = await source.search(options.query, options.category);
|
|
24
|
-
allResults.push(...results);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
spinner.warn(`Failed to search ${source.name}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
spinner.succeed(`Search complete. Found ${allResults.length} results.`);
|
|
31
|
-
|
|
32
|
-
let filtered = filterByCategory(allResults, options.category || 'all');
|
|
33
|
-
|
|
34
|
-
if (options.minSeeds && options.minSeeds > 0) {
|
|
35
|
-
filtered = filterBySeeds(filtered, options.minSeeds);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (options.minSize || options.maxSize) {
|
|
39
|
-
filtered = filterBySize(filtered, options.minSize, options.maxSize);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
filtered = sortResults(filtered, options.sortBy || 'seeds', options.order || 'desc');
|
|
43
|
-
|
|
44
|
-
if (options.limit && options.limit > 0) {
|
|
45
|
-
filtered = filtered.slice(0, options.limit);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
filtered = filtered.map((r, i) => ({ ...r, num: i + 1 }));
|
|
49
|
-
|
|
50
|
-
cacheResults(filtered);
|
|
51
|
-
|
|
52
|
-
displayResults(filtered);
|
|
1
|
+
import ora from 'ora';
|
|
2
|
+
import { SearchOptions, TorrentResult } from '../types';
|
|
3
|
+
import { getEnabledSources } from '../sources/registry';
|
|
4
|
+
import { filterByCategory, filterBySize, filterBySeeds, sortResults } from '../filters';
|
|
5
|
+
import { displayResults, displayError } from '../cli/display';
|
|
6
|
+
import { cacheResults } from '../download/engine';
|
|
7
|
+
|
|
8
|
+
export async function searchCommand(options: SearchOptions): Promise<void> {
|
|
9
|
+
const spinner = ora('Searching torrent sources...').start();
|
|
10
|
+
|
|
11
|
+
let sources = getEnabledSources();
|
|
12
|
+
|
|
13
|
+
if (options.sources && options.sources.length > 0) {
|
|
14
|
+
const requested = options.sources.map(s => s.toLowerCase());
|
|
15
|
+
sources = sources.filter(s => requested.includes(s.name.toLowerCase()));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const allResults: TorrentResult[] = [];
|
|
19
|
+
|
|
20
|
+
for (const source of sources) {
|
|
21
|
+
try {
|
|
22
|
+
spinner.text = `Searching ${source.name}...`;
|
|
23
|
+
const results = await source.search(options.query, options.category);
|
|
24
|
+
allResults.push(...results);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
spinner.warn(`Failed to search ${source.name}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
spinner.succeed(`Search complete. Found ${allResults.length} results.`);
|
|
31
|
+
|
|
32
|
+
let filtered = filterByCategory(allResults, options.category || 'all');
|
|
33
|
+
|
|
34
|
+
if (options.minSeeds && options.minSeeds > 0) {
|
|
35
|
+
filtered = filterBySeeds(filtered, options.minSeeds);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (options.minSize || options.maxSize) {
|
|
39
|
+
filtered = filterBySize(filtered, options.minSize, options.maxSize);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
filtered = sortResults(filtered, options.sortBy || 'seeds', options.order || 'desc');
|
|
43
|
+
|
|
44
|
+
if (options.limit && options.limit > 0) {
|
|
45
|
+
filtered = filtered.slice(0, options.limit);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
filtered = filtered.map((r, i) => ({ ...r, num: i + 1 }));
|
|
49
|
+
|
|
50
|
+
cacheResults(filtered);
|
|
51
|
+
|
|
52
|
+
displayResults(filtered);
|
|
53
53
|
}
|
package/src/download/engine.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DownloadProgress } from '../cli/progress';
|
|
3
|
-
import { TorrentResult, DownloadOptions } from '../types';
|
|
4
|
-
import axios from 'axios';
|
|
1
|
+
import { TorrentResult } from '../types';
|
|
5
2
|
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
6
3
|
import { join } from 'path';
|
|
7
4
|
|
|
@@ -34,144 +31,4 @@ export function getCachedResults(): TorrentResult[] {
|
|
|
34
31
|
cachedResults = loadCache();
|
|
35
32
|
}
|
|
36
33
|
return cachedResults;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function downloadTorrent(
|
|
40
|
-
result: TorrentResult,
|
|
41
|
-
options: DownloadOptions = {}
|
|
42
|
-
): Promise<void> {
|
|
43
|
-
const client = new WebTorrent();
|
|
44
|
-
const progress = new DownloadProgress();
|
|
45
|
-
const savePath = options.savePath || process.cwd();
|
|
46
|
-
|
|
47
|
-
let torrentId: string;
|
|
48
|
-
|
|
49
|
-
if (result.magnet && result.magnet.startsWith('magnet:')) {
|
|
50
|
-
torrentId = result.magnet;
|
|
51
|
-
} else if (result.url && result.url.includes('magnet:')) {
|
|
52
|
-
torrentId = result.url;
|
|
53
|
-
} else if (result.url && result.url.includes('nyaa.si')) {
|
|
54
|
-
console.log('Fetching magnet link from Nyaa...');
|
|
55
|
-
const magnet = await getMagnetFromResult(result);
|
|
56
|
-
if (magnet) {
|
|
57
|
-
torrentId = magnet;
|
|
58
|
-
} else {
|
|
59
|
-
throw new Error('Could not get magnet link from Nyaa page');
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
console.log('Fetching torrent file...');
|
|
63
|
-
const torrentUrl = await getTorrentUrl(result);
|
|
64
|
-
if (torrentUrl) {
|
|
65
|
-
const response = await axios.get(torrentUrl, { responseType: 'arraybuffer' });
|
|
66
|
-
const tempFile = join(savePath, 'temp.torrent');
|
|
67
|
-
writeFileSync(tempFile, response.data);
|
|
68
|
-
torrentId = tempFile;
|
|
69
|
-
} else {
|
|
70
|
-
throw new Error('Could not get torrent URL');
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
console.log(`\nDownloading: ${result.name}`);
|
|
75
|
-
console.log(`Saving to: ${savePath}\n`);
|
|
76
|
-
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
console.log('Adding torrent to client...');
|
|
79
|
-
console.log('Torrent ID:', torrentId.substring(0, 60) + '...');
|
|
80
|
-
|
|
81
|
-
const torrent = client.add(torrentId, {
|
|
82
|
-
path: savePath
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
torrent.on('warning', (warn) => {
|
|
86
|
-
console.log('Torrent warning:', warn.message);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
torrent.on('peer', (peer) => {
|
|
90
|
-
console.log('New peer connected:', peer);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
console.log('Torrent added, waiting for ready...');
|
|
94
|
-
|
|
95
|
-
torrent.on('ready', () => {
|
|
96
|
-
const total = torrent.length;
|
|
97
|
-
console.log(`✓ Torrent ready! Total size: ${(total / (1024*1024)).toFixed(2)} MB`);
|
|
98
|
-
console.log(` Files: ${torrent.files.map(f => f.name).join(', ')}`);
|
|
99
|
-
console.log(` Info hash: ${torrent.infoHash}`);
|
|
100
|
-
progress.start(total);
|
|
101
|
-
|
|
102
|
-
torrent.on('download', (bytes: number) => {
|
|
103
|
-
const percent = ((torrent.downloaded / total) * 100).toFixed(1);
|
|
104
|
-
process.stdout.write(`\rDownloading: ${percent}% (${(torrent.downloaded/1024/1024).toFixed(1)} MB / ${(total/1024/1024).toFixed(1)} MB) - ${torrent.peers.length} peers `);
|
|
105
|
-
progress.update(torrent.downloaded, total);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
torrent.on('done', () => {
|
|
109
|
-
progress.stop();
|
|
110
|
-
console.log('\n\n✓ Download complete!');
|
|
111
|
-
console.log(`Downloaded to: ${savePath}`);
|
|
112
|
-
client.destroy();
|
|
113
|
-
resolve();
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
torrent.on('error', (err: Error) => {
|
|
118
|
-
console.error('\nDownload error:', err.message);
|
|
119
|
-
client.destroy();
|
|
120
|
-
reject(err);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
setTimeout(() => {
|
|
124
|
-
console.log('\n\nDebug:');
|
|
125
|
-
console.log(' Downloaded:', torrent.downloaded);
|
|
126
|
-
console.log(' Length:', torrent.length);
|
|
127
|
-
console.log(' Peers:', torrent.peers?.length || 0);
|
|
128
|
-
console.log(' Done:', torrent.done);
|
|
129
|
-
|
|
130
|
-
if (torrent.downloaded > 0) {
|
|
131
|
-
console.log('\nDownload in progress but taking long...');
|
|
132
|
-
console.log(`Progress: ${(torrent.downloaded/torrent.length*100).toFixed(1)}%`);
|
|
133
|
-
} else {
|
|
134
|
-
console.log('\nNo progress after 60s - may be stuck or no peers');
|
|
135
|
-
}
|
|
136
|
-
}, 60000);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async function getTorrentUrl(result: TorrentResult): Promise<string> {
|
|
141
|
-
if (result.magnet && result.magnet.startsWith('magnet:')) {
|
|
142
|
-
return result.magnet;
|
|
143
|
-
}
|
|
144
|
-
return result.url;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function getMagnetFromResult(result: TorrentResult): Promise<string> {
|
|
148
|
-
if (result.magnet) return result.magnet;
|
|
149
|
-
if (!result.url) return '';
|
|
150
|
-
|
|
151
|
-
try {
|
|
152
|
-
const { data } = await axios.get(result.url, { timeout: 15000 });
|
|
153
|
-
const cheerio = require('cheerio');
|
|
154
|
-
const $ = cheerio.load(data);
|
|
155
|
-
return $('a[href^="magnet:"]').attr('href') || '';
|
|
156
|
-
} catch {
|
|
157
|
-
return '';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function downloadByNumber(
|
|
162
|
-
number: number,
|
|
163
|
-
savePath?: string
|
|
164
|
-
): Promise<void> {
|
|
165
|
-
const results = getCachedResults();
|
|
166
|
-
|
|
167
|
-
if (results.length === 0) {
|
|
168
|
-
throw new Error('No search results. Run "tor-dl search" first.');
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (number < 1 || number > results.length) {
|
|
172
|
-
throw new Error(`Invalid number. Choose between 1 and ${results.length}`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const result = results[number - 1];
|
|
176
|
-
await downloadTorrent(result, { savePath });
|
|
177
34
|
}
|
package/src/index.ts
CHANGED
package/src/sources/nyaa.ts
CHANGED
|
@@ -36,6 +36,8 @@ export class NyaaScraper implements SourceScraper {
|
|
|
36
36
|
const peers = parseInt($(el).find('td:nth-child(7)').text().trim()) || 0;
|
|
37
37
|
|
|
38
38
|
if (title && title.length > 3) {
|
|
39
|
+
const idMatch = link.match(/\/view\/(\d+)/);
|
|
40
|
+
const torrentUrl = idMatch ? `https://nyaa.si/download/${idMatch[1]}.torrent` : '';
|
|
39
41
|
results.push({
|
|
40
42
|
num: results.length + 1,
|
|
41
43
|
name: title,
|
|
@@ -45,6 +47,7 @@ export class NyaaScraper implements SourceScraper {
|
|
|
45
47
|
peers,
|
|
46
48
|
source: 'Nyaa',
|
|
47
49
|
url: link,
|
|
50
|
+
torrentUrl,
|
|
48
51
|
magnet: ''
|
|
49
52
|
});
|
|
50
53
|
}
|
|
@@ -30,6 +30,7 @@ export class ThePirateBayScraper implements SourceScraper {
|
|
|
30
30
|
peers: parseInt(item.leechers) || 0,
|
|
31
31
|
source: 'ThePirateBay',
|
|
32
32
|
url: `https://thepiratebay.org/torrent/${item.id}`,
|
|
33
|
+
torrentUrl: `magnet:?xt=urn:btih:${item.info_hash}`,
|
|
33
34
|
magnet: `magnet:?xt=urn:btih:${item.info_hash}`,
|
|
34
35
|
hash: item.info_hash
|
|
35
36
|
}));
|
package/src/sources/yts.ts
CHANGED
|
@@ -34,6 +34,7 @@ export class YtsScraper implements SourceScraper {
|
|
|
34
34
|
peers: movie.torrents?.[0]?.peers || 0,
|
|
35
35
|
source: 'YTS',
|
|
36
36
|
url: movie.torrents?.[0]?.url || '',
|
|
37
|
+
torrentUrl: movie.torrents?.[0]?.url || '',
|
|
37
38
|
magnet: movie.torrents?.[0]?.hash ? `magnet:?xt=urn:btih:${movie.torrents[0].hash}` : '',
|
|
38
39
|
hash: movie.torrents?.[0]?.hash
|
|
39
40
|
});
|
package/src/types.ts
CHANGED
package/bin/tordl.js
DELETED
package/dist/bin/torrent-cli.js
DELETED
package/src/cli/progress.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import cliProgress from 'cli-progress';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
|
|
4
|
-
export class DownloadProgress {
|
|
5
|
-
private bar: cliProgress.SingleBar;
|
|
6
|
-
private startTime: number;
|
|
7
|
-
private totalBytes: number = 0;
|
|
8
|
-
private downloadedBytes: number = 0;
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
this.startTime = Date.now();
|
|
12
|
-
this.bar = new cliProgress.SingleBar({
|
|
13
|
-
format: '[{bar}] {percentage}% | {speed} | ETA: {eta} | {downloaded}',
|
|
14
|
-
barCompleteChar: '\u2588',
|
|
15
|
-
barIncompleteChar: '\u2591',
|
|
16
|
-
hideCursor: true,
|
|
17
|
-
fps: 10,
|
|
18
|
-
etaAsynchronous: true
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
start(total: number): void {
|
|
23
|
-
this.totalBytes = total;
|
|
24
|
-
this.bar.start(total, 0, {
|
|
25
|
-
speed: '0 B/s',
|
|
26
|
-
downloaded: '0 MB'
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
update(downloaded: number, total: number): void {
|
|
31
|
-
this.downloadedBytes = downloaded;
|
|
32
|
-
this.totalBytes = total || this.totalBytes;
|
|
33
|
-
|
|
34
|
-
const speed = this.calculateSpeed();
|
|
35
|
-
const eta = this.calculateETA();
|
|
36
|
-
const downloadedMB = (this.downloadedBytes / (1024 * 1024)).toFixed(2);
|
|
37
|
-
|
|
38
|
-
this.bar.update(this.downloadedBytes, {
|
|
39
|
-
speed,
|
|
40
|
-
downloaded: `${downloadedMB} MB`,
|
|
41
|
-
eta
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private calculateSpeed(): string {
|
|
46
|
-
const elapsed = (Date.now() - this.startTime) / 1000;
|
|
47
|
-
const bytesPerSecond = elapsed > 0 ? this.downloadedBytes / elapsed : 0;
|
|
48
|
-
return this.formatBytes(bytesPerSecond) + '/s';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private calculateETA(): string {
|
|
52
|
-
const elapsed = (Date.now() - this.startTime) / 1000;
|
|
53
|
-
if (this.downloadedBytes === 0 || this.totalBytes === 0) return 'N/A';
|
|
54
|
-
|
|
55
|
-
const speed = this.downloadedBytes / elapsed;
|
|
56
|
-
const remaining = this.totalBytes - this.downloadedBytes;
|
|
57
|
-
const seconds = remaining / speed;
|
|
58
|
-
|
|
59
|
-
if (seconds < 60) return `${Math.round(seconds)}s`;
|
|
60
|
-
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ${Math.round(seconds % 60)}s`;
|
|
61
|
-
return `${Math.floor(seconds / 3600)}h ${Math.floor((seconds % 3600) / 60)}m`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
private formatBytes(bytes: number): string {
|
|
65
|
-
if (bytes < 1024) return bytes + ' B';
|
|
66
|
-
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(2) + ' KB';
|
|
67
|
-
if (bytes < 1024 * 1024 * 1024) return (bytes / (1024 * 1024)).toFixed(2) + ' MB';
|
|
68
|
-
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
stop(): void {
|
|
72
|
-
this.bar.stop();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getTotalDownloaded(): number {
|
|
76
|
-
return this.downloadedBytes;
|
|
77
|
-
}
|
|
78
|
-
}
|