Skip to content

Commit

Permalink
Auto-format code [skip actions]
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 1, 2025
1 parent 6ca8906 commit f6b1d54
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions bot/core/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Config:
USE_SERVICE_ACCOUNTS = False
WEB_PINCODE = False
YT_DLP_OPTIONS = ""

# INKYPINKY
METADATA_KEY = ""
SET_COMMANDS = True
Expand All @@ -65,7 +65,7 @@ class Config:
PAID_CHANNEL_LINK = ""
DELETE_LINKS = False
FSUB_IDS = ""

@classmethod
def get(cls, key):
if hasattr(cls, key):
Expand Down
6 changes: 4 additions & 2 deletions bot/helper/aeon_utils/metadata_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ async def get_streams(file):
try:
return json.loads(stdout)["streams"]
except KeyError:
LOGGER.error(f"No streams found in the ffprobe output: {stdout.decode().strip()}")
LOGGER.error(
f"No streams found in the ffprobe output: {stdout.decode().strip()}"
)
return None


Expand Down Expand Up @@ -182,4 +184,4 @@ async def add_attachment(file, attachment_path):

os.replace(temp_file, file)
LOGGER.info(f"Photo attachment added successfully to file: {file}")
return
return
32 changes: 18 additions & 14 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from bot.core.aeon_client import TgClient
from bot.core.config_manager import Config
from bot.helper.aeon_utils.metadata_editor import get_streams

from .ext_utils.bot_utils import get_size_bytes, new_task, sync_to_async
from .ext_utils.bulk_links import extract_bulk_links
Expand All @@ -47,14 +48,12 @@
create_sample_video,
create_thumb,
get_document_type,
is_mkv,
run_ffmpeg_cmd,
run_metadata_cmd,
split_file,
take_ss,
is_mkv,
)
from bot.helper.aeon_utils.metadata_editor import change_metadata, get_streams

from .mirror_leech_utils.gdrive_utils.list import GoogleDriveList
from .mirror_leech_utils.rclone_utils.list import RcloneList
from .mirror_leech_utils.status_utils.ffmpeg_status import FFmpegStatus
Expand Down Expand Up @@ -211,7 +210,8 @@ async def before_start(self):
if self.ffmpeg_cmds and not isinstance(self.ffmpeg_cmds, list):
if self.user_dict.get("ffmpeg_cmds", None):
self.ffmpeg_cmds = self.user_dict["ffmpeg_cmds"].get(
self.ffmpeg_cmds, None
self.ffmpeg_cmds,
None,
)
elif "ffmpeg_cmds" not in self.user_dict and Config.FFMPEG_CMDS:
self.ffmpeg_cmds = Config.FFMPEG_CMDS.get(self.ffmpeg_cmds, None)
Expand Down Expand Up @@ -801,7 +801,9 @@ async def proceed_compress(self, dl_path, gid, o_files, ft_delete):
return ""
async with self.subprocess_lock:
self.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await self.subproc.wait()
if self.is_cancelled:
Expand Down Expand Up @@ -1373,7 +1375,7 @@ async def process_file(file_path, key):
[
f"-metadata:s:v:{stream_index}",
f"language={languages[stream_index]}",
]
],
)
elif stream_type == "audio":
cmd.extend(
Expand All @@ -1382,21 +1384,21 @@ async def process_file(file_path, key):
f"0:{stream_index}",
f"-metadata:s:a:{audio_index}",
f"title={key}",
]
],
)
if stream_index in languages:
cmd.extend(
[
f"-metadata:s:a:{audio_index}",
f"language={languages[stream_index]}",
]
],
)
audio_index += 1
elif stream_type == "subtitle":
codec_name = stream.get("codec_name", "unknown")
if codec_name in ["webvtt", "unknown"]:
LOGGER.warning(
f"Skipping unsupported subtitle metadata modification: {codec_name} for stream {stream_index}"
f"Skipping unsupported subtitle metadata modification: {codec_name} for stream {stream_index}",
)
else:
cmd.extend(
Expand All @@ -1405,14 +1407,14 @@ async def process_file(file_path, key):
f"0:{stream_index}",
f"-metadata:s:s:{subtitle_index}",
f"title={key}",
]
],
)
if stream_index in languages:
cmd.extend(
[
f"-metadata:s:s:{subtitle_index}",
f"language={languages[stream_index]}",
]
],
)
subtitle_index += 1
else:
Expand All @@ -1423,7 +1425,9 @@ async def process_file(file_path, key):

async def process_directory(directory, key):
"""Processes all MKV files in a directory."""
for dirpath, _, files in await sync_to_async(walk, directory, topdown=False):
for dirpath, _, files in await sync_to_async(
walk, directory, topdown=False
):
for file_ in files:
file_path = ospath.join(dirpath, file_)
if is_mkv(file_path):
Expand All @@ -1437,7 +1441,7 @@ async def process_directory(directory, key):
return ""
await run_metadata_cmd(self, cmd)
os.replace(temp_file, file_path)
return None

if self.is_file:
if is_mkv(up_dir):
Expand All @@ -1453,4 +1457,4 @@ async def process_directory(directory, key):

if checked:
cpu_eater_lock.release()
return up_dir
return up_dir
31 changes: 21 additions & 10 deletions bot/helper/ext_utils/media_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ async def convert_video(listener, video_file, ext, retry=False):
return False
async with listener.subprocess_lock:
listener.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await listener.subproc.wait()
async with listener.subprocess_lock:
Expand Down Expand Up @@ -115,7 +117,9 @@ async def convert_audio(listener, audio_file, ext):
return False
async with listener.subprocess_lock:
listener.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await listener.subproc.wait()
async with listener.subprocess_lock:
Expand Down Expand Up @@ -649,7 +653,9 @@ async def create_sample_video(listener, video_file, sample_duration, part_durati
return False
async with listener.subprocess_lock:
listener.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await listener.subproc.wait()
async with listener.subprocess_lock:
Expand Down Expand Up @@ -784,7 +790,9 @@ async def run_ffmpeg_cmd(listener, cmd, path):
return False
async with listener.subprocess_lock:
listener.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await listener.subproc.wait()
async with listener.subprocess_lock:
Expand All @@ -808,24 +816,26 @@ async def run_ffmpeg_cmd(listener, cmd, path):


async def run_metadata_cmd(listener, cmd):
#base_name, ext = ospath.splitext(path)
#dir, base_name = base_name.rsplit("/", 1)
#output_file = cmd[-1]
#if output_file != "mltb" and output_file.startswith("mltb"):
# base_name, ext = ospath.splitext(path)
# dir, base_name = base_name.rsplit("/", 1)
# output_file = cmd[-1]
# if output_file != "mltb" and output_file.startswith("mltb"):
# oext = ospath.splitext(output_file)[-1]
# if ext == oext:
# base_name = f"ffmpeg.{base_name}"
# else:
# ext = oext
#else:
# else:
# base_name = f"ffmpeg.{base_name}"
# output = f"{dir}/{base_name}{ext}"
# cmd[-1] = output
if listener.is_cancelled:
return False
async with listener.subprocess_lock:
listener.subproc = await create_subprocess_exec(
*cmd, stdout=PIPE, stderr=PIPE
*cmd,
stdout=PIPE,
stderr=PIPE,
)
code = await listener.subproc.wait()
async with listener.subprocess_lock:
Expand All @@ -847,5 +857,6 @@ async def run_metadata_cmd(listener, cmd):
# await remove(output)
return False


def is_mkv(file):
return file.lower().endswith(".mkv")

0 comments on commit f6b1d54

Please sign in to comment.