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.
Files changed (156) hide show
  1. package/AGENTS.md +6 -6
  2. package/README.md +22 -180
  3. package/dist/bin/{tordl.js → tor-dl.js} +2 -3
  4. package/dist/cli/display.d.ts.map +1 -1
  5. package/dist/cli/display.js +13 -9
  6. package/dist/cli/display.js.map +1 -1
  7. package/dist/cli/parser.d.ts.map +1 -1
  8. package/dist/cli/parser.js +21 -27
  9. package/dist/cli/parser.js.map +1 -1
  10. package/dist/commands/download.d.ts +1 -1
  11. package/dist/commands/download.d.ts.map +1 -1
  12. package/dist/commands/download.js +55 -49
  13. package/dist/commands/download.js.map +1 -1
  14. package/dist/download/engine.d.ts +1 -3
  15. package/dist/download/engine.d.ts.map +1 -1
  16. package/dist/download/engine.js +0 -129
  17. package/dist/download/engine.js.map +1 -1
  18. package/dist/index.d.ts +0 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +0 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/sources/nyaa.d.ts.map +1 -1
  23. package/dist/sources/nyaa.js +3 -0
  24. package/dist/sources/nyaa.js.map +1 -1
  25. package/dist/sources/thepiratebay.d.ts.map +1 -1
  26. package/dist/sources/thepiratebay.js +1 -0
  27. package/dist/sources/thepiratebay.js.map +1 -1
  28. package/dist/sources/yts.d.ts.map +1 -1
  29. package/dist/sources/yts.js +1 -0
  30. package/dist/sources/yts.js.map +1 -1
  31. package/dist/src/cli/display.d.ts +7 -0
  32. package/dist/src/cli/display.d.ts.map +1 -0
  33. package/dist/src/cli/display.js +59 -0
  34. package/dist/src/cli/display.js.map +1 -0
  35. package/dist/src/cli/parser.d.ts +5 -0
  36. package/dist/src/cli/parser.d.ts.map +1 -0
  37. package/dist/src/cli/parser.js +122 -0
  38. package/dist/src/cli/parser.js.map +1 -0
  39. package/dist/src/cli/progress.d.ts +15 -0
  40. package/dist/src/cli/progress.d.ts.map +1 -0
  41. package/dist/src/cli/progress.js +76 -0
  42. package/dist/src/cli/progress.js.map +1 -0
  43. package/dist/src/commands/download.d.ts +2 -0
  44. package/dist/src/commands/download.d.ts.map +1 -0
  45. package/dist/src/commands/download.js +70 -0
  46. package/dist/src/commands/download.js.map +1 -0
  47. package/dist/src/commands/search.d.ts +3 -0
  48. package/dist/src/commands/search.d.ts.map +1 -0
  49. package/dist/src/commands/search.js +46 -0
  50. package/dist/src/commands/search.js.map +1 -0
  51. package/dist/src/commands/update.d.ts +2 -0
  52. package/dist/src/commands/update.d.ts.map +1 -0
  53. package/dist/src/commands/update.js +32 -0
  54. package/dist/src/commands/update.js.map +1 -0
  55. package/dist/src/download/engine.d.ts +6 -0
  56. package/dist/src/download/engine.d.ts.map +1 -0
  57. package/dist/src/download/engine.js +163 -0
  58. package/dist/src/download/engine.js.map +1 -0
  59. package/dist/src/filters/category.d.ts +3 -0
  60. package/dist/src/filters/category.d.ts.map +1 -0
  61. package/dist/src/filters/category.js +24 -0
  62. package/dist/src/filters/category.js.map +1 -0
  63. package/dist/src/filters/index.d.ts +5 -0
  64. package/dist/src/filters/index.d.ts.map +1 -0
  65. package/dist/src/filters/index.js +13 -0
  66. package/dist/src/filters/index.js.map +1 -0
  67. package/dist/src/filters/seeds.d.ts +3 -0
  68. package/dist/src/filters/seeds.d.ts.map +1 -0
  69. package/dist/src/filters/seeds.js +7 -0
  70. package/dist/src/filters/seeds.js.map +1 -0
  71. package/dist/src/filters/size.d.ts +4 -0
  72. package/dist/src/filters/size.d.ts.map +1 -0
  73. package/dist/src/filters/size.js +36 -0
  74. package/dist/src/filters/size.js.map +1 -0
  75. package/dist/src/filters/sort.d.ts +5 -0
  76. package/dist/src/filters/sort.d.ts.map +1 -0
  77. package/dist/src/filters/sort.js +25 -0
  78. package/dist/src/filters/sort.js.map +1 -0
  79. package/dist/src/index.d.ts +11 -0
  80. package/dist/src/index.d.ts.map +1 -0
  81. package/dist/src/index.js +30 -0
  82. package/dist/src/index.js.map +1 -0
  83. package/dist/src/sources/1337x.d.ts +11 -0
  84. package/dist/src/sources/1337x.d.ts.map +1 -0
  85. package/dist/src/sources/1337x.js +121 -0
  86. package/dist/src/sources/1337x.js.map +1 -0
  87. package/dist/src/sources/eztv.d.ts +11 -0
  88. package/dist/src/sources/eztv.d.ts.map +1 -0
  89. package/dist/src/sources/eztv.js +104 -0
  90. package/dist/src/sources/eztv.js.map +1 -0
  91. package/dist/src/sources/httpClient.d.ts +24 -0
  92. package/dist/src/sources/httpClient.d.ts.map +1 -0
  93. package/dist/src/sources/httpClient.js +42 -0
  94. package/dist/src/sources/httpClient.js.map +1 -0
  95. package/dist/src/sources/limetorrent.d.ts +11 -0
  96. package/dist/src/sources/limetorrent.d.ts.map +1 -0
  97. package/dist/src/sources/limetorrent.js +113 -0
  98. package/dist/src/sources/limetorrent.js.map +1 -0
  99. package/dist/src/sources/nyaa.d.ts +11 -0
  100. package/dist/src/sources/nyaa.d.ts.map +1 -0
  101. package/dist/src/sources/nyaa.js +119 -0
  102. package/dist/src/sources/nyaa.js.map +1 -0
  103. package/dist/src/sources/rarbg.d.ts +11 -0
  104. package/dist/src/sources/rarbg.d.ts.map +1 -0
  105. package/dist/src/sources/rarbg.js +122 -0
  106. package/dist/src/sources/rarbg.js.map +1 -0
  107. package/dist/src/sources/registry.d.ts +9 -0
  108. package/dist/src/sources/registry.d.ts.map +1 -0
  109. package/dist/src/sources/registry.js +70 -0
  110. package/dist/src/sources/registry.js.map +1 -0
  111. package/dist/src/sources/solidtorrents.d.ts +11 -0
  112. package/dist/src/sources/solidtorrents.d.ts.map +1 -0
  113. package/dist/src/sources/solidtorrents.js +105 -0
  114. package/dist/src/sources/solidtorrents.js.map +1 -0
  115. package/dist/src/sources/thepiratebay.d.ts +11 -0
  116. package/dist/src/sources/thepiratebay.d.ts.map +1 -0
  117. package/dist/src/sources/thepiratebay.js +67 -0
  118. package/dist/src/sources/thepiratebay.js.map +1 -0
  119. package/dist/src/sources/torlock.d.ts +11 -0
  120. package/dist/src/sources/torlock.d.ts.map +1 -0
  121. package/dist/src/sources/torlock.js +116 -0
  122. package/dist/src/sources/torlock.js.map +1 -0
  123. package/dist/src/sources/torrentproject.d.ts +11 -0
  124. package/dist/src/sources/torrentproject.d.ts.map +1 -0
  125. package/dist/src/sources/torrentproject.js +105 -0
  126. package/dist/src/sources/torrentproject.js.map +1 -0
  127. package/dist/src/sources/torrentscsv.d.ts +11 -0
  128. package/dist/src/sources/torrentscsv.d.ts.map +1 -0
  129. package/dist/src/sources/torrentscsv.js +62 -0
  130. package/dist/src/sources/torrentscsv.js.map +1 -0
  131. package/dist/src/sources/yts.d.ts +12 -0
  132. package/dist/src/sources/yts.d.ts.map +1 -0
  133. package/dist/src/sources/yts.js +88 -0
  134. package/dist/src/sources/yts.js.map +1 -0
  135. package/dist/src/types.d.ts +60 -0
  136. package/dist/src/types.d.ts.map +1 -0
  137. package/dist/src/types.js +3 -0
  138. package/dist/src/types.js.map +1 -0
  139. package/dist/types.d.ts +1 -0
  140. package/dist/types.d.ts.map +1 -1
  141. package/output.txt +0 -0
  142. package/package.json +8 -11
  143. package/scripts/build.js +9 -0
  144. package/src/cli/display.ts +63 -57
  145. package/src/cli/parser.ts +23 -30
  146. package/src/commands/download.ts +48 -15
  147. package/src/commands/search.ts +52 -52
  148. package/src/download/engine.ts +1 -144
  149. package/src/index.ts +0 -1
  150. package/src/sources/nyaa.ts +3 -0
  151. package/src/sources/thepiratebay.ts +1 -0
  152. package/src/sources/yts.ts +1 -0
  153. package/src/types.ts +1 -0
  154. package/bin/tordl.js +0 -5
  155. package/dist/bin/torrent-cli.js +0 -5
  156. 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 and download tool')
