Skip to content

Commit

Permalink
build: remove unused dependacies.
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
5hojib authored Feb 17, 2025
1 parent 2585d72 commit 543f9d4
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout deploy branch
- name: Checkout
uses: actions/checkout@v2

- name: Delete unnecessary directories and files
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ruff_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
else
git commit -m "Auto-format code [skip actions]"
git commit -m "format: Auto-format code by ruff [skip actions]."
git push origin ${{ github.ref }}
fi
env:
Expand Down
3 changes: 2 additions & 1 deletion bot/core/torrent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async def aria2_remove(cls, download):
if download.get("status", "") in ["active", "paused", "waiting"]:
await cls.aria2.forceRemove(download.get("gid", ""))
else:
await cls.aria2.removeDownloadResult(download.get("gid", ""))
with contextlib.suppress(Exception):
await cls.aria2.removeDownloadResult(download.get("gid", ""))

@classmethod
async def remove_all(cls):
Expand Down
11 changes: 1 addition & 10 deletions bot/helper/ext_utils/help_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,7 @@
Format: {key: value, key: value, key: value}.
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}]}
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.""",
"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.
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"]}
Notes:
- Add `-del` to the list which you want from the bot to delete the original files after command run complete!
- To execute one of those lists in bot for example, you must use -ff subtitle (list key) or -ff convert (list key)
Here I will explain how to use mltb.* which is reference to files you want to work on.
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.
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.
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.
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.""",
"FFMPEG_CMDS": """Read this guide. http://telegra.ph/Ffmpeg-guide-01-10""",
}

