Skip to content

Commit 543f9d4

Browse files
authored
build: remove unused dependacies.
## Summary by Sourcery Update dependencies, improve error handling, and refine documentation and workflows. Improve commit messages in the ruff format workflow and update the FFMPEG commands help message. Bug Fixes: - Handle `Aria2rpcException` and `ClientError` exceptions during download completion and error handling to prevent crashes. - Fix error handling in download completion and rename functions. Build: - Update project dependencies by removing or updating specific packages, including `aiohttp`, `anytree`, `beautifulsoup4`, `bencoding`, `cinemagoer`, `config`, `mutagen`, `markdown`, `pybase64`, `pycountry`, `python-dotenv`. CI: - Improve commit message format in ruff format workflow. Documentation: - Update FFMPEG commands help message.
1 parent 2585d72 commit 543f9d4

11 files changed

Lines changed: 35 additions & 44 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
deploy:
3636
runs-on: ubuntu-latest
3737
steps:
38-
- name: Checkout deploy branch
38+
- name: Checkout
3939
uses: actions/checkout@v2
4040

4141
- name: Delete unnecessary directories and files

.github/workflows/ruff_format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
if git diff-index --quiet HEAD --; then
3333
echo "No changes to commit."
3434
else
35-
git commit -m "Auto-format code [skip actions]"
35+
git commit -m "format: Auto-format code by ruff [skip actions]."
3636
git push origin ${{ github.ref }}
3737
fi
3838
env:

bot/core/torrent_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ async def aria2_remove(cls, download):
2626
if download.get("status", "") in ["active", "paused", "waiting"]:
2727
await cls.aria2.forceRemove(download.get("gid", ""))
2828
else:
29-
await cls.aria2.removeDownloadResult(download.get("gid", ""))
29+
with contextlib.suppress(Exception):
30+
await cls.aria2.removeDownloadResult(download.get("gid", ""))
3031

3132
@classmethod
3233
async def remove_all(cls):

bot/helper/ext_utils/help_messages.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,16 +409,7 @@
409409
Format: {key: value, key: value, key: value}.
410410
Example: {"format": "bv*+mergeall[vcodec=none]", "nocheckcertificate": True, "playliststart": 10, "fragment_retries": float("inf"), "matchtitle": "S13", "writesubtitles": True, "live_from_start": True, "postprocessor_args": {"ffmpeg": ["-threads", "4"]}, "wait_for_video": (5, 100), "download_ranges": [{"start_time": 0, "end_time": 10}]}
411411
Check all yt-dlp api options from this <a href='https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L184'>FILE</a> or use this <a href='https://t.me/mltb_official_channel/177'>script</a> to convert cli arguments to api options.""",
412-
"FFMPEG_CMDS": """Dict of list values of ffmpeg commands. You can set multiple ffmpeg commands for all files before upload. Don't write ffmpeg at beginning, start directly with the arguments.
413-
Examples: {"subtitle": ["-i mltb.mkv -c copy -c:s srt mltb.mkv", "-i mltb.video -c copy -c:s srt mltb"], "convert": ["-i mltb.m4a -c:a libmp3lame -q:a 2 mltb.mp3", "-i mltb.audio -c:a libmp3lame -q:a 2 mltb.mp3"], extract: ["-i mltb -map 0:a -c copy mltb.mka -map 0:s -c copy mltb.srt"]}
414-
Notes:
415-
- Add `-del` to the list which you want from the bot to delete the original files after command run complete!
416-
- To execute one of those lists in bot for example, you must use -ff subtitle (list key) or -ff convert (list key)
417-
Here I will explain how to use mltb.* which is reference to files you want to work on.
418-
1. First cmd: the input is mltb.mkv so this cmd will work only on mkv videos and the output is mltb.mkv also so all outputs is mkv. -del will delete the original media after complete run of the cmd.
419-
2. Second cmd: the input is mltb.video so this cmd will work on all videos and the output is only mltb so the extenstion is same as input files.
420-
3. Third cmd: the input in mltb.m4a so this cmd will work only on m4a audios and the output is mltb.mp3 so the output extension is mp3.
421-
4. Fourth cmd: the input is mltb.audio so this cmd will work on all audios and the output is mltb.mp3 so the output extension is mp3.""",
412+
"FFMPEG_CMDS": """Read this guide. http://telegra.ph/Ffmpeg-guide-01-10""",
422413
}
423414