28
- .version('1.0.0')
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
- .command('download <number>')
67
- .description('Download a torrent by number from previous search')
68
- .option('-p, --path <path>', 'Download path')
69
- .action(async (number: string, options) => {
70
- const { downloadCommand } = await import('../commands/download');
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
- .argument('<number>', 'Torrent number to download')
85
- .action(async (number: string) => {
86
- const { downloadCommand } = await import('../commands/download');
87
- await downloadCommand(parseInt(number));
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]);
@@ -1,8 +1,9 @@
1
1
  import { displayError, displaySuccess, displayInfo } from '../cli/display';
2
2
  import { getCachedResults } from '../download/engine';
3
- import ora from 'ora';
3
+ import { exec, execSync } from 'child_process';
4
+ import chalk from 'chalk';
4
5
 
5
- export async function downloadCommand(number: number, savePath?: string): Promise<void> {
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
- displayInfo(`Downloading: ${result.name}`);
21
- displayInfo(`Source: ${result.source}`);
22
- displayInfo(`Size: ${result.size}`);
23
- displayInfo(`Seeds: ${result.seeds}\n`);
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 spinner = ora('Starting download...').start();
26
+ const url = result.torrentUrl || result.magnet || '';
26
27
 
27
- try {
28
- const { downloadTorrent } = await import('../download/engine');
29
- await downloadTorrent(result, { savePath });
30
- spinner.succeed('Download complete!');
31
- } catch (error: any) {
32
- spinner.fail(`Download failed: ${error.message}`);
33
- displayError('Make sure you have a stable internet connection and sufficient disk space.');
34
- process.exit(1);
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
  }
@@ -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
  }
@@ -1,7 +1,4 @@
1
- import WebTorrent from 'webtorrent';
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
@@ -1,7 +1,6 @@
1
1
  export * from './types';
2
2
  export { createParser, loadFilters } from './cli/parser';
3
3
  export * from './cli/display';
4
- export * from './cli/progress';
5
4
  export * from './sources/registry';
6
5
  export * from './filters';
7
6
  export * from './download/engine';
@@ -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
  }));
@@ -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
@@ -11,6 +11,7 @@ export interface TorrentResult {
11
11
  hash?: string;
12
12
  category?: string;
13
13
  date?: string;
14
+ torrentUrl?: string;
14
15
  }
15
16
 
16
17
  export interface SourceConfig {
package/bin/tordl.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- const { createParser } = require('../dist/cli/parser');
3
-
4
- const program = createParser();
5
- program.parse(process.argv);
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
- const { createParser } = require('../cli/parser');
3
-
4
- const program = createParser();
5
- program.parse(process.argv);
@@ -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
- }