Skip to content

Commit

Permalink
Merge pull request #1736 from 5hojib/master
Browse files Browse the repository at this point in the history
Minor fix and format
  • Loading branch information
anasty17 authored Jul 15, 2024
2 parents d18c00a + 66483ea commit acfab96
Show file tree
Hide file tree
Showing 47 changed files with 153 additions and 124 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
Empty file modified aria-nox-nzb.sh
100755 → 100644
Empty file.
8 changes: 4 additions & 4 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
if bool(environ.get("_____REMOVE_THIS_LINE_____")):
log_error("The README.md file there to be read! Exiting now!")
exit(1)
except:
except Exception:
pass

task_dict_lock = Lock()
Expand Down Expand Up @@ -192,7 +192,7 @@
max_concurrent_transmissions=10,
).start()
IS_PREMIUM_USER = user.me.is_premium
except:
except Exception:
log_error("Failed to start client from USER_SESSION_STRING")
IS_PREMIUM_USER = False
user = ""
Expand Down Expand Up @@ -255,7 +255,7 @@
USENET_SERVERS = []
else:
USENET_SERVERS = eval(USENET_SERVERS)
except:
except Exception:
log_error(f"Wrong USENET_SERVERS format: {USENET_SERVERS}")
USENET_SERVERS = []

Expand Down Expand Up @@ -285,7 +285,7 @@
else:
try:
SEARCH_PLUGINS = eval(SEARCH_PLUGINS)
except:
except Exception:
log_error(f"Wrong USENET_SERVERS format: {SEARCH_PLUGINS}")
SEARCH_PLUGINS = ""

Expand Down
23 changes: 2 additions & 21 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,7 @@
from .helper.telegram_helper.button_build import ButtonMaker
from .helper.telegram_helper.filters import CustomFilters
from .helper.telegram_helper.message_utils import sendMessage, editMessage, sendFile
from .modules import (
authorize,
cancel_task,
clone,
exec,
file_selector,
gd_count,
gd_delete,
gd_search,
mirror_leech,
status,
torrent_search,
ytdlp,
rss,
shell,
users_settings,
bot_settings,
help,
force_start,
)
from .modules import authorize, cancel_task, clone, exec, file_selector, gd_count, gd_delete, gd_search, mirror_leech, status, torrent_search, ytdlp, rss, shell, users_settings, bot_settings, help, force_start # noqa: F401


async def stats(_, message):
Expand Down Expand Up @@ -245,7 +226,7 @@ async def send_incomplete_task_message(cid, msg):
await bot.edit_message_text(
chat_id=chat_id, message_id=msg_id, text="Restarted Successfully!"
)
except:
except Exception:
pass
await remove(".restartmsg")

