Skip to content

Commit

Permalink
subtitle-edit 4.0.8 and improve cleaning of empty dirs (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
double16 authored Sep 6, 2024
1 parent 48bcc68 commit 7a73b21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RUN apt-get -q update && \
find /etc/cron.*/* -type f -not -name "*logrotate*" -not -name "*anacron*" -delete &&\
rm -rf /tmp/*

RUN curl -o /tmp/se.zip -L "https://github.com/SubtitleEdit/subtitleedit/releases/download/4.0.7/SE407.zip" &&\
RUN curl -o /tmp/se.zip -L "https://github.com/SubtitleEdit/subtitleedit/releases/download/4.0.8/SE408.zip" &&\
unzip -d /usr/share/subtitle-edit /tmp/se.zip &&\
rm /tmp/se.zip &&\
curl -L -o /usr/bin/systemctl https://github.com/gdraheim/docker-systemctl-replacement/raw/${SYSTEMCTL_VER}/files/docker/systemctl3.py &&\
Expand Down
22 changes: 16 additions & 6 deletions dvrprocess/clean_orphaned_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Define the metadata extensions
metadata_extensions = [".bak.edl", ".edl", ".mkv.ini", ".comskip.ini"]
metadata_files = ['comskip.ini', '.DS_Store']

def find_orphaned_files(root_dir, dry_run=False):
# Walk through all directories and files within the root directory
Expand All @@ -33,12 +34,21 @@ def find_orphaned_files(root_dir, dry_run=False):
os.remove(orphan_file)
print(f"Removed: {orphan_file}")
# After processing files, check if the directory is empty
if not os.listdir(dirpath) and removed_files:
if dry_run:
print(f"[DRY RUN] Would remove empty directory: {dirpath}")
else:
os.rmdir(dirpath)
print(f"Removed empty directory: {dirpath}")
if removed_files:
contents = os.listdir(dirpath)
contents_to_remove = list()
for file in metadata_files:
if file in contents:
contents.remove(file)
contents_to_remove.append(file)
if not contents:
if dry_run:
print(f"[DRY RUN] Would remove empty directory: {dirpath}")
else:
for file in contents_to_remove:
os.remove(os.path.join(dirpath, file))
os.rmdir(dirpath)
print(f"Removed empty directory: {dirpath}")

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Remove orphaned metadata files.")
Expand Down

0 comments on commit 7a73b21

Please sign in to comment.