Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit fe22b1c

Browse files
authored
v4.2 (#27)
- Added Extract Password Protected Archive Files - Many minor bug fixed
1 parent d760da4 commit fe22b1c

File tree

5 files changed

+219
-7
lines changed

5 files changed

+219
-7
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ RUN apt-get -qq update && \
1313

1414
COPY requirements.txt .
1515
COPY extract /usr/local/bin
16-
RUN chmod +x /usr/local/bin/extract
16+
COPY pextract /usr/local/bin
17+
RUN chmod +x /usr/local/bin/extract && chmod +x /usr/local/bin/pextract
1718
RUN pip3 install --no-cache-dir -r requirements.txt
1819
RUN locale-gen en_US.UTF-8
1920
ENV LANG en_US.UTF-8

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Fork this repo, than upload credentials.json and token.pickle to your forks
5252
- Custom Buttons
5353
- Custom Filename (Only for url, telegram files and ytdl. Not for mega links and magnet/torrents)
5454
- Speedtest with picture results
55+
- Extracting password protected files and using custom filename see these examples:-
56+
> https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20
5557
- Extract these filetypes and uploads to google drive
5658
> ZIP, RAR, TAR, 7z, ISO, WIM, CAB, GZIP, BZIP2,
5759
> APM, ARJ, CHM, CPIO, CramFS, DEB, DMG, FAT,

bot/modules/mirror.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424
import os
2525
import subprocess
2626
import threading
27+
import re
2728

2829
ariaDlManager = AriaDownloadHelper()
2930
ariaDlManager.start_listener()
3031

3132
class MirrorListener(listeners.MirrorListeners):
32-
def __init__(self, bot, update, isTar=False, tag=None, extract=False):
33+
def __init__(self, bot, update, pswd, isTar=False, tag=None, extract=False):
3334
super().__init__(bot, update)
3435
self.isTar = isTar
3536
self.tag = tag
3637
self.extract = extract
38+
self.pswd = pswd
3739

3840
def onDownloadStarted(self):
3941
pass
@@ -76,7 +78,11 @@ def onDownloadComplete(self):
7678
)
7779
with download_dict_lock:
7880
download_dict[self.uid] = ExtractStatus(name, m_path, size)
79-
archive_result = subprocess.run(["extract", m_path])
81+
pswd = self.pswd
82+
if pswd is not None:
83+
archive_result = subprocess.run(["pextract", m_path, pswd])
84+
else:
85+
archive_result = subprocess.run(["extract", m_path])
8086
if archive_result.returncode == 0:
8187
threading.Thread(target=os.remove, args=(m_path,)).start()
8288
LOGGER.info(f"Deleting archive : {m_path}")
@@ -200,12 +206,21 @@ def _mirror(bot, update, isTar=False, extract=False):
200206
name_args = update.message.text.split('|')
201207
try:
202208
link = message_args[1]
209+
if link.startswith("|") or link.startswith("pswd: "):
210+
link = ''
203211
except IndexError:
204212
link = ''
205213
try:
206214
name = name_args[1]
215+
name = name.strip()
216+
if name.startswith("pswd: "):
217+
name = ''
207218
except IndexError:
208219
name = ''
220+
pswd = re.search('(?<=pswd: )(.*)', update.message.text)
221+
if pswd is not None:
222+
pswd = pswd.groups()
223+
pswd = " ".join(pswd)
209224
LOGGER.info(link)
210225
link = link.strip()
211226
reply_to = update.message.reply_to_message
@@ -240,8 +255,7 @@ def _mirror(bot, update, isTar=False, extract=False):
240255
link = direct_link_generator(link)
241256
except DirectDownloadLinkException as e:
242257
LOGGER.info(f'{link}: {e}')
243-
244-
listener = MirrorListener(bot, update, isTar, tag, extract)
258+
listener = MirrorListener(bot, update, pswd, isTar, tag, extract)
245259
if bot_utils.is_mega_link(link):
246260
link_type = get_mega_link_type(link)
247261
if link_type == "folder" and BLOCK_MEGA_FOLDER:

