5 Commits

Author SHA1 Message Date
Derek Christensen
03df92dded better logging message 2017-01-12 17:03:16 -08:00
Derek Christensen
62a11d6a9a fix spacing error 2017-01-10 23:46:01 -08:00
Derek Christensen
8a32a28019 removed unneeded xml file 2017-01-10 23:43:11 -08:00
Derek Christensen
b9c6beb58c Additional TV handling 2017-01-10 23:05:17 -08:00
Derek Christensen
48d6768d38 Handle TV series 2017-01-02 12:47:57 -08:00
4 changed files with 162 additions and 9 deletions

123
arm/tv_dvd.py Executable file
View File

@@ -0,0 +1,123 @@
#!/usr/bin/python3
import sys
import argparse
import os
# import re
import subprocess
import logging
import pprint
import time
def entry():
""" Entry to program, parses arguments"""
parser = argparse.ArgumentParser(description='Get type of dvd--movie or tv series')
parser.add_argument('-d', '--devpath', help='Devpath', required=True)
parser.add_argument('-m', '--minlength', help='Minimum Length', default=0, type=int)
parser.add_argument('-x', '--maxlength', help='Maximum Length', default=0, type=int)
parser.add_argument('-a', '--armpath', help='ArmPath', required=True)
parser.add_argument('-r', '--rawpath', help='Rawpath', required=True)
parser.add_argument('-e', '--label', help='Label', required=True)
parser.add_argument('-b', '--handbrakecli', help='HandbrakeCLI', default="HandBrakeCLI")
parser.add_argument('-p', '--hb_preset', help='Handbrake Preset', required=True)
parser.add_argument('-g', '--hb_args', help='Handbrake Arguements', default='')
parser.add_argument('-l', '--logfile', help='Logfile (path/logname)', required=True)
return parser.parse_args()
def log_params():
"""log all entry parameters"""
logging.info("Logging tv_dvd parameters")
logging.info("**** Start tv_dvd.py paramaters *** ")
logging.info("devpath: " + args.devpath)
logging.info("minlength: " + str(args.minlength))
logging.info("maxlength: " + str(args.maxlength))
logging.info("armpath: " + args.armpath)
logging.info("rawpath: " + args.rawpath)
logging.info("handbrakecli: " + args.handbrakecli)
logging.info("hb_preset: " + args.hb_preset)
logging.info("logfile: " + args.logfile)
logging.info("hb_args: " + args.hb_args)
logging.info("*** End of tv_dvd.py parameters ***")
def main():
"""main tv processing function"""
logging.info("Starting TV_DVD processing")
try:
d = subprocess.check_output(["lsdvd", '-Oy', args.devpath]).decode("utf-8")
except subprocess.CalledProcessError as derror:
print("Call to lsdvd failed with code: " + str(derror.returncode), derror.output)
err = "Aborting. Call to lsdvd failed with code: " + str(derror.returncode), derror.output
sys.exit(err)
data = d.replace("lsdvd = ", "", 1)
info = eval(data, {})
# print(info['track'])
#get filesystem in order
ts = round(time.time() * 100)
basepath = os.path.join(args.armpath, args.label + "_" + str(ts))
if not os.path.exists(basepath):
try:
os.makedirs(basepath)
except:
logging.error("Couldn't create the base file path: " + basepath + " Probably a permissions error")
err = "Couldn't create the base file path: " + basepath + " Probably a permissions error"
sys.exit(err)
total = 0
for index, item in enumerate(info['track']):
if item['ix'] > total:
total = item['ix']
logging.info("Found " + str(total) + " tracks.")
for index, item in enumerate(info['track']):
if item['length'] < args.minlength:
#too short
logging.info("Track #" + str(item['ix']) + " of " + str(total) + ". Length (" + str(item['length']) + \
") is less than minimum length (" + str(args.minlength) + "). Skipping")
elif item['length'] > args.maxlength:
#too long
logging.info("Track #" + str(item['ix']) +" of " + str(total) + ". Length (" + str(item['length']) + \
") is greater than maximum length (" + str(args.maxlength) + "). Skipping")
else:
#just right
logging.info("Processing track #" + str(item['ix']) + " of " + str(total) + ". Length is " + str(item['length']) + " seconds.")
filename = os.path.join(basepath, "title_" + str(item['ix']) + ".mkv")
cmd = 'nice {0} -i "{1}" -o "{2}" --preset "{3}" -t {4} {5}>> {6}'.format(
args.handbrakecli,
args.devpath,
filename,
args.hb_preset,
str(item['ix']),
args.hb_args,
args.logfile
)
logging.debug("Sending command: %s", (cmd))
try:
hb = subprocess.check_output(
cmd,
shell=True
).decode("utf-8")
except subprocess.CalledProcessError as hb_error:
err = "Call to hadnbrake failed with code: " + str(hb_error.returncode) + "(" + str(hb_error.output) + ")"
logging.error(err)
sys.exit(err)
args = entry()
#set up logging
logging.basicConfig(filename=args.logfile, format='[%(asctime)s] ARM: %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', \
level=logging.INFO)
log_params()
main()

View File

