forked from imgload/qBittorrent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqBittorrent.py
118 lines (104 loc) · 5.24 KB
/
qBittorrent.py
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
# ============================= FORM ============================= #
#@markdown <h3>⬅️ Click Here to Mount Google Drive</h3>
#@markdown <br><center><img src='https://raw.githubusercontent.com/imgload/qBittorrent/master/content/img/google-drive.png' height="100" alt="netdata"/></center>
# ================================================================ #
from google.colab import drive
drive.mount('/content/drive')
# ============================= FORM ============================= #
#@markdown <br><center><img src='https://raw.githubusercontent.com/imgload/qBittorrent/master/content/img/qbittorrent.png' height="60" alt="netdata"/></center>
#@markdown <h3>⬅️ Click Here to Install qBittorrent</h3>
#@markdown <h4>✅ The rclone method is recommended and always the safest.</h4>
Version = "Newest" #@param ["Newest", "4.1.6", "4.0.3"]
# ================================================================ #
import os, psutil, IPython, uuid, time
import ipywidgets as widgets
from IPython.display import HTML, clear_output
from urllib.request import urlopen
from google.colab import output
class MakeButton(object):
def __init__(self, title, callback):
self._title = title
self._callback = callback
def _repr_html_(self):
callback_id = 'button-' + str(uuid.uuid4())
output.register_callback(callback_id, self._callback)
template = """<button class="p-Widget jupyter-widgets jupyter-button widget-button mod-info" id="{callback_id}">{title}</button>
<script>
document.querySelector("#{callback_id}").onclick = (e) => {{
google.colab.kernel.invokeFunction('{callback_id}', [], {{}})
e.preventDefault();
}};
</script>"""
html = template.format(title=self._title, callback_id=callback_id)
return html
def MakeLabel(description, button_style):
return widgets.Button(description=description, disabled=True, button_style=button_style)
def RandomGenerator():
return time.strftime("%S") + str(time.time()).split(".")[-1]
def CheckProcess(process, command):
for pid in psutil.pids():
try:
p = psutil.Process(pid)
if process in p.name():
for arg in p.cmdline():
if command in str(arg):
return True
else:
pass
else:
pass
except:
continue
def Plugin_Installer(url):
with urlopen(url) as story:
story_words = []
for line in story:
line_words = line.decode('utf-8').split()
for word in line_words:
story_words.append(word)
for word in story_words:
get_ipython().system_raw("wget -q -P /root/.local/share/data/qBittorrent/nova3/engines/ " + word + " &")
def AutoSSH(name,port):
get_ipython().system_raw("autossh -M 0 -fNT -o 'StrictHostKeyChecking=no' -o 'ServerAliveInterval 300' -o 'ServerAliveCountMax 30' -R " + name + ":80:localhost:" + port + " serveo.net &")
def Start_AutoSSH_QB():
if CheckProcess("qbittorrent-nox", "") != True:
get_ipython().system_raw("qbittorrent-nox -d --webui-port=$Port_QB")
if CheckProcess("autossh", Random_URL_QB) != True:
AutoSSH(Random_URL_QB, Port_QB)
def Start_Localhost_QB():
try:
clear_output(wait=True)
!autossh -l $Random_URL_QB -M 0 -o 'StrictHostKeyChecking=no' -o 'ServerAliveInterval 300' -o 'ServerAliveCountMax 30' -R 80:localhost:$Port_QB ssh.localhost.run
except:
Control_Panel_QB()
Control_Panel_QB()
def Control_Panel_QB():
clear_output(wait=True)
display(MakeLabel("✔ Successfully", "success"), MakeButton("Web Link", Start_Localhost_QB), HTML("<h2 style=\"font-family:Trebuchet MS;color:#4f8bd6;\">qBittorrent Edit by Imgload.ir</h2><h4 style=\"font-family:Trebuchet MS;color:#4f8bd6;\">"))
try:
try:
Random_URL_QB
except NameError:
Random_URL_QB = "qb" + RandomGenerator()
Port_QB = "6006"
display(MakeLabel("Installing in Progress", "warning"))
get_ipython().system_raw("rm -rf /content/sample_data/")
if Version != "4.0.3":
get_ipython().system_raw("mkdir -p -m 666 /root/.local/share/data/qBittorrent/nova3/engines/")
Plugin_Installer("https://raw.githubusercontent.com/imgload/qBittorrent/master/res/plugins.txt")
if os.path.isfile("/usr/bin/autossh") == False:
get_ipython().system_raw("apt update -qq -y && apt install autossh -qq -y")
if os.path.isfile("/usr/bin/qbittorrent-nox") == False:
if Version != "Newest":
if Version == "4.0.3":
get_ipython().system_raw("apt install qbittorrent-nox=4.0.3-1 -qq -y")
else:
get_ipython().system_raw("apt install libtorrent-rasterbar9 -qq -y && wget -q https://raw.githubusercontent.com/imgload/qBittorrent/master/res/archive/qbittorrent-nox_$Version\.deb -O /root/.qbittorrent-nox.deb && dpkg -i /root/.qbittorrent-nox.deb && rm -rf /root/.qbittorrent-nox.deb")
else:
get_ipython().system_raw("yes "" | add-apt-repository ppa:qbittorrent-team/qbittorrent-stable && apt install qbittorrent-nox -qq -y")
get_ipython().system_raw("mkdir -p -m 666 /{content/qBittorrent,root/{.qBittorrent_temp,.config/qBittorrent}} && wget -q https://raw.githubusercontent.com/imgload/qBittorrent/master/res/qBittorrent.conf -O /root/.config/qBittorrent/qBittorrent.conf")
Start_AutoSSH_QB()
Control_Panel_QB()
except:
clear_output(wait=True)
display(MakeLabel("✘ Unsuccessfully", "danger"))