Expand Down
42 changes: 21 additions & 21 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async def beforeStart(self):
await self.client.send_chat_action(
self.upDest, ChatAction.TYPING
)
except:
except Exception:
raise ValueError("Start the bot and try again!")
elif (self.userTransmission or self.mixedLeech) and not self.isSuperChat:
self.userTransmission = False
Expand Down Expand Up @@ -351,7 +351,7 @@ async def getTag(self, text: list):
self.userDict = user_data.get(self.userId, {})
try:
await self.message.unpin()
except:
except Exception:
pass
if self.user:
if username := self.user.username:
Expand Down Expand Up @@ -453,7 +453,7 @@ async def initBulk(self, input_list, bulk_start, bulk_end, obj):
self.multiTag,
self.options,
).newEvent()
except:
except Exception:
await sendMessage(
self.message,
"Reply to text file or to telegram message that have links seperated by new line!",
Expand Down Expand Up @@ -510,7 +510,7 @@ async def proceedExtract(self, dl_path, gid):
if code != 0:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract archive splits!. Path: {f_path}"
Expand All @@ -525,7 +525,7 @@ async def proceedExtract(self, dl_path, gid):
del_path = ospath.join(dirpath, file_)
try:
await remove(del_path)
except:
except Exception:
self.isCancelled = True
return up_path
else:
Expand Down Expand Up @@ -560,13 +560,13 @@ async def proceedExtract(self, dl_path, gid):
if not self.seed:
try:
await remove(dl_path)
except:
except Exception:
self.isCancelled = True
return up_path
else:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Unable to extract archive! Uploading anyway. Path: {dl_path}"
Expand Down Expand Up @@ -642,7 +642,7 @@ async def proceedCompress(self, dl_path, gid, o_files, ft_delete):
if await aiopath.exists(f):
try:
await remove(f)
except:
except Exception:
pass
ft_delete.clear()
return up_path
Expand All @@ -652,7 +652,7 @@ async def proceedCompress(self, dl_path, gid, o_files, ft_delete):
self.newDir = ""
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Unable to zip this path: {dl_path}")
return dl_path
Expand Down Expand Up @@ -684,13 +684,13 @@ async def proceedSplit(self, up_dir, m_size, o_files, gid):
else:
try:
await remove(f_path)
except:
except Exception:
return
continue
elif not self.seed or self.newDir:
try:
await remove(f_path)
except:
except Exception:
return
else:
m_size.append(f_size)
Expand Down Expand Up @@ -866,7 +866,7 @@ async def proceedConvert(m_path):
else:
try:
await remove(dl_path)
except:
except Exception:
pass
return output_file
else:
Expand All @@ -886,7 +886,7 @@ async def proceedConvert(m_path):
else:
try:
await remove(f_path)
except:
except Exception:
pass
if checked:
cpu_eater_lock.release()
Expand Down Expand Up @@ -930,10 +930,10 @@ async def generateScreenshots(self, dl_path):
async def substitute(self, dl_path):
if await aiopath.isfile(dl_path):
up_dir, name = dl_path.rsplit("/", 1)
for l in self.nameSub:
pattern = l[0]
res = l[1] if len(l) > 1 and l[1] else ""
sen = len(l) > 2 and l[2] == "s"
for substitution in self.nameSub:
pattern = substitution[0]
res = substitution[1] if len(substitution) > 1 and substitution[1] else ""
sen = len(substitution) > 2 and substitution[2] == "s"
new_name = sub(rf"{pattern}", res, name, flags=I if sen else 0)
new_path = ospath.join(up_dir, new_name)
await move(dl_path, new_path)
Expand All @@ -942,10 +942,10 @@ async def substitute(self, dl_path):
for dirpath, _, files in await sync_to_async(walk, dl_path, topdown=False):
for file_ in files:
f_path = ospath.join(dirpath, file_)
for l in self.nameSub:
pattern = l[0]
res = l[1] if len(l) > 1 and l[1] else ""
sen = len(l) > 2 and l[2] == "s"
for substitution in self.nameSub:
pattern = substitution[0]
res = substitution[1] if len(substitution) > 1 and substitution[1] else ""
sen = len(substitution) > 2 and substitution[2] == "s"
new_name = sub(rf"{pattern}", res, file_, flags=I if sen else 0)
await move(f_path, ospath.join(dirpath, new_name))
return dl_path
8 changes: 4 additions & 4 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async def get_content_type(url):
async with AsyncClient() as client:
response = await client.get(url, allow_redirects=True, verify=False)
return response.headers.get("Content-Type")
except:
except Exception:
return None


Expand All @@ -175,7 +175,7 @@ def update_user_ldata(id_, key, value):
async def retry_function(func, *args, **kwargs):
try:
return await func(*args, **kwargs)
except:
except Exception:
return await retry_function(func, *args, **kwargs)


Expand All @@ -187,11 +187,11 @@ async def cmd_exec(cmd, shell=False):
stdout, stderr = await proc.communicate()
try:
stdout = stdout.decode().strip()
except:
except Exception:
stdout = "Unable to decode the response!"
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
return stdout, stderr, proc.returncode

Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/files_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def clean_all():
try:
LOGGER.info("Cleaning Download Directory")
rmtree(DOWNLOAD_DIR, ignore_errors=True)
except:
except Exception:
pass
makedirs(DOWNLOAD_DIR, exist_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/jdownloader_booter.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def connectToDevice(self):
break
else:
continue
except:
except Exception:
continue
break
await self.device.enable_direct_connection()
Expand Down
16 changes: 8 additions & 8 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def convert_video(listener, video_file, ext, retry=False):
else:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Something went wrong while converting video, mostly file need specific codec. Path: {video_file}"
Expand Down Expand Up @@ -91,7 +91,7 @@ async def convert_audio(listener, audio_file, ext):
else:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Something went wrong while converting audio, mostly file need specific codec. Path: {audio_file}"
Expand Down Expand Up @@ -261,7 +261,7 @@ async def take_ss(video_file, ss_nb) -> bool:
)
await rmtree(dirpath, ignore_errors=True)
return False
except:
except Exception:
LOGGER.error(
f"Error while creating sreenshots from video. Path: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!"
)
Expand Down Expand Up @@ -330,7 +330,7 @@ async def create_thumbnail(video_file, duration):
f"Error while extracting thumbnail from video. Name: {video_file} stderr: {err}"
)
return None
except:
except Exception:
LOGGER.error(
f"Error while extracting thumbnail from video. Name: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!"
)
Expand Down Expand Up @@ -404,11 +404,11 @@ async def split_file(
elif code != 0:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
try:
await remove(out_path)
except:
except Exception:
pass
if multi_streams:
LOGGER.warning(
Expand Down Expand Up @@ -488,7 +488,7 @@ async def split_file(
elif code != 0:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(f"{stderr}. Split Document: {path}")
return True
Expand Down Expand Up @@ -556,7 +556,7 @@ async def createSampleVideo(listener, video_file, sample_duration, part_duration
else:
try:
stderr = stderr.decode().strip()
except:
except Exception:
stderr = "Unable to decode the error!"
LOGGER.error(
f"{stderr}. Something went wrong while creating sample video, mostly file is corrupted. Path: {video_file}"
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/status_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def get_readable_message(sid, is_user, page_no=1, status="All", page_step=
if hasattr(task, "seeders_num"):
try:
msg += f"\n<b>Seeders:</b> {task.seeders_num()} | <b>Leechers:</b> {task.leechers_num()}"
except:
except Exception:
pass
elif tstatus == MirrorStatus.STATUS_SEEDING:
msg += f"\n<b>Size: </b>{task.size()}"
Expand Down
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def stop_duplicate_check(listener):
elif listener.extract:
try:
name = get_base_name(name)
except:
except Exception:
name = None

if name is not None:
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/listeners/aria2_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def _onDownloadStarted(api, gid):
async def _onDownloadComplete(api, gid):
try:
download = await sync_to_async(api.get_download, gid)
except:
except Exception:
return
if download.options.follow_torrent == "false":
return
Expand Down Expand Up @@ -107,7 +107,7 @@ async def _onBtDownloadComplete(api, gid):
if not file_o.selected and await aiopath.exists(f_path):
try:
await remove(f_path)
except:
except Exception:
pass
await clean_unwanted(download.dir)
if task.listener.seed:
Expand Down Expand Up @@ -170,7 +170,7 @@ async def _onDownloadError(api, gid):
return
error = download.error_message
LOGGER.info(f"Download Error: {error}")
except:
except Exception:
pass
if task := await getTaskByGid(gid):
await task.listener.onDownloadError(error)
Expand Down
Loading

0 comments on commit acfab96

Please sign in to comment.