-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
133 lines (123 loc) · 4.93 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* FreeFlix - A command-line torrent streaming application
*
* This program allows users to search and stream movies/TV shows from torrent sources
* directly to their media player of choice (MPV or VLC).
*
* @copyright Copyright (C) 2025
* @license GNU General Public License v3.0
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Features:
* - Integrated Mullvad VPN support
* - Cross-platform support (Windows, macOS, Linux)
* - Multiple media player support (MPV, VLC)
* - Automatic terminal detection
* - Peer filtering (minimum 2 peers required)
*
* Dependencies:
* - readline: For command line interface
* - torrent-browse: For searching torrents
* - inquirer: For interactive selection
* - bun: For process execution
* - peerflix: For torrent streaming (external dependency)
* - Mullvad VPN (optional)
*
* Command line options:
* --no-mullvad: Skip Mullvad VPN connection check
*
* @requires node:readline
* @requires process
* @requires torrent-browse
* @requires inquirer
* @requires bun
*/
import * as readline from "node:readline";
import { stdin as input, stdout as output } from "process";
import { search, defaultProviders } from "torrent-browse";
import inquirer from "inquirer";
import { $ } from "bun";
const rl = readline.createInterface({ input, output });
if (!process.argv.includes("--no-mullvad")) {
try {
await $`mullvad connect && sleep 1`.quiet();
console.log("Mullvad enabled!");
} catch (error) {
console.error("Mullvad not found, skipping...");
}
}
rl.question("Search movies or episodes: ", (searchQuery: string) => {
search(defaultProviders, searchQuery)
.then(async result => {
const choices = result.items
.filter(item => item.data.peers > 2)
.map(item => ({ name: item.data.name, value: item }));
if (choices.length == 0) {
console.error("No available torrents found :(");
return;
}
const answer = await inquirer.prompt([
{
type: "list",
name: "selectedItem",
message: "Select an item:",
choices: choices
}
]);
fetch(answer.selectedItem.data.link).then(response => response.text()).then(async html => {
let magnetMatch = html.match(/href="(magnet:[^"]+)"/)?.toString().replace("href=\"", "").split("\"")[0];
if (!magnetMatch || magnetMatch === "") {
magnetMatch = answer.selectedItem.data.magnet;
}
const players = process.platform === 'win32' ? ['mpv.exe', 'vlc.exe']
: process.platform === 'darwin' ? ['mpv', 'vlc']
: ['mpv', 'vlc'];
const terminals = process.platform === 'win32'
? ['cmd.exe']
: process.platform === 'darwin'
? ['Terminal.app', 'iTerm.app']
: ['kgx', 'gnome-terminal', 'xterm', 'konsole', 'terminal'];
let player = 'mpv';
for (const p of players) {
try {
if ((await $`which ${p}`.quiet()).exitCode === 0) {
player = p;
break;
}
} catch {
continue;
}
}
let terminal = 'xterm';
for (const t of terminals) {
try {
if ((await $`which ${t}`.quiet()).exitCode === 0) {
terminal = t;
break;
}
} catch {
continue;
}
}
terminal = process.platform === 'win32' ? 'cmd.exe' :
process.platform === 'darwin' ? 'Terminal.app' : terminal;
if (process.platform === 'win32') {
await $`${terminal} /c "peerflix ${magnetMatch} --${player}"`;
} else if (process.platform === 'darwin') {
await $`open -a ${terminal} peerflix ${magnetMatch} --${player}`;
} else {
await $`${terminal} -e "peerflix ${magnetMatch} --${player}"`;
}
});
})
.catch(error => console.error(error))
.finally(() => rl.close());
});