Compare commits

...

5 Commits

Author SHA1 Message Date
b5b2f580fa Add possibility to use --all-audio 2024-03-19 14:56:18 +01:00
13c7bde679 Change file modes 2023-10-06 16:08:45 +02:00
5790b9134e Add timeout error handling 2023-10-06 16:02:16 +02:00
a7bc9c6257 Modify rsync arguments 2023-10-06 15:53:41 +02:00
7306e018a6 Add transcode timeout 2023-10-06 15:53:09 +02:00
12 changed files with 50 additions and 29 deletions

3
.env.sample Normal file → Executable file
View File

@@ -8,7 +8,8 @@ TRANSFER_DESTINATION_FOLDER="../transcoder/raw"
HANDBRAKE_PROCESS_NICE_LEVEL=10 HANDBRAKE_PROCESS_NICE_LEVEL=10
HANDBRAKE_PRESET_MOVIE="General/HQ 1080p30 Surround" HANDBRAKE_PRESET_MOVIE="General/HQ 1080p30 Surround"
HANDBRAKE_PRESET_SERIES="General/HQ 1080p30 Surround" HANDBRAKE_PRESET_SERIES="General/HQ 1080p30 Surround"
HANDBRAKE_AUDIO_LANG_LIST="de,en" HANDBRAKE_AUDIO_LANG_LIST="de,en" # Leave empty to get all audio tracks
OUT_VIDEO_FORMAT=".mkv" OUT_VIDEO_FORMAT=".mkv"
MIN_EPISODES_DURATION_MINUTES=30 MIN_EPISODES_DURATION_MINUTES=30
MAX_EPISODES_DURATION_MINUTES=90 MAX_EPISODES_DURATION_MINUTES=90
TRANSCODE_TIMEOUT_MINUTES=120

0
.envrc Normal file → Executable file
View File

0
.gitignore vendored Normal file → Executable file
View File

0
COPYING Normal file → Executable file
View File

0
Readme.org Normal file → Executable file
View File

0
flake.lock generated Normal file → Executable file
View File

0
flake.nix Normal file → Executable file
View File

0
requirements.txt Normal file → Executable file
View File

0
ripper/bell.oga Normal file → Executable file
View File

View File

@@ -107,8 +107,7 @@ def transfer_ripped_dvd(ripped_dvd, destination_folder):
subprocess.run( subprocess.run(
[ [
"rsync", "rsync",
"-az", "-rzP",
"-e ssh",
"--remove-source-files", "--remove-source-files",
ripped_dvd, ripped_dvd,
destination_folder, destination_folder,

View File

@@ -37,6 +37,7 @@ HANDBRAKE_AUDIO_LANG_LIST = os.environ["HANDBRAKE_AUDIO_LANG_LIST"]
OUT_VIDEO_FORMAT = os.environ["OUT_VIDEO_FORMAT"] OUT_VIDEO_FORMAT = os.environ["OUT_VIDEO_FORMAT"]
MIN_EPISODES_DURATION_SECONDS = int(os.environ["MIN_EPISODES_DURATION_MINUTES"]) * 60 MIN_EPISODES_DURATION_SECONDS = int(os.environ["MIN_EPISODES_DURATION_MINUTES"]) * 60
MAX_EPISODES_DURATION_SECONDS = int(os.environ["MAX_EPISODES_DURATION_MINUTES"]) * 60 MAX_EPISODES_DURATION_SECONDS = int(os.environ["MAX_EPISODES_DURATION_MINUTES"]) * 60
TRANSCODE_TIMEOUT_SECONDS = int(os.environ["TRANSCODE_TIMEOUT_MINUTES"]) * 60
SERIES_TITLE_REGEX = r"S(\d+)[ _]?E(\d+)(-(\d+))?$" SERIES_TITLE_REGEX = r"S(\d+)[ _]?E(\d+)(-(\d+))?$"
@@ -131,15 +132,21 @@ class Dvd:
"HandBrakeCLI", "HandBrakeCLI",
"--preset", "--preset",
handbrake_preset, handbrake_preset,
"--audio-lang-list",
HANDBRAKE_AUDIO_LANG_LIST,
"--first-audio",
"--input", "--input",
self.dvd_path, self.dvd_path,
"--output", "--output",
output_file, output_file,
] ]
if HANDBRAKE_AUDIO_LANG_LIST.strip() == "":
args += ["--all-audio"]
else:
args += [
"--audio-lang-list",
HANDBRAKE_AUDIO_LANG_LIST,
"--first-audio"]
if os.path.exists(self.nodvdnav_file): if os.path.exists(self.nodvdnav_file):
args += ["--no-dvdnav"] args += ["--no-dvdnav"]
self.append_line_to_logfile( self.append_line_to_logfile(
@@ -278,12 +285,19 @@ def transcode_episode(dvd: Dvd, season, episode, title_number):
# Returns success # Returns success
def run_and_log_handbrake(dvd: Dvd, command) -> bool: def run_and_log_handbrake(dvd: Dvd, command) -> bool:
with open(dvd.log_file, "a") as log_file: with open(dvd.log_file, "a") as log_file:
proc = subprocess.run( try:
command, proc = subprocess.run(
stderr=subprocess.STDOUT, command,
stdout=log_file, stderr=subprocess.STDOUT,
) stdout=log_file,
if proc.returncode != 0: timeout=TRANSCODE_TIMEOUT_SECONDS,
)
if proc.returncode != 0:
return False
except subprocess.TimeoutExpired:
log_file.write(
f"Transcoding timeout of {TRANSCODE_TIMEOUT_SECONDS}s reached!"
)
return False return False
if check_handbrake_log_for_error(dvd): if check_handbrake_log_for_error(dvd):
@@ -307,23 +321,30 @@ def find_series_titles(dvd: Dvd):
return read_titles_from_titles_file(dvd) return read_titles_from_titles_file(dvd)
with open(dvd.log_file, "w") as log_file: with open(dvd.log_file, "w") as log_file:
proc = subprocess.run( try:
[ proc = subprocess.run(
"nice", [
"-n", "nice",
str(HANDBRAKE_PROCESS_NICE_LEVEL), "-n",
"HandBrakeCLI", str(HANDBRAKE_PROCESS_NICE_LEVEL),
"--input", "HandBrakeCLI",
dvd.dvd_path, "--input",
"-t", dvd.dvd_path,
"0", "-t",
"--min-duration", "0",
str(MIN_EPISODES_DURATION_SECONDS), "--min-duration",
"--json", str(MIN_EPISODES_DURATION_SECONDS),
], "--json",
stdout=subprocess.PIPE, ],
stderr=log_file, stdout=subprocess.PIPE,
) stderr=log_file,
timeout=TRANSCODE_TIMEOUT_SECONDS,
)
except subprocess.TimeoutExpired:
log_file.write(
f"Transcoding timeout of {TRANSCODE_TIMEOUT_SECONDS}s reached!"
)
return None
if proc.returncode != 0: if proc.returncode != 0:
return None return None

0
transcoder/video_transcoder.service.sample Normal file → Executable file
View File