8 Commits

Author SHA1 Message Date
Derek Christensen
42845b8265 Changed default hb_args to match old hardcoded arguments 2017-01-10 23:27:33 -08:00
Derek Christensen
07080fdd9b disable sc2086 2017-01-10 23:21:39 -08:00
Derek Christensen
cf48fec50f Added HB_ARGS for user configurable HandBrake arguments 2017-01-10 23:17:07 -08:00
Derek Christensen
cc408285c5 fixed video_title declaration 2016-12-29 09:51:31 -08:00
Derek Christensen
cff56120ba Fixed VIDEO_TYPE assignment 2016-12-29 09:29:58 -08:00
Derek Christensen
660aa152da Uncomment ripping call 2016-12-28 21:04:10 -08:00
Derek Christensen
9e6a2899f5 Try to handle incorrect year coming from metaservices 2016-12-28 20:54:00 -08:00
muckngrind4
32ebce8d89 Move files to media directory for "all files" on bluray (#32)
* Added Emby processes to more scenarios
* Comment editiing
* Fix mv command
* Disable some shecllcheck errors
2016-12-20 19:20:55 -08:00
4 changed files with 149 additions and 35 deletions

View File

@@ -11,7 +11,7 @@ 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 our final output
# 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
@@ -76,6 +76,9 @@ HANDBRAKE_CLI=HandBrakeCLI
# 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
# Additional HandBrake arguments.
HB_ARGS="--subtitle scan -F"
#####################
## Emby Parameters ##
#####################
@@ -85,6 +88,9 @@ MAINFEATURE=false
# 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=""

View File

@@ -19,6 +19,7 @@ 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)]
@@ -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)

View File

@@ -70,7 +70,18 @@ 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

View File

@@ -36,12 +36,16 @@ TIMESTAMP=$5
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"
# shellcheck disable=SC2086
$HANDBRAKE_CLI -i "$SRC" -o "$DEST/$LABEL.$DEST_EXT" --main-feature --preset="$HB_PRESET" $HB_ARGS 2>> "$LOG"
rmdir "$SRC"
elif [ "$RIPMETHOD" = "backup" ] && [ "$MAINFEATURE" = false ] && [ "$ID_CDROM_MEDIA_BD" = "1" ]; then
echo "Transcoding BluRay all titles above minlength." >> "$LOG"
# Itterate through titles of MakeMKV backup
# First get number of titles
# 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"
@@ -55,7 +59,14 @@ TIMESTAMP=$5
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"
# shellcheck disable=SC2086
$HANDBRAKE_CLI -i "$SRC" -o "$DEST/$LABEL-$TITLE.$DEST_EXT" --min-duration="$MINLENGTH" -t "$TITLE" --preset="$HB_PRESET" $HB_ARGS 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
@@ -64,7 +75,8 @@ TIMESTAMP=$5
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"
# shellcheck disable=SC2086
$HANDBRAKE_CLI -i "$DEVNAME" -o "${DEST}/${LABEL}.${DEST_EXT}" --main-feature --preset="${HB_PRESET}" $HB_ARGS 2>> "$LOG"
eject "$DEVNAME"
else
echo "Transcoding all files." >> "$LOG"
@@ -77,14 +89,33 @@ TIMESTAMP=$5
filename=${filename%.*}
echo "Transcoding file $FILE" >> "$LOG"
$HANDBRAKE_CLI -i "$SRC/$FILE" -o "$DEST/$filename.$DEST_EXT" --preset="$HB_PRESET" --subtitle scan -F 2>> "$LOG"
# shellcheck disable=SC2086
$HANDBRAKE_CLI -i "$SRC/$FILE" -o "$DEST/$filename.$DEST_EXT" --preset="$HB_PRESET" $HB_ARGS 2>> "$LOG"
rm "$SRC/$FILE"
done
rmdir "$SRC"
fi
if [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = true ] && [ "$HAS_NICE_TITLE" = true ]; then
# move the file to the final media directory
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"
@@ -92,25 +123,68 @@ TIMESTAMP=$5
if [ "$EMBY_REFRESH" = true ]; then
# signal emby to scan library
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
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"