4 Commits

Author SHA1 Message Date
Derek Christensen
aef3c4062d Disable some shecllcheck errors 2016-12-19 00:22:41 -08:00
Derek Christensen
950b6463c2 Fix mv command 2016-12-19 00:08:59 -08:00
Derek Christensen
31fdda8dbe Comment editiing 2016-12-17 23:49:57 -08:00
Derek Christensen
4a54544eb2 Added Emby processes to more scenarios 2016-12-17 23:25:01 -08:00
4 changed files with 16 additions and 203 deletions

View File

@@ -1,123 +0,0 @@
#!/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,9 +16,6 @@ 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 ##
#####################
@@ -49,9 +46,6 @@ 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
@@ -60,11 +54,6 @@ MAXLENGTH="0"
# 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

@@ -19,14 +19,13 @@ def getdvdtype():
""" Queries OMDbapi.org for title information and parses if it's a movie
or a tv series """
dvd_title = args.title
needs_new_year = "false"
try:
year = dvd_title[(dvd_title.rindex('(')):len(dvd_title)]
except:
year = ""
else:
year = re.sub('[()]', '', year)
year = re.sub('[()]','', year)
try:
dvd_title = dvd_title[0:(dvd_title.rindex('('))].strip()
@@ -38,39 +37,21 @@ def getdvdtype():
if year is None:
year = ""
dvd_type = callwebservice(dvd_title_clean, year)
# print (dvd_type)
dvd_type = callwebservice(dvd_title, year)
# handle failures
# this is kind of kludgy, but it kind of work...
if (dvd_type == "fail"):
# first see if there is a hyphen and split it
if (dvd_title.find("-") > -1):
dvd_title_slice = dvd_title[:dvd_title.find("-")]
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)
# first try submitting without the year
dvd_type = callwebservice(dvd_title_clean, "")
# print (dvd_type)
if dvd_type != "fail":
#that means the year is wrong.
needs_new_year = "true"
if dvd_type == "fail":
# second see if there is a hyphen and split it
if dvd_title.find("-") > -1:
dvd_title_slice = dvd_title[:dvd_title.find("-")]
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
return dvd_type + "#" + new_year
else:
return dvd_type
return dvd_type
def cleanupstring(string):
# clean up title string to pass to OMDbapi.org
@@ -80,8 +61,6 @@ def cleanupstring(string):
def callwebservice(dvd_title, year=""):
""" Queries OMDbapi.org for title information and parses if it's a movie
or a tv series """
# print (dvd_title)
try:
dvd_title_info_json = urllib.request.urlopen("http://www.omdbapi.com/?t={0}&y={1}&plot=short&r=json".format(dvd_title, year)).read()
except:
@@ -91,11 +70,9 @@ def callwebservice(dvd_title, year=""):
if doc['Response'] == "False":
return "fail"
else:
global new_year
new_year = doc['Year']
return doc['Type']
args = entry()
dvd_type = getdvdtype()
print(dvd_type)
print(dvd_type)

View File

@@ -70,21 +70,9 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
fi
if [ $HAS_NICE_TITLE == true ]; then
VTYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1)
#handle year mismath if found
if [[ $VTYPE =~ .*#.* ]]; then
VIDEO_TYPE=$(echo "$VTYPE" | cut -f1 -d#)
NEW_YEAR=$(echo "$VTYPE" | cut -f2 -d#)
echo "VIDEO_TYPE is $VIDEO_TYPE and NEW_YEAR is $NEW_YEAR"
VIDEO_TITLE="$(echo "$VIDEO_TITLE" | cut -f1 -d\()($NEW_YEAR)"
echo "Year mismatch found. New video title is $VIDEO_TITLE"
else
VIDEO_TYPE="$VTYPE"
fi
VIDEO_TYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1)
else
VIDEO_TYPE="unknown"
fi
echo "got to here"
@@ -93,24 +81,7 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
echo "video type is ${VIDEO_TYPE}"
umount "/mnt/$DEVNAME"
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
/opt/arm/video_rip.sh "$VIDEO_TITLE" "$HAS_NICE_TITLE" "$VIDEO_TYPE" "$LOG"
else
umount "/mnt/$DEVNAME"
echo "identified udf as data" >> "$LOG"
@@ -120,7 +91,6 @@ 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