help_string = f"""
Expand Down
15 changes: 8 additions & 7 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from asyncio import sleep
from time import time

from aioaria2.exceptions import Aria2rpcException
from aiofiles.os import path as aiopath
from aiofiles.os import remove
from aiohttp.client_exceptions import ClientError

from bot import LOGGER, intervals, task_dict, task_dict_lock
from bot.core.config_manager import Config
Expand Down Expand Up @@ -62,7 +64,8 @@ async def _on_download_complete(api, data):
gid = data["params"][0]["gid"]
download = await api.tellStatus(gid)
options = await api.getOption(gid)
except Exception:
except (Aria2rpcException, ClientError) as e:
LOGGER.error(f"onDownloadComplete: {e}")
return
if options.get("follow-torrent", "") == "false":
return
Expand Down Expand Up @@ -117,15 +120,15 @@ async def _on_bt_download_complete(api, data):
if task.listener.seed:
try:
await api.changeOption(gid, {"max-upload-limit": "0"})
except Exception as e:
except (Aria2rpcException, ClientError) as e:
LOGGER.error(
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}",
)
else:
try:
await api.forcePause(gid)
except Exception as e:
LOGGER.error(f"{e} GID: {gid}")
except (Aria2rpcException, ClientError) as e:
LOGGER.error(f"onBtDownloadComplete: {e} GID: {gid}")
await task.listener.on_download_complete()
if intervals["stopAll"]:
return
Expand Down Expand Up @@ -171,13 +174,11 @@ async def _on_download_error(api, data):
await sleep(1)
LOGGER.info(f"onDownloadError: {gid}")
error = "None"
try:
with contextlib.suppress(Aria2rpcException, ClientError):
download = await api.tellStatus(gid)
options = await api.getOption(gid)
error = download.get("errorMessage", "")
LOGGER.info(f"Download Error: {error}")
except Exception:
pass
if options.get("follow-torrent", "") == "false":
return
if task := await get_task_by_gid(gid):
Expand Down
5 changes: 4 additions & 1 deletion bot/helper/listeners/direct_listener.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from asyncio import sleep

from aioaria2.exceptions import Aria2rpcException
from aiohttp.client_exceptions import ClientError

from bot import LOGGER
from bot.core.torrent_manager import TorrentManager, aria2_name

Expand Down Expand Up @@ -47,7 +50,7 @@ async def download(self, contents):
options=self._a2c_opt,
position=0,
)
except Exception as e:
except (Aria2rpcException, ClientError) as e:
self._failed += 1
LOGGER.error(f"Unable to download {filename} due to: {e}")
continue
Expand Down
3 changes: 2 additions & 1 deletion bot/helper/listeners/qbit_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from aiofiles.os import path as aiopath
from aiofiles.os import remove
from aioqbt.exc import AQError

from bot import (
LOGGER,
Expand Down Expand Up @@ -187,7 +188,7 @@ async def _qb_listener():
qb_torrents[tag]["seeding"] = False
await _on_seed_finish(tor_info)
await sleep(0.5)
except Exception as e:
except AQError as e:
LOGGER.error(str(e))
await sleep(3)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from base64 import b64encode

from aioaria2.exceptions import Aria2rpcException
from aiofiles import open as aiopen
from aiofiles.os import path as aiopath
from aiofiles.os import remove
from aiohttp.client_exceptions import ClientError

from bot import LOGGER, task_dict, task_dict_lock
from bot.core.config_manager import Config
Expand Down Expand Up @@ -49,7 +51,7 @@ async def add_aria2_download(listener, dpath, header, ratio, seed_time):
uris=[listener.link],
options=a2c_opt,
)
except Exception as e:
except (Aria2rpcException, ClientError) as e:
LOGGER.info(f"Aria2c Download Error: {e}")
await listener.on_download_error(f"{e}")
return
Expand Down
8 changes: 5 additions & 3 deletions bot/helper/mirror_leech_utils/download_utils/qbit_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from aiofiles.os import path as aiopath
from aiofiles.os import remove
from aioqbt.api import AddFormBuilder
from aioqbt.exc import AQError

from bot import LOGGER, qb_torrents, task_dict, task_dict_lock
from bot.core.config_manager import Config
Expand Down Expand Up @@ -38,7 +39,7 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
form = form.seeding_time_limit(int(seed_time))
try:
await TorrentManager.qbittorrent.torrents.add(form.build())
except Exception as e:
except AQError as e:
LOGGER.error(
f"{e}. {listener.mid}. Already added torrent or unsupported link/file type!",
)
Expand Down Expand Up @@ -124,8 +125,9 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
)
await on_download_start(f"{listener.mid}")
await TorrentManager.qbittorrent.torrents.start([ext_hash])
except Exception as e:
del qb_torrents[f"{listener.mid}"]
except AQError as e:
if f"{listener.mid}" in qb_torrents:
del qb_torrents[f"{listener.mid}"]
await listener.on_download_error(f"{e}")
finally:
if await aiopath.exists(listener.link):
Expand Down
12 changes: 1 addition & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
asyncio
aiohttp
aiofiles
aioshutil
anytree==2.8.0
anytree
apscheduler
aioaria2
aioqbt
beautifulsoup4
bencoding
cinemagoer
cloudscraper
config
dnspython
electrogram
fastapi
Expand All @@ -24,14 +19,9 @@ jinja2
langcodes
lxml
motor
mutagen
markdown
natsort
pillow
psutil
pybase64
pycountry
python-dotenv
pyshorteners
python-magic
pytz
Expand Down
14 changes: 7 additions & 7 deletions web/wserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from logging import INFO, WARNING, FileHandler, StreamHandler, basicConfig, getLogger

from aioaria2 import Aria2HttpClient
from aiohttp.client_exceptions import ClientResponseError
from aiohttp.client_exceptions import ClientError
from aioqbt.client import create_client
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, JSONResponse
Expand Down Expand Up @@ -69,7 +69,7 @@ async def re_verify(paused, resumed, hash_id):
id=paused,
priority=0,
)
except ClientResponseError as e:
except ClientError as e:
LOGGER.error(f"{e} Errored in reverification paused!")
if resumed:
try:
Expand All @@ -78,7 +78,7 @@ async def re_verify(paused, resumed, hash_id):
id=resumed,
priority=1,
)
except ClientResponseError as e:
except ClientError as e:
LOGGER.error(f"{e} Errored in reverification resumed!")
k += 1
if k > 5:
Expand Down Expand Up @@ -181,7 +181,7 @@ async def handle_torrent(request: Request):
op = await aria2.getOption(gid)
fpath = f"{op['dir']}/"
content = make_tree(res, "aria2", fpath)
except (Exception, ClientResponseError) as e:
except (Exception, ClientError) as e:
LOGGER.error(str(e))
content = {
"files": [],
Expand All @@ -200,7 +200,7 @@ async def handle_rename(gid, data):
await qbittorrent.torrents.rename_file(hash=gid, **data)
else:
await qbittorrent.torrents.rename_folder(hash=gid, **data)
except ClientResponseError as e:
except ClientError as e:
LOGGER.error(f"{e} Errored in renaming")


Expand All @@ -212,7 +212,7 @@ async def set_qbittorrent(gid, selected_files, unselected_files):
id=unselected_files,
priority=0,
)
except ClientResponseError as e:
except ClientError as e:
LOGGER.error(f"{e} Errored in paused")
if selected_files:
try:
Expand All @@ -221,7 +221,7 @@ async def set_qbittorrent(gid, selected_files, unselected_files):
id=selected_files,
priority=1,
)
except ClientResponseError as e:
except ClientError as e:
LOGGER.error(f"{e} Errored in resumed")
await sleep(0.5)
if not await re_verify(unselected_files, selected_files, gid):
Expand Down

0 comments on commit 543f9d4

Please sign in to comment.