bot/modules/watch.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def _watch(bot: Bot, update, isTar=False):
4545
tag = reply_to.from_user.username
4646
else:
4747
tag = None
48-
49-
listener = MirrorListener(bot, update, isTar, tag)
48+
pswd = ""
49+
listener = MirrorListener(bot, update, pswd, isTar, tag)
5050
ydl = YoutubeDLHelper(listener)
5151
threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual, name)).start()
5252
sendStatusMessage(update, bot)

pextract

+195
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/bin/bash
2+
3+
if [ $# -lt 1 ]; then
4+
echo "Usage: $(basename $0) FILES"
5+
exit 1
6+
fi
7+
8+
extract() {
9+
arg="$1"
10+
pswd="$2"
11+
cd "$(dirname "$arg")" || exit
12+
case "$arg" in
13+
*.tar.bz2)
14+
tar xjf "$arg" --one-top-level
15+
local code=$?
16+
;;
17+
*.tar.gz)
18+
tar xzf "$arg" --one-top-level
19+
local code=$?
20+
;;
21+
*.bz2)
22+
bunzip2 "$arg"
23+
local code=$?
24+
;;
25+
*.gz)
26+
gunzip "$arg"
27+
local code=$?
28+
;;
29+
*.tar)
30+
tar xf "$arg" --one-top-level
31+
local code=$?
32+
;;
33+
*.tbz2)
34+
(tar xjf "$arg" --one-top-level)
35+
local code=$?
36+
;;
37+
*.tgz)
38+
tar xzf "$arg" --one-top-level
39+
local code=$?
40+
;;
41+
*.zip)
42+
a_dir=$(expr "$arg" : '\(.*\).zip')
43+
7z x "$arg" -o"$a_dir" -p"$pswd"
44+
local code=$?
45+
;;
46+
*.7z)
47+
a_dir=$(expr "$arg" : '\(.*\).7z')
48+
7z x "$arg" -o"$a_dir" -p"$pswd"
49+
local code=$?
50+
;;
51+
*.Z)
52+
uncompress "$arg"
53+
local code=$?
54+
;;
55+
*.rar)
56+
a_dir=$(expr "$arg" : '\(.*\).rar')
57+
mkdir "$a_dir"
58+
7z x "$arg" -o"$a_dir" -p"$pswd"
59+
local code=$?
60+
;;
61+
*.iso)
62+
a_dir=$(expr "$arg" : '\(.*\).iso')
63+
7z x "$arg" -o"$a_dir" -p"$pswd"
64+
local code=$?
65+
;;
66+
*.wim)
67+
a_dir=$(expr "$arg" : '\(.*\).wim')
68+
7z x "$arg" -o"$a_dir" -p"$pswd"
69+
local code=$?
70+
;;
71+
*.cab)
72+
a_dir=$(expr "$arg" : '\(.*\).cab')
73+
7z x "$arg" -o"$a_dir" -p"$pswd"
74+
local code=$?
75+
;;
76+
*.apm)
77+
a_dir=$(expr "$arg" : '\(.*\).apm')
78+
7z x "$arg" -o"$a_dir" -p"$pswd"
79+
local code=$?
80+
;;
81+
*.arj)
82+
a_dir=$(expr "$arg" : '\(.*\).arj')
83+
7z x "$arg" -o"$a_dir" -p"$pswd"
84+
local code=$?
85+
;;
86+
*.chm)
87+
a_dir=$(expr "$arg" : '\(.*\).chm')
88+
7z x "$arg" -o"$a_dir" -p"$pswd"
89+
local code=$?
90+
;;
91+
*.cpio)
92+
a_dir=$(expr "$arg" : '\(.*\).cpio')
93+
7z x "$arg" -o"$a_dir" -p"$pswd"
94+
local code=$?
95+
;;
96+
*.cramfs)
97+
a_dir=$(expr "$arg" : '\(.*\).cramfs')
98+
7z x "$arg" -o"$a_dir" -p"$pswd"
99+
local code=$?
100+
;;
101+
*.deb)
102+
a_dir=$(expr "$arg" : '\(.*\).deb')
103+
7z x "$arg" -o"$a_dir" -p"$pswd"
104+
local code=$?
105+
;;
106+
*.dmg)
107+
a_dir=$(expr "$arg" : '\(.*\).dmg')
108+
7z x "$arg" -o"$a_dir" -p"$pswd"
109+
local code=$?
110+
;;
111+
*.fat)
112+
a_dir=$(expr "$arg" : '\(.*\).fat')
113+
7z x "$arg" -o"$a_dir" -p"$pswd"
114+
local code=$?
115+
;;
116+
*.hfs)
117+
a_dir=$(expr "$arg" : '\(.*\).hfs')
118+
7z x "$arg" -o"$a_dir" -p"$pswd"
119+
local code=$?
120+
;;
121+
*.lzh)
122+
a_dir=$(expr "$arg" : '\(.*\).lzh')
123+
7z x "$arg" -o"$a_dir" -p"$pswd"
124+
local code=$?
125+
;;
126+
*.lzma)
127+
a_dir=$(expr "$arg" : '\(.*\).lzma')
128+
7z x "$arg" -o"$a_dir" -p"$pswd"
129+
local code=$?
130+
;;
131+
*.lzma2)
132+
a_dir=$(expr "$arg" : '\(.*\).lzma2')
133+
7z x "$arg" -o"$a_dir" -p"$pswd"
134+
local code=$?
135+
;;
136+
*.mbr)
137+
a_dir=$(expr "$arg" : '\(.*\).mbr')
138+
7z x "$arg" -o"$a_dir" -p"$pswd"
139+
local code=$?
140+
;;
141+
*.msi)
142+
a_dir=$(expr "$arg" : '\(.*\).msi')
143+
7z x "$arg" -o"$a_dir" -p"$pswd"
144+
local code=$?
145+
;;
146+
*.mslz)
147+
a_dir=$(expr "$arg" : '\(.*\).mslz')
148+
7z x "$arg" -o"$a_dir" -p"$pswd"
149+
local code=$?
150+
;;
151+
*.nsis)
152+
a_dir=$(expr "$arg" : '\(.*\).nsis')
153+
7z x "$arg" -o"$a_dir" -p"$pswd"
154+
local code=$?
155+
;;
156+
*.ntfs)
157+
a_dir=$(expr "$arg" : '\(.*\).ntfs')
158+
7z x "$arg" -o"$a_dir" -p"$pswd"
159+
local code=$?
160+
;;
161+
*.rpm)
162+
a_dir=$(expr "$arg" : '\(.*\).rpm')
163+
7z x "$arg" -o"$a_dir" -p"$pswd"
164+
local code=$?
165+
;;
166+
*.squashfs)
167+
a_dir=$(expr "$arg" : '\(.*\).squashfs')
168+
7z x "$arg" -o"$a_dir" -p"$pswd"
169+
local code=$?
170+
;;
171+
*.udf)
172+
a_dir=$(expr "$arg" : '\(.*\).udf')
173+
7z x "$arg" -o"$a_dir" -p"$pswd"
174+
local code=$?
175+
;;
176+
*.vhd)
177+
a_dir=$(expr "$arg" : '\(.*\).vhd')
178+
7z x "$arg" -o"$a_dir" -p"$pswd"
179+
local code=$?
180+
;;
181+
*.xar)
182+
a_dir=$(expr "$arg" : '\(.*\).xar')
183+
7z x "$arg" -o"$a_dir" -p"$pswd"
184+
local code=$?
185+
;;
186+
*)
187+
echo "'$arg' cannot be extracted via extract()" 1>&2
188+
exit 1
189+
;;
190+
esac
191+
cd - || exit $?
192+
exit $code
193+
}
194+
195+
extract "$1" "$2"

0 commit comments

Comments
 (0)