Browse Source

enable multithreading support by building a command list and iterating over it in parallel with thread amount configurable in ini

master
Constantin Fürst 2 years ago
parent
commit
e9fa0aac21
  1. 20
      libconv.py
  2. 1
      quality-flac.ini
  3. 1
      small-mp3.ini

20
libconv.py

@ -7,6 +7,7 @@ import subprocess
import sys
import re
from joblib import Parallel, delayed
from configparser import ConfigParser
from copy import deepcopy
from pathlib import Path
@ -27,12 +28,15 @@ DRY_RUN: bool = config.get("libconv", "dry_run") != "false"
DEDUCE_METADATA: bool = config.get("libconv", "deduce_metadata") == "true"
FFMPEG_LOCATION: str = config.get("ffmpeg", "location")
FFMPEG_OPTS: str = config.get("ffmpeg", "options")
THREADS: int = int(config.get("libconv", "threads"))
if DST_OVERWRITE:
FFMPEG_OPTS += " -y"
logging.basicConfig(level=logging.INFO)
cmd_list: List[str] = []
# ----------------------------------------------------------------- #
# file and folder operations
@ -49,7 +53,7 @@ def mkdir(path: str):
def execute(command: str):
logging.debug(f"execute: {command}")
if not DRY_RUN:
os.system(command)
cmd_list.append(command)
# ----------------------------------------------------------------- #
# cue sheet processing
@ -210,6 +214,18 @@ def process_folder(path: str):
logging.info("scanning subfolders")
scan_folder(path)
def execute_command_list():
logging.info(f"Executing all {len(cmd_list)} commands with {THREADS} parallel threads")
if DRY_RUN:
logging.info("Skipping execution as we are dry-running. Printing list as debug-info.")
logging.debug(str(cmd_list))
return
Parallel(n_jobs=THREADS)(
delayed(os.system)(cmd) for cmd in cmd_list
)
if __name__ == "__main__":
logging.info(f"Using settings from {CONFIG_FILE}")
@ -219,3 +235,5 @@ if __name__ == "__main__":
logging.info("Overwrite of existing files active")
process_folder(SRC_FOLDER)
execute_command_list()

1
quality-flac.ini

@ -11,4 +11,5 @@ location = ffmpeg
[libconv]
overwrite = false
dry_run = true
threads = 6

1
small-mp3.ini

@ -12,4 +12,5 @@ location = ffmpeg
overwrite = true
dry_run = false
deduce_metadata = true
threads = 6
Loading…
Cancel
Save