@@ -16,6 +16,9 @@ GET_VIDEO_TITLE=true
# Note: RIPMETHOD must be set to "mkv" for this feature to work
SKIP_TRANSCODE=false
# Default Video Type. Use this to give ARM a way to handle dvds/bds that aren't identifiable.
# DEFAULT_VIDEOTYPE="series"
#####################
## Directory setup ##
#####################
@@ -46,6 +49,9 @@ LOGLIFE=1
# Minimum length of track for MakeMKV rip (in seconds)
MINLENGTH="600"
# Maximum length of track for MakeMKV rip (in seconds). Set to 0 to disable
MAXLENGTH="0"
# Method of MakeMKV to use for Blu Ray discs. Options are "mkv" or "backup".
# mkv is the normal method of ripping mkv files directly from the DVD
# backup decrypts the dvd and then copies it to the hard drive. This allows HandBrake to apply some of it's
@@ -54,6 +60,11 @@ MINLENGTH="600"
# DVD's will always default back to the "mkv" mode. If this is set to "backup" then you must also set HandBrake's MAINFEATURE to true.
RIPMETHOD="mkv"
# Additional HandBrake arguments. '--subtitle scan -F --subtitle-burned' will scan for forced foreign language
# audio and burn them into the video
# HB_ARGS="--subtitle scan -F --subtitle-burned"
HB_ARGS="--subtitle scan -F --subtitle-burned"
##########################
## HandBrake Parameters ##
##########################

View File

@@ -26,7 +26,7 @@ def getdvdtype():
except:
year = ""
else:
year = re.sub('[()]','', year)
year = re.sub('[()]', '', year)
try:
dvd_title = dvd_title[0:(dvd_title.rindex('('))].strip()
@@ -49,22 +49,22 @@ def getdvdtype():
dvd_type = callwebservice(dvd_title_clean, "")
# print (dvd_type)
if (dvd_type != "fail"):
#that means the year is wrong.
if dvd_type != "fail":
#that means the year is wrong.
needs_new_year = "true"
if (dvd_type == "fail"):
if dvd_type == "fail":
# second see if there is a hyphen and split it
if (dvd_title.find("-") > -1):
if dvd_title.find("-") > -1:
dvd_title_slice = dvd_title[:dvd_title.find("-")]
dvd_title_slice =cleanupstring(dvd_title_slice)
dvd_title_slice = cleanupstring(dvd_title_slice)
dvd_type = callwebservice(dvd_title_slice)
# if still fail, then try slicing off the last word in a loop
while dvd_type == "fail" and dvd_title_clean.count('+') > 0:
dvd_title_clean = dvd_title_clean.rsplit('+', 1)[0]
dvd_type = callwebservice(dvd_title_clean)
if needs_new_year == "true":
#pass the new year back to bash to handle
global new_year

View File

@@ -84,6 +84,7 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
fi
else
VIDEO_TYPE="unknown"
fi
echo "got to here"
@@ -92,7 +93,24 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
echo "video type is ${VIDEO_TYPE}"
umount "/mnt/$DEVNAME"
/opt/arm/video_rip.sh "$VIDEO_TITLE" "$HAS_NICE_TITLE" "$VIDEO_TYPE" "$LOG"
if [ $VIDEO_TYPE = "series" ] && [ "$ID_CDROM_MEDIA_DVD" = "1" ]; then
echo "Processing TV series. Calling tv_dvd.py" >> "$LOG"
STR="/opt/arm/arm/tv_dvd.py -d "\"${DEVNAME}\"" -m ${MINLENGTH} -x ${MAXLENGTH} -a "\"${ARMPATH}\"" -r "\"${RAWPATH}\"" -e "\"${ID_FS_LABEL}\"" -b "\"${HANDBRAKE_CLI}\"" -p "\"${HB_PRESET}\"" -g "\"${HB_ARGS}\"" -l "\"${LOG}\"""
echo "Sending command ${STR}"
eval "${STR}" 2>> "$LOG"
eject "$DEVNAME"
elif
[ "$VIDEO_TYPE" = "unknown" ] && [ "$DEFAULT_VIDEOTYPE" == "series" ] && [ "$ID_CDROM_MEDIA_DVD" = "1" ]; then
echo "Video type is 'unknown' and default video type is series. Processing TV series. Calling tv_dvd.py" >> "$LOG"
STR="/opt/arm/arm/tv_dvd.py -d "\"${DEVNAME}\"" -m ${MINLENGTH} -x ${MAXLENGTH} -a "\"${ARMPATH}\"" -r "\"${RAWPATH}\"" -e "\"${ID_FS_LABEL}\"" -b "\"${HANDBRAKE_CLI}\"" -p "\"${HB_PRESET}\"" -g "\"${HB_ARGS}\"" -l "\"${LOG}\"""
echo "Sending command ${STR}"
eval "${STR}" 2>> "$LOG"
eject "$DEVNAME"
else
echo "Sending to video_rip queue" >> "$LOG"
/opt/arm/video_rip.sh "$VIDEO_TITLE" "$HAS_NICE_TITLE" "$VIDEO_TYPE" "$LOG"
fi
else
umount "/mnt/$DEVNAME"
echo "identified udf as data" >> "$LOG"
@@ -102,6 +120,7 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
fi
else
echo "ARM_CHECK_UDF is false, assuming udf is video" >> "$LOG"
/opt/arm/video_rip.sh "$LOG"
fi