Compare commits
16 Commits
v1.3.0
...
tvhandling
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03df92dded | ||
|
|
62a11d6a9a | ||
|
|
8a32a28019 | ||
|
|
b9c6beb58c | ||
|
|
48d6768d38 | ||
|
|
cc408285c5 | ||
|
|
cff56120ba | ||
|
|
660aa152da | ||
|
|
9e6a2899f5 | ||
|
|
32ebce8d89 | ||
|
|
40bfb99eff | ||
|
|
6dedbf2f72 | ||
|
|
e70bf17a70 | ||
|
|
1478264a00 | ||
|
|
ffcfb2220d | ||
|
|
7a5cfb5306 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ test.sh
|
||||
archive/
|
||||
config
|
||||
temp/
|
||||
test.py
|
||||
|
||||
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()
|
||||
124
config.sample
Normal file → Executable file
124
config.sample
Normal file → Executable file
@@ -11,92 +11,142 @@ ARM_CHECK_UDF=true
|
||||
# For BluRays attempts to extract the title from an XML file on the disc
|
||||
GET_VIDEO_TITLE=true
|
||||
|
||||
# Skip transcoding if you want the original MakeMKV files as your final output
|
||||
# Thiw will produce the highest quality videos (and use the most storage)
|
||||
# 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 ##
|
||||
#####################
|
||||
|
||||
#Base directory of ARM media directory
|
||||
#Ripped and transcoded files end up here
|
||||
# Base directory of ARM media directory
|
||||
# Ripped and transcoded files end up here
|
||||
ARMPATH="/mnt/media/ARM/"
|
||||
|
||||
#Path to raw MakeMKV directory
|
||||
#Destination for MakeMKV and source for HandBrake
|
||||
# Path to raw MakeMKV directory
|
||||
# Destination for MakeMKV and source for HandBrake
|
||||
RAWPATH="/mnt/media/ARM/raw/"
|
||||
|
||||
#Path to final media directory
|
||||
#Destination for final file. Only used for movies that are positively identified
|
||||
# Path to final media directory
|
||||
# Destination for final file. Only used for movies that are positively identified
|
||||
MEDIA_DIR="/mnt/media/ARM/emby/movies/"
|
||||
|
||||
#Path to directory to hold log files
|
||||
#Make sure to include trailing /
|
||||
# Path to directory to hold log files
|
||||
# Make sure to include trailing /
|
||||
LOGPATH="/opt/arm/logs/"
|
||||
|
||||
#How long to let log files live before deleting (in days)
|
||||
# How long to let log files live before deleting (in days)
|
||||
LOGLIFE=1
|
||||
|
||||
########################
|
||||
## MakeMKV Parameters ##
|
||||
########################
|
||||
|
||||
#Minimum length of track for MakeMKV rip (in seconds)
|
||||
# Minimum length of track for MakeMKV rip (in seconds)
|
||||
MINLENGTH="600"
|
||||
|
||||
#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
|
||||
#analytical abilities such as the main-feature identification. This method seems to offer success on bluray
|
||||
#discs that fail in "mkv" mode. *** NOTE: MakeMKV only supports the backup method on BluRay discs. Regular
|
||||
#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.
|
||||
# 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
|
||||
# analytical abilities such as the main-feature identification. This method seems to offer success on bluray
|
||||
# discs that fail in "mkv" mode. *** NOTE: MakeMKV only supports the backup method on BluRay discs. Regular
|
||||
# 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 ##
|
||||
##########################
|
||||
|
||||
# Handbrake preset profile
|
||||
# See https://trac.handbrake.fr/wiki/BuiltInPresets
|
||||
# Execute "HandBrakeCLI -z" to see a list of all presets
|
||||
HB_PRESET="High Profile"
|
||||
|
||||
#Extension of the final video file
|
||||
# Extension of the final video file
|
||||
DEST_EXT=mkv
|
||||
|
||||
#Handbrake binary to call
|
||||
# Handbrake binary to call
|
||||
HANDBRAKE_CLI=HandBrakeCLI
|
||||
|
||||
#Have HandBrake transcode the main feature only. BluRay discs must have RIPMETHOD="backup" for this to work.
|
||||
#If MAINFEATURE is true, blurays will be backed up to the HD and then HandBrake will go to work on the backed up
|
||||
#files. For normal DVDs, ARM will by pass MakeMKV and be accessed directly by HandBrake. This will require
|
||||
#libdvdcss2 be installed.
|
||||
#NOTE: For the most part, HandBrake correctly identifies the main feature on movie DVD's, although it is not perfect.
|
||||
#However, it does not handle tv shows well at all. You will likely want this value to be false when ripping tv shows.
|
||||
#MAINFEATURE=false
|
||||
# Have HandBrake transcode the main feature only. BluRay discs must have RIPMETHOD="backup" for this to work.
|
||||
# If MAINFEATURE is true, blurays will be backed up to the HD and then HandBrake will go to work on the backed up
|
||||
# files. For normal DVDs, ARM will bypass MakeMKV and hand off the dvd directly to HandBrake. This will require
|
||||
# libdvdcss2 be installed.
|
||||
# NOTE: For the most part, HandBrake correctly identifies the main feature on movie DVD's, although it is not perfect.
|
||||
# However, it does not handle tv shows well at all. You will likely want this value to be false when ripping tv shows.
|
||||
MAINFEATURE=false
|
||||
|
||||
#####################
|
||||
## Emby Parameters ##
|
||||
#####################
|
||||
|
||||
# Parameters to enable automatic library scan in Emby. This will trigger only if MainFeature is true above.
|
||||
|
||||
# Scan emby library after succesful placement of mainfeature (see above)
|
||||
EMBY_REFRESH=false
|
||||
|
||||
# Use subfolders in Emby as described here: https://github.com/MediaBrowser/Wiki/wiki/Movie%20naming#movie-extras
|
||||
EMBY_SUBFOLDERS=true
|
||||
|
||||
# Server parameters
|
||||
# Server can be ip address or domain name
|
||||
EMBY_SERVER=""
|
||||
EMBY_PORT="8096"
|
||||
|
||||
# Emby authentication fluff parameters. These can be anything.
|
||||
EMBY_CLIENT="ARM"
|
||||
EMBY_DEVICE="ARM"
|
||||
EMBY_DEVICEID="ARM"
|
||||
|
||||
# Emby authentication parameters. These are parameters that must be set to a current user in Emby.
|
||||
EMBY_USERNAME=""
|
||||
|
||||
# EMBY_USERID is the user ID associated with the username above. You can find this by going to the following address on your emby server
|
||||
# <server>:<port>/Users/Public and getting the ID value for the username above.
|
||||
EMBY_USERID=""
|
||||
|
||||
# This is the SHA1 encrypted password for the username above. You can generate the SHA1 hash of your password by executing the following at
|
||||
# the command line:
|
||||
# echo -n your-password | sha1sum | awk '{print $1}'
|
||||
# or using an online generator like the one located at http://www.sha1-online.com/
|
||||
EMBY_PASSWORD=""
|
||||
|
||||
#############################
|
||||
## Notification Parameters ##
|
||||
#############################
|
||||
|
||||
#Pushbullet API Key
|
||||
#Leave empty or comment out to disable Pushbullet notifications
|
||||
# Pushbullet API Key
|
||||
# Leave empty or comment out to disable Pushbullet notifications
|
||||
PB_KEY=""
|
||||
|
||||
#IFTTT API KEY
|
||||
#Leave empty or comment out to disable IFTTT notifications
|
||||
#IFTTT_KEY=""
|
||||
# IFTTT API KEY
|
||||
# Leave empty or comment out to disable IFTTT notifications
|
||||
# IFTTT_KEY=""
|
||||
|
||||
#IFTTT Event Name
|
||||
# IFTTT Event Name
|
||||
IFTTT_EVENT="arm_event"
|
||||
|
||||
#Determine logfile name
|
||||
#use the label of the DVD/CD or else use empty.log
|
||||
#this is required for udev events where there is no media available
|
||||
#such as ejecting the drive
|
||||
# Determine logfile name
|
||||
# use the label of the DVD/CD or else use empty.log
|
||||
# this is required for udev events where there is no media available
|
||||
# such as ejecting the drive
|
||||
if [ -z "$ID_FS_LABEL" ]; then
|
||||
LOGFILE="empty.log"
|
||||
else
|
||||
LOGFILE=${ID_FS_LABEL}".log"
|
||||
fi
|
||||
|
||||
#Set full logfile path
|
||||
# Set full logfile path
|
||||
LOG=$LOGPATH$LOGFILE
|
||||
|
||||
|
||||
@@ -19,36 +19,83 @@ 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"
|
||||
|
||||
year = dvd_title[(dvd_title.rindex('(')):len(dvd_title)]
|
||||
year = re.sub('[()]','', year)
|
||||
try:
|
||||
year = dvd_title[(dvd_title.rindex('(')):len(dvd_title)]
|
||||
except:
|
||||
year = ""
|
||||
else:
|
||||
year = re.sub('[()]', '', year)
|
||||
|
||||
dvd_title = dvd_title[0:(dvd_title.rindex('('))].strip()
|
||||
dvd_title = cleanupstring(dvd_title)
|
||||
try:
|
||||
dvd_title = dvd_title[0:(dvd_title.rindex('('))].strip()
|
||||
except:
|
||||
dvd_title_clean = cleanupstring(dvd_title)
|
||||
else:
|
||||
dvd_title_clean = cleanupstring(dvd_title)
|
||||
|
||||
if year is None:
|
||||
year = ""
|
||||
|
||||
dvd_title_info_json = urllib.request.urlopen("http://www.omdbapi.com/?t={0}&y={1}&plot=short&r=json".format(dvd_title, year)).read()
|
||||
doc = json.loads(dvd_title_info_json.decode())
|
||||
|
||||
return doc['Type']
|
||||
dvd_type = callwebservice(dvd_title_clean, year)
|
||||
# print (dvd_type)
|
||||
|
||||
# handle failures
|
||||
# this is kind of kludgy, but it kind of work...
|
||||
if (dvd_type == "fail"):
|
||||
|
||||
# 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
|
||||
string = string.strip()
|
||||
return re.sub('[_ ]',"+",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:
|
||||
return "fail"
|
||||
else:
|
||||
doc = json.loads(dvd_title_info_json.decode())
|
||||
if doc['Response'] == "False":
|
||||
return "fail"
|
||||
else:
|
||||
global new_year
|
||||
new_year = doc['Year']
|
||||
return doc['Type']
|
||||
|
||||
args = entry()
|
||||
|
||||
|
||||
try:
|
||||
dvd_type = getdvdtype()
|
||||
except:
|
||||
print("fail")
|
||||
else:
|
||||
# we only want "movie" or "series"
|
||||
if dvd_type == "movie" or dvd_type == "series":
|
||||
print(dvd_type)
|
||||
else:
|
||||
print("other")
|
||||
dvd_type = getdvdtype()
|
||||
print(dvd_type)
|
||||
42
identify.sh
42
identify.sh
@@ -13,6 +13,14 @@ mkdir -p "$LOGPATH"
|
||||
|
||||
#shellcheck disable=SC2094
|
||||
{
|
||||
# echo all config parameters to logfile
|
||||
# excludes sensative parameters
|
||||
# shellcheck disable=SC2129
|
||||
echo "*** Start config parameters ****" >> "$LOG"
|
||||
# shellcheck disable=SC2002
|
||||
cat "$ARM_CONFIG"|sed '/^[#;].*$/d;/^$/d;/if/d;/^ /d;/^else/d;/^fi/d;/KEY=/d;/PASSWORD/d' >> "$LOG"
|
||||
echo "*** End config parameters ****" >> "$LOG"
|
||||
|
||||
echo "Starting Identify Script..." >> "$LOG"
|
||||
|
||||
VIDEO_TITLE=""
|
||||
@@ -62,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"
|
||||
@@ -73,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"
|
||||
@@ -83,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
|
||||
|
||||
|
||||
@@ -30,20 +30,50 @@ TIMESTAMP=$5
|
||||
|
||||
# DEST="${ARMPATH}/${LABEL}_${TIMESTAMP}"
|
||||
mkdir "$DEST"
|
||||
if [ "$RIPMETHOD" = "backup" ] && [ "$MAINFEATURE" = true ] && [ "$ID_CDROM_MEDIA_BD" = "1" ]; then
|
||||
if [ "$SKIP_TRANSCODE" = true ] && [ "$RIPMETHOD" = "mkv" ]; then
|
||||
# this only works for files ripped by MakeMKV into .mkv files
|
||||
echo "Skipping transcode. Moving files from $SRC to $DEST" >> "$LOG"
|
||||
mv "$SRC"/* "$DEST"/ >> "$LOG"
|
||||
elif [ "$RIPMETHOD" = "backup" ] && [ "$MAINFEATURE" = true ] && [ "$ID_CDROM_MEDIA_BD" = "1" ]; then
|
||||
echo "Transcoding BluRay main feature only." >> "$LOG"
|
||||
$HANDBRAKE_CLI -i "$SRC" -o "$DEST/$LABEL.$DEST_EXT" --main-feature --preset="$HB_PRESET" --subtitle scan -F 2>> "$LOG"
|
||||
rmdir "$SRC"
|
||||
elif [ "$RIPMETHOD" = "backup" ] && [ "$MAINFEATURE" = false ] && [ "$ID_CDROM_MEDIA_BD" = "1" ]; then
|
||||
echo "Transcoding BluRay all titles above minlength." >> "$LOG"
|
||||
# This fails, need to figure out how to iterate through all fetures on a backup source
|
||||
$HANDBRAKE_CLI -i "$SRC" -o "$DEST/$LABEL.$DEST_EXT" --min-duration "$MINLENGTH" --preset="$HB_PRESET" --subtitle scan -F 2>> "$LOG"
|
||||
rmdir "$SRC"
|
||||
# Itterate through titles of MakeMKV backup
|
||||
# First check if this is the main title
|
||||
MAINTITLENO="$(echo ""|HandBrakeCLI --input "$SRC" --title 0 --scan |& grep -B 1 "Main Feature" | sed 's/[^0-9]*//g')"
|
||||
|
||||
# Get number of titles
|
||||
TITLES="$(echo ""|HandBrakeCLI --input "$SRC" --scan |& grep -Po '(?<=scan: BD has )([0-9]+)')"
|
||||
echo "$TITLES titles on BluRay Disc" >> "$LOG"
|
||||
|
||||
for TITLE in $(seq 1 "$TITLES")
|
||||
do
|
||||
echo "Processing title $TITLE" >> "$LOG"
|
||||
|
||||
TIME="$(echo ""|HandBrakeCLI --input "$SRC" --title "$TITLE" --scan |& grep 'duration is' | sed -r 's/.*\((.*)ms\)/\1/')"
|
||||
|
||||
SEC=$(( TIME / 1000 )) >> "$LOG"
|
||||
echo "Title length is $SEC seconds." >> "$LOG"
|
||||
if [ $SEC -gt "$MINLENGTH" ]; then
|
||||
echo "HandBraking title $TITLE"
|
||||
$HANDBRAKE_CLI -i "$SRC" -o "$DEST/$LABEL-$TITLE.$DEST_EXT" --min-duration="$MINLENGTH" -t "$TITLE" --preset="$HB_PRESET" --subtitle scan -F 2 >> "$LOG"
|
||||
|
||||
# Check for main title and rename
|
||||
if [ "$MAINTITLENO" = "$TITLE" ] && [ "$HAS_NICE_TITLE" = true ]; then
|
||||
echo "Sending the following command: mv -n \"$DEST/$LABEL-$TITLE.$DEST_EXT\" \"${DEST}/${LABEL}.${DEST_EXT}\"" >> "$LOG"
|
||||
mv -n "$DEST/$LABEL-$TITLE.$DEST_EXT" "${DEST}/${LABEL}.${DEST_EXT}" >> "$LOG"
|
||||
fi
|
||||
else
|
||||
echo "Title $TITLE lenth less than $MINLENGTH. Skipping." >> "$LOG"
|
||||
fi
|
||||
done
|
||||
rm -rf "$SRC"
|
||||
elif [ "$MAINFEATURE" = true ] && [ "$ID_CDROM_MEDIA_DVD" = "1" ]; then
|
||||
echo "Transcoding DVD main feature only." >> "$LOG"
|
||||
# echo "$HANDBRAKE_CLI -i $DEVNAME -o \"${DEST}/${LABEL}.${DEST_EXT}\" --main-feature --preset="${HB_PRESET}" --subtitle scan -F 2" >> $LOG
|
||||
$HANDBRAKE_CLI -i "$DEVNAME" -o "${DEST}/${LABEL}.${DEST_EXT}" --main-feature --preset="${HB_PRESET}" --subtitle scan -F 2>> "$LOG"
|
||||
# $HANDBRAKE_CLI -i $DEVNAME -o "${DEST}/${LABEL}.${DEST_EXT}" --main-feature --preset="${HB_PRESET}">> $LOG
|
||||
eject "$DEVNAME"
|
||||
else
|
||||
echo "Transcoding all files." >> "$LOG"
|
||||
@@ -62,16 +92,95 @@ TIMESTAMP=$5
|
||||
rmdir "$SRC"
|
||||
fi
|
||||
|
||||
if [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = true ] && [ "$HAS_NICE_TITLE" = true ]; then
|
||||
echo "checing for existing file" >> "$LOG"
|
||||
embyrefresh ()
|
||||
{
|
||||
ApiKey="$(curl -s -H "Authorization: MediaBrowser Client=\"$EMBY_CLIENT\", Device=\"$EMBY_DEVICE\", DeviceId=\"$EMBY_DEVICEID\", Version=1.0.0.0, UserId=\"$EMBY_USERID\"" -d "username=$EMBY_USERNAME" -d "password=$EMBY_PASSWORD" "http://$EMBY_SERVER:$EMBY_PORT/users/authenticatebyname?format=json" | python -m json.tool | grep 'AccessToken' | sed 's/\"//g; s/AccessToken://g; s/\,//g; s/ //g')"
|
||||
|
||||
RESPONSE=$(curl -d 'Library' "http://$EMBY_SERVER:$EMBY_PORT/Library/Refresh?api_key=$ApiKey")
|
||||
|
||||
if [ ${#RESPONSE} = 0 ]; then
|
||||
# scan was successful
|
||||
echo "Emby refresh command sent successfully" >> "$LOG"
|
||||
else
|
||||
# scan failed
|
||||
echo "Emby refresh command failed for some reason. Probably authentication issues" >> "$LOG"
|
||||
fi
|
||||
}
|
||||
|
||||
if [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = true ] && [ "$HAS_NICE_TITLE" = true ] && [ "$EMBY_SUBFOLDERS" = false ]; then
|
||||
# move the file to the final media directory
|
||||
# shellcheck disable=SC2129,SC2016
|
||||
echo '$VIDEO_TYPE is movie, $MAINFEATURE is true, $HAS_NICE_TITLE is true, $EMBY_SUBFOLDERS is false' >> "$LOG"
|
||||
echo "Moving a single file." >> "$LOG"
|
||||
echo "Checing for existing file..." >> "$LOG"
|
||||
if [ ! -f "$MEDIA_DIR/$LABEL.$DEST_EXT" ]; then
|
||||
echo "No file found. Moving \"$DEST/$LABEL.$DEST_EXT to $MEDIA_DIR/$LABEL.$DEST_EXT\"" >> "$LOG"
|
||||
mv -n "$DEST/$LABEL.$DEST_EXT" "$MEDIA_DIR/$LABEL.$DEST_EXT"
|
||||
|
||||
if [ "$EMBY_REFRESH" = true ]; then
|
||||
# signal emby to scan library
|
||||
embyrefresh
|
||||
else
|
||||
echo "Emby Refresh False. Skipping library scan" >> "$LOG"
|
||||
fi
|
||||
else
|
||||
echo "Warning: $MEDIA_DIR/$LABEL.$DEST_EXT File exists! File moving aborted" >> "$LOG"
|
||||
fi
|
||||
else
|
||||
echo "Nothing here..." >> "$LOG"
|
||||
elif [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = true ] && [ "$HAS_NICE_TITLE" = true ] && [ "$EMBY_SUBFOLDERS" = true ]; then
|
||||
# shellcheck disable=SC2129,SC2016
|
||||
echo '$VIDEO_TYPE is movie, $MAINFEATURE is true, $HAS_NICE_TITLE is true, $EMBY_SUBFOLDERS is true' >> "$LOG"
|
||||
echo "Moving a single file to emby subfolders" >> "$LOG"
|
||||
mkdir "$MEDIA_DIR/$LABEL" >> "$LOG"
|
||||
if [ ! -f "$MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT" ]; then
|
||||
echo "No file found. Moving \"$DEST/$LABEL.$DEST_EXT to $MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT\"" >> "$LOG"
|
||||
mv -n "$DEST/$LABEL.$DEST_EXT" "$MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT"
|
||||
|
||||
if [ "$EMBY_REFRESH" = true ]; then
|
||||
# signal emby to scan library
|
||||
embyrefresh
|
||||
else
|
||||
echo "Emby Refresh False. Skipping library scan" >> "$LOG"
|
||||
fi
|
||||
else
|
||||
echo "Warning: $MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT File exists! File moving aborted" >> "$LOG"
|
||||
fi
|
||||
elif [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = false ] && [ "$HAS_NICE_TITLE" = true ] && [ "$EMBY_SUBFOLDERS" = false ]; then
|
||||
# shellcheck disable=SC2129,SC2016
|
||||
echo '$VIDEO_TYPE is movie, $MAINFEATURE is false, $HAS_NICE_TITLE is true, $EMBY_SUBFOLDERS is false' >> "$LOG"
|
||||
# hopefully this is never happen because it will cause a lot of duplicate files
|
||||
echo "***WARNING!*** This will likely leave files in the transcoding directory as there is very likely existing files in the media directory"
|
||||
echo "Moving multiple files to emby movie folder" >> "$LOG"
|
||||
mv -n "$DEST/$LABEL.$DEST_EXT" "$MEDIA_DIR/$LABEL.$DEST_EXT"
|
||||
if [ "$EMBY_REFRESH" = true ]; then
|
||||
# signal emby to scan library
|
||||
embyrefresh
|
||||
else
|
||||
echo "Emby Refresh False. Skipping library scan" >> "$LOG"
|
||||
fi
|
||||
elif [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = false ] && [ "$HAS_NICE_TITLE" = true ] && [ "$EMBY_SUBFOLDERS" = true ]; then
|
||||
# shellcheck disable=SC2129,SC2016
|
||||
echo '$VIDEO_TYPE is movie, $MAINFEATURE is false, $HAS_NICE_TITLE is true, $EMBY_SUBFOLDERS is true' >> "$LOG"
|
||||
echo "Moving multiple files to emby movie subfolders" >> "$LOG"
|
||||
echo "First move main title" >> "$LOG"
|
||||
mkdir -v "$MEDIA_DIR/$LABEL" >> "$LOG"
|
||||
if [ ! -f "$MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT" ]; then
|
||||
echo "No file found. Moving \"$DEST/$LABEL.$DEST_EXT to $MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT\"" >> "$LOG"
|
||||
mv -n "$DEST/$LABEL.$DEST_EXT" "$MEDIA_DIR/$LABEL/$LABEL.$DEST_EXT" >> "$LOG"
|
||||
fi
|
||||
|
||||
#now move "extras"
|
||||
# shellcheck disable=SC2129,SC2016
|
||||
mkdir -v "$MEDIA_DIR/$LABEL/extras" >> "$LOG"
|
||||
# shellcheck disable=SC2086
|
||||
echo "Sending command: mv -n "\"$DEST/$LABEL/*\"" "\"$MEDIA_DIR/$LABEL/extras/\""" >> "$LOG"
|
||||
mv -n "${DEST}"/* "$MEDIA_DIR/$LABEL/extras/" >> "$LOG"
|
||||
if [ "$EMBY_REFRESH" = true ]; then
|
||||
# signal emby to scan library
|
||||
embyrefresh
|
||||
else
|
||||
echo "Emby Refresh False. Skipping library scan" >> "$LOG"
|
||||
fi
|
||||
rmdir "$DEST"
|
||||
fi
|
||||
|
||||
rmdir "$SRC"
|
||||
|
||||
Reference in New Issue
Block a user