Skip to content

Commit

Permalink
trying to fix, metadata for folder
Browse files Browse the repository at this point in the history
  • Loading branch information
5hojib committed Jan 6, 2025
1 parent 3f56f7c commit da078cb
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions bot/helper/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,47 +1337,48 @@ async def proceed_ffmpeg(self, dl_path, gid):

async def proceed_metadata(self, dl_path, gid):
key = self.metadata
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(self, gid, "Metadata")
checked = False

async def _process_directory(directory, key):
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):
cmd, temp_file = await get_metadata_cmd(file_path, key)
if not cmd:
return ""
if not checked:
await cpu_eater_lock.acquire()
if self.isCancelled:
cpu_eater_lock.release()
return ""
self.subsize = await aiopath.getsize(file_path)
self.subname = file_
await run_ffmpeg_cmd(self, cmd)
self.subproc = None
os.replace(temp_file, file_path)
return None

if self.is_file:
if is_mkv(dl_path):
if is_mkv(dl_path):
cmd, temp_file = await get_metadata_cmd(dl_path, key)
if cmd:
checked = True
await cpu_eater_lock.acquire()
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(self, gid, "Metadata")
await cpu_eater_lock.acquire()
self.subsize = self.size
await run_ffmpeg_cmd(self, cmd)
self.subproc = None
os.replace(temp_file, dl_path)
else:
await _process_directory(dl_path, key)

for dirpath, _, files in await sync_to_async(
walk,
dl_path,
topdown=False,
):
for file_ in files:
file_path = ospath.join(dirpath, file_)
if self.is_cancelled:
cpu_eater_lock.release()
return ""
if is_mkv(file_path):
cmd, temp_file = await get_metadata_cmd(file_path, key)
if cmd:
if not checked:
checked = True
async with task_dict_lock:
task_dict[self.mid] = FFmpegStatus(
self,
gid,
"Metadata",
)
await cpu_eater_lock.acquire()
LOGGER.info(f"Running metadata cmd for: {file_path}")
self.subsize = await aiopath.getsize(file_path)
self.subname = file_
await run_ffmpeg_cmd(self, cmd)
self.suproc = None
if checked:
cpu_eater_lock.release()
return dl_path
return dl_path

0 comments on commit da078cb

Please sign in to comment.