Change error log handling

This commit is contained in:
Julian Mutter 2022-08-18 17:30:27 +02:00
parent f4f394f21b
commit 3f6fcf2248
2 changed files with 20 additions and 4 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
rip.log
ripped/
tmp/
/transcoder/raw/
/transcoder/transcode.log

22
transcoder/transcode_dvd.py Normal file → Executable file
View File

@ -21,15 +21,20 @@ def main():
mkdirs()
for dvd_type in ("movie", "series"):
for dvd in filter(is_dvd_files_not_locked, list_ripped_dvds(dvd_type)):
print(f"Transcoding {dvd_type} {dvd}")
# TOOD: nice transcoding process so it does not block server
success = transcode_ripped_dvd(dvd, dvd_type)
dvd_title = "" # TODO
dvd_title = os.path.basename(dvd)
if success:
mv_video_from_tmp_to_transcoded_dir(dvd_title, dvd_type)
write_to_logfile(dvd_type, dvd_title, "Success")
delete_original_video_files(dvd)
delete_transcoding_logfile(dvd)
print("Success")
else:
write_to_logfile(dvd_type, dvd_title, "FAILURE")
err_log_file = dvd + ".err.log"
print(f"Failed. Please see logs at {err_log_file}")
delete_tmp_dir()
@ -52,6 +57,7 @@ def list_ripped_dvds(dvd_type):
dvd_titles = os.listdir(path)
dvd_titles = filter(lambda title: not title.endswith(".lock"), dvd_titles)
dvd_titles = filter(lambda title: not title.endswith(".err.log"), dvd_titles)
dvd_titles = filter(lambda title: not title.endswith(".log"), dvd_titles)
return map(lambda dvd_title: os.path.join(path, dvd_title), dvd_titles)
except FileNotFoundError:
print(
@ -61,7 +67,11 @@ def list_ripped_dvds(dvd_type):
def is_dvd_files_not_locked(dvd):
return not os.path.exists(dvd + ".lock") and not os.path.exists(dvd + ".err.log")
return (
not os.path.exists(dvd + ".lock")
and not os.path.exists(dvd + ".err.log")
and not os.path.exists(dvd + ".log")
)
def transcode_ripped_dvd(ripped_dvd, dvd_type):
@ -74,7 +84,7 @@ def transcode_ripped_dvd(ripped_dvd, dvd_type):
def transcode_movie(movie):
video_file_name = os.path.basename(movie) + OUT_VIDEO_FORMAT
output_file = os.path.join(TMP_DIR, video_file_name)
log_file_path = movie + ".err.log"
log_file_path = movie + ".log"
with open(log_file_path, "w") as log_file:
@ -122,7 +132,11 @@ def write_to_logfile(dvd_type, dvd_title, tag):
def delete_transcoding_logfile(dvd):
os.remove(dvd + "err.log")
os.remove(dvd + ".log")
def rename_transcoding_logfile_as_error_log(dvd):
shutil.move(dvd + ".log", dvd + ".err.log")
def delete_original_video_files(folder):