424415
help_string = f"""

bot/helper/listeners/aria2_listener.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from asyncio import sleep
33
from time import time
44

5+
from aioaria2.exceptions import Aria2rpcException
56
from aiofiles.os import path as aiopath
67
from aiofiles.os import remove
8+
from aiohttp.client_exceptions import ClientError
79

810
from bot import LOGGER, intervals, task_dict, task_dict_lock
911
from bot.core.config_manager import Config
@@ -62,7 +64,8 @@ async def _on_download_complete(api, data):
6264
gid = data["params"][0]["gid"]
6365
download = await api.tellStatus(gid)
6466
options = await api.getOption(gid)
65-
except Exception:
67+
except (Aria2rpcException, ClientError) as e:
68+
LOGGER.error(f"onDownloadComplete: {e}")
6669
return
6770
if options.get("follow-torrent", "") == "false":
6871
return
@@ -117,15 +120,15 @@ async def _on_bt_download_complete(api, data):
117120
if task.listener.seed:
118121
try:
119122
await api.changeOption(gid, {"max-upload-limit": "0"})
120-
except Exception as e:
123+
except (Aria2rpcException, ClientError) as e:
121124
LOGGER.error(
122125
f"{e} You are not able to seed because you added global option seed-time=0 without adding specific seed_time for this torrent GID: {gid}",
123126
)
124127
else:
125128
try:
126129
await api.forcePause(gid)
127-
except Exception as e:
128-
LOGGER.error(f"{e} GID: {gid}")
130+
except (Aria2rpcException, ClientError) as e:
131+
LOGGER.error(f"onBtDownloadComplete: {e} GID: {gid}")
129132
await task.listener.on_download_complete()
130133
if intervals["stopAll"]:
131134
return
@@ -171,13 +174,11 @@ async def _on_download_error(api, data):
171174
await sleep(1)
172175
LOGGER.info(f"onDownloadError: {gid}")
173176
error = "None"
174-
try:
177+
with contextlib.suppress(Aria2rpcException, ClientError):
175178
download = await api.tellStatus(gid)
176179
options = await api.getOption(gid)
177180
error = download.get("errorMessage", "")
178181
LOGGER.info(f"Download Error: {error}")
179-
except Exception:
180-
pass
181182
if options.get("follow-torrent", "") == "false":
182183
return
183184
if task := await get_task_by_gid(gid):

bot/helper/listeners/direct_listener.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from asyncio import sleep
22

3+
from aioaria2.exceptions import Aria2rpcException
4+
from aiohttp.client_exceptions import ClientError
5+
36
from bot import LOGGER
47
from bot.core.torrent_manager import TorrentManager, aria2_name
58

@@ -47,7 +50,7 @@ async def download(self, contents):
4750
options=self._a2c_opt,
4851
position=0,
4952
)
50-
except Exception as e:
53+
except (Aria2rpcException, ClientError) as e:
5154
self._failed += 1
5255
LOGGER.error(f"Unable to download {filename} due to: {e}")
5356
continue

bot/helper/listeners/qbit_listener.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from aiofiles.os import path as aiopath
66
from aiofiles.os import remove
7+
from aioqbt.exc import AQError
78

89
from bot import (
910
LOGGER,
@@ -187,7 +188,7 @@ async def _qb_listener():
187188
qb_torrents[tag]["seeding"] = False
188189
await _on_seed_finish(tor_info)
189190
await sleep(0.5)
190-
except Exception as e:
191+
except AQError as e:
191192
LOGGER.error(str(e))
192193
await sleep(3)
193194

bot/helper/mirror_leech_utils/download_utils/aria2_download.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from base64 import b64encode
22

3+
from aioaria2.exceptions import Aria2rpcException
34
from aiofiles import open as aiopen
45
from aiofiles.os import path as aiopath
56
from aiofiles.os import remove
7+
from aiohttp.client_exceptions import ClientError
68

79
from bot import LOGGER, task_dict, task_dict_lock
810
from bot.core.config_manager import Config
@@ -49,7 +51,7 @@ async def add_aria2_download(listener, dpath, header, ratio, seed_time):
4951
uris=[listener.link],
5052
options=a2c_opt,
5153
)
52-
except Exception as e:
54+
except (Aria2rpcException, ClientError) as e:
5355
LOGGER.info(f"Aria2c Download Error: {e}")
5456
await listener.on_download_error(f"{e}")
5557
return

bot/helper/mirror_leech_utils/download_utils/qbit_download.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from aiofiles.os import path as aiopath
55
from aiofiles.os import remove
66
from aioqbt.api import AddFormBuilder
7+
from aioqbt.exc import AQError
78

89
from bot import LOGGER, qb_torrents, task_dict, task_dict_lock
910
from bot.core.config_manager import Config
@@ -38,7 +39,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
3839
form = form.seeding_time_limit(int(seed_time))
3940
try:
4041
await TorrentManager.qbittorrent.torrents.add(form.build())
41-
except Exception as e:
42+
except AQError as e:
4243
LOGGER.error(
4344
f"{e}. {listener.mid}. Already added torrent or unsupported link/file type!",
4445
)
@@ -124,8 +125,9 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
124125
)
125126
await on_download_start(f"{listener.mid}")
126127
await TorrentManager.qbittorrent.torrents.start([ext_hash])
127-
except Exception as e:
128-
del qb_torrents[f"{listener.mid}"]
128+
except AQError as e:
129+
if f"{listener.mid}" in qb_torrents:
130+
del qb_torrents[f"{listener.mid}"]
129131
await listener.on_download_error(f"{e}")
130132
finally:
131133
if await aiopath.exists(listener.link):

requirements.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
asyncio
2-
aiohttp
32
aiofiles
43
aioshutil
5-
anytree==2.8.0
4+
anytree
65
apscheduler
76
aioaria2
87
aioqbt
9-
beautifulsoup4
10-
bencoding
11-
cinemagoer
128
cloudscraper
13-
config
149
dnspython
1510
electrogram
1611
fastapi
@@ -24,14 +19,9 @@ jinja2
2419
langcodes
2520
lxml
2621
motor
27-
mutagen
28-
markdown
2922
natsort
3023
pillow
3124
psutil
32-
pybase64
33-
pycountry
34-
python-dotenv
3525
pyshorteners
3626
python-magic
3727
pytz

0 commit comments

Comments
 (0)