Fix bugs, Add error messages
This commit is contained in:
parent
e6917b9807
commit
140d30d767
@ -27,6 +27,13 @@ def main():
|
|||||||
chdir_to_script_dir()
|
chdir_to_script_dir()
|
||||||
mkdirs()
|
mkdirs()
|
||||||
|
|
||||||
|
dst = os.path.join(RIPPED_DIR, args.type, args.title)
|
||||||
|
if os.path.exists(dst):
|
||||||
|
print(
|
||||||
|
f"A {args.type} with this name has already been ripped. Are you sure you spelled the name right?"
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
success = rip_to_tmp_dir(args)
|
success = rip_to_tmp_dir(args)
|
||||||
program_execution_time_str = get_program_execution_time_str(program_start_time)
|
program_execution_time_str = get_program_execution_time_str(program_start_time)
|
||||||
if success:
|
if success:
|
||||||
@ -110,14 +117,11 @@ def rip_to_tmp_dir(args) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def create_rip_command(args, dest):
|
def create_rip_command(args, dest):
|
||||||
if args.type == "movie":
|
return f"dvdbackup -v -p -i '{args.dev}' -o '{dest}' -M -n \"{args.title}\""
|
||||||
return f"dvdbackup -i '{args.dev}' -o '{dest}' -F -n '{args.title}'"
|
|
||||||
else:
|
|
||||||
return f"dvdbackup -i '{args.dev}' -o '{dest}' -M -n '{args.title}'"
|
|
||||||
|
|
||||||
|
|
||||||
def get_program_execution_time_str(program_start_time):
|
def get_program_execution_time_str(program_start_time):
|
||||||
program_execution_time_minutes = (program_start_time - time.time()) / 60.0
|
program_execution_time_minutes = (time.time() - program_start_time) / 60.0
|
||||||
program_execution_time_minutes = max(0.0, program_execution_time_minutes)
|
program_execution_time_minutes = max(0.0, program_execution_time_minutes)
|
||||||
return f"{program_execution_time_minutes:.1f} minutes"
|
return f"{program_execution_time_minutes:.1f} minutes"
|
||||||
|
|
||||||
|
@ -3,13 +3,21 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
DESTINATION_FOLDER = "transcoder/raw" # pi@192.168.xxx:/home/pi/transcoder/raw
|
DESTINATION_FOLDER = (
|
||||||
|
"../transcoder/raw" # pi@192.168.xxx:/home/pi/dvd_rip/transcoder/raw
|
||||||
|
)
|
||||||
RIPPED_DIR = "ripped"
|
RIPPED_DIR = "ripped"
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
chdir_to_script_dir()
|
chdir_to_script_dir()
|
||||||
|
|
||||||
|
if not os.path.exists(DESTINATION_FOLDER):
|
||||||
|
print(
|
||||||
|
f"Destination folder '{DESTINATION_FOLDER}' does not exist. Please run transcoder script to generate it"
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
for dvd_type in ("movie", "series"):
|
for dvd_type in ("movie", "series"):
|
||||||
for dvd in list_ripped_dvds(dvd_type):
|
for dvd in list_ripped_dvds(dvd_type):
|
||||||
print(f"Transferring {dvd_type}: {dvd}")
|
print(f"Transferring {dvd_type}: {dvd}")
|
||||||
|
@ -13,10 +13,12 @@ TRANSCODED_DIR = "transcoded"
|
|||||||
LOGFILE = "transcode.log"
|
LOGFILE = "transcode.log"
|
||||||
|
|
||||||
HANDBRAKE_PROCESS_NICE_LEVEL = 10
|
HANDBRAKE_PROCESS_NICE_LEVEL = 10
|
||||||
HANDBRAKE_PRESET = "General/HQ 1080p30 Surround"
|
HANDBRAKE_PRESET_MOVIE = "General/HQ 1080p30 Surround"
|
||||||
|
HANDBRAKE_PRESET_SERIES = "General/Fast 1080p30"
|
||||||
HANDBRAKE_AUDIO_LANG_LIST = "de,en"
|
HANDBRAKE_AUDIO_LANG_LIST = "de,en"
|
||||||
OUT_VIDEO_FORMAT = ".m4v"
|
OUT_VIDEO_FORMAT = ".mkv"
|
||||||
MIN_EPISODES_DURATION_SECONDS = 10 * 60
|
MIN_EPISODES_DURATION_SECONDS = 30 * 60
|
||||||
|
MAX_EPISODES_DURATION_SECONDS = 1.5 * 60 * 60
|
||||||
|
|
||||||
SERIES_TITLE_REGEX = r"S(\d+)[ _]?E(\d+)-(\d+)$"
|
SERIES_TITLE_REGEX = r"S(\d+)[ _]?E(\d+)-(\d+)$"
|
||||||
|
|
||||||
@ -90,13 +92,17 @@ class Dvd:
|
|||||||
return (series, episodes)
|
return (series, episodes)
|
||||||
|
|
||||||
def transcode_command_args_without_title_number(self, output_file):
|
def transcode_command_args_without_title_number(self, output_file):
|
||||||
|
handbrake_preset = HANDBRAKE_PRESET_MOVIE
|
||||||
|
if self.is_series():
|
||||||
|
handbrake_preset = HANDBRAKE_PRESET_SERIES
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
"nice",
|
"nice",
|
||||||
"-n",
|
"-n",
|
||||||
str(HANDBRAKE_PROCESS_NICE_LEVEL),
|
str(HANDBRAKE_PROCESS_NICE_LEVEL),
|
||||||
"HandBrakeCLI",
|
"HandBrakeCLI",
|
||||||
"--preset",
|
"--preset",
|
||||||
HANDBRAKE_PRESET,
|
handbrake_preset,
|
||||||
"--first-audio",
|
"--first-audio",
|
||||||
"--audio-lang-list",
|
"--audio-lang-list",
|
||||||
HANDBRAKE_AUDIO_LANG_LIST,
|
HANDBRAKE_AUDIO_LANG_LIST,
|
||||||
@ -224,8 +230,8 @@ def transcode_episode(dvd: Dvd, season, episode, title_number):
|
|||||||
+ [
|
+ [
|
||||||
"--title",
|
"--title",
|
||||||
str(title_number),
|
str(title_number),
|
||||||
"--min-duration",
|
# "--min-duration",
|
||||||
str(MIN_EPISODES_DURATION_SECONDS),
|
# str(MIN_EPISODES_DURATION_SECONDS),
|
||||||
],
|
],
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
stdout=log_file,
|
stdout=log_file,
|
||||||
@ -274,10 +280,22 @@ def find_series_titles(dvd: Dvd):
|
|||||||
break
|
break
|
||||||
|
|
||||||
json_obj = json.loads(json_str)
|
json_obj = json.loads(json_str)
|
||||||
titles = list(map(lambda title: title["Index"], json_obj["TitleList"]))
|
|
||||||
|
titles = json_obj["TitleList"]
|
||||||
|
if dvd.is_series():
|
||||||
|
titles = filter(is_json_title_duration_not_too_long, titles)
|
||||||
|
titles = list(map(lambda title: title["Index"], titles))
|
||||||
return titles
|
return titles
|
||||||
|
|
||||||
|
|
||||||
|
def is_json_title_duration_not_too_long(title):
|
||||||
|
duration = title["Duration"]
|
||||||
|
duration_seconds = duration["Hours"] * 60 * 60
|
||||||
|
duration_seconds += duration["Minutes"] * 60
|
||||||
|
duration_seconds += duration["Seconds"]
|
||||||
|
return duration_seconds <= MAX_EPISODES_DURATION_SECONDS
|
||||||
|
|
||||||
|
|
||||||
def mv_videos_from_tmp_to_transcoded_dir(video_files, video_type):
|
def mv_videos_from_tmp_to_transcoded_dir(video_files, video_type):
|
||||||
for video_file in video_files:
|
for video_file in video_files:
|
||||||
src = video_file
|
src = video_file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user