Compare commits
9 Commits
bugfix-noa
...
tvhandling
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03df92dded | ||
|
|
62a11d6a9a | ||
|
|
8a32a28019 | ||
|
|
b9c6beb58c | ||
|
|
48d6768d38 | ||
|
|
cc408285c5 | ||
|
|
cff56120ba | ||
|
|
660aa152da | ||
|
|
9e6a2899f5 |
123
arm/tv_dvd.py
Executable file
123
arm/tv_dvd.py
Executable 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()
|
||||
@@ -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 ##
|
||||
##########################
|
||||
|
||||
@@ -19,13 +19,14 @@ 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()
|
||||
@@ -37,21 +38,39 @@ def getdvdtype():
|
||||
if year is None:
|
||||
year = ""
|
||||
|
||||
dvd_type = callwebservice(dvd_title, year)
|
||||
dvd_type = callwebservice(dvd_title_clean, year)
|
||||
# print (dvd_type)
|
||||
|
||||
# handle failures
|
||||
# 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)
|
||||
# this is kind of kludgy, but it kind of work...
|
||||
if (dvd_type == "fail"):
|
||||
|
||||
return dvd_type
|
||||
# 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
|
||||
|
||||
def cleanupstring(string):
|
||||
# clean up title string to pass to OMDbapi.org
|
||||
@@ -61,6 +80,8 @@ 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:
|
||||
@@ -70,9 +91,11 @@ 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)
|
||||
34
identify.sh
34
identify.sh
@@ -70,9 +70,21 @@ if [ "$ID_FS_TYPE" == "udf" ]; then
|
||||
fi
|
||||
|
||||
if [ $HAS_NICE_TITLE == true ]; then
|
||||
VIDEO_TYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1)
|
||||
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
|
||||
else
|
||||
VIDEO_TYPE="unknown"
|
||||
|
||||
fi
|
||||
|
||||
echo "got to here"
|
||||
@@ -81,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"
|
||||
@@ -91,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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user