18 Commits

Author SHA1 Message Date
Benjamin Bryan
b0be50c291 default ripmethod to mkv (#23) 2016-12-03 21:54:36 -08:00
Benjamin Bryan
7264409de4 fix rmdir command (#21) 2016-12-03 20:32:05 -08:00
Benjamin Bryan
56ab1c8c99 libdvdcss requirement (#20) 2016-12-03 20:31:53 -08:00
Benjamin Bryan
5cffb7a527 fix version (#19) 2016-12-03 15:35:00 -08:00
Benjamin Bryan
575e0e36b4 Makemkv readme (#18)
Note on installing MakeMKV license
2016-12-02 20:51:05 -08:00
Benjamin Bryan
032b461e84 Python requirements (#17)
Python Requirements
Changelog
Readme
Change GET_VIDEO_TITLE to true in config sample
2016-12-02 20:40:30 -08:00
Benjamin Bryan
8a4318885a Clean bash (#16)
Clean up bash for shellcheck
2016-11-30 20:57:37 -08:00
Benjamin Bryan
698cae773a Autofilename (#15)
* Implemented call to OMDbapi.org to identify if the dvd is a movie or tv series.  If a movie, automaticlaly
the transcoded video to the final media directory.

* Added MEDIA_DIR parameter to config file.  Cleaned up comments.

* Some calls to the service return extra characters in the title such as [P&S] (pan and scan) and
[WS] (widescreen).  Added code to clean these to the clean_for_filename function.

* Added call to getvideotyp.py.

* Added code to auto move transcoded file to media directory.  Addition of double quotes to account for spaces
in filenames.
2016-11-28 20:21:13 -08:00
Benjamin Bryan
1c4ddb9a87 More merge fixes (#14)
* cleanup after my horrible merge
2016-11-25 19:55:07 -08:00
Benjamin Bryan
4105c5bb85 Update readme (#12)
* add ci

* add ci

* add build status

* update readme
2016-11-23 23:19:39 -08:00
Benjamin Bryan
2bd9ef3375 Update readme md (#13)
* add ci

* add ci

* add build status

* update readme
2016-11-23 23:19:27 -08:00
Benjamin Bryan
88d9e83c1c Squashed commit of the following:
commit 3651c39b1f8eab5c51248f84eee7d2ee749b122c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 23:06:31 2016 -0800

    update readme

commit 2bd873123b14da69a4df94aa2751c107c2d89d0c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 22:46:14 2016 -0800

    add build status

commit 1b60de53a6f0d889f970f42b701d0c0e4f7c7d6b
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 22:33:40 2016 -0800

    add ci

commit 4a669745a3b7a8c31cba8d644bd46ec87d9b20ba
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 22:33:12 2016 -0800

    add ci

# Conflicts:
#	README.md
2016-11-23 23:18:57 -08:00
Benjamin Bryan
9898c33818 Continuous Integration (#11)
* add ci

* add ci

* add build status
2016-11-23 22:49:40 -08:00
Benjamin Bryan
d52d872665 quotes and move mkdir up (#10)
Fix merge errors

* I'm terrible at merging...
2016-11-23 22:31:23 -08:00
Benjamin Bryan
5e8b35fc17 Squashed commit of the following:
commit 2986b3cfdc487f71aa7808501da0196c93679596
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 21:53:22 2016 -0800

    merge changes

commit c2a5d54f2edbe16ebb4df67c62cce97b2f1e3c4c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 21:18:43 2016 -0800

    fix bad var

commit a96af91a2ab0d8c87dd3dc06466203c7efdf2cef
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 21:05:00 2016 -0800

    logging comment

commit 4e2ce38520dee4221bf99070083b740a07947115
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 21:04:00 2016 -0800

    add timestamp in raw folder

commit bb4f003fc44a117edadb178594ffbadd20edc81c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 20:49:22 2016 -0800

    check to see if title exists, if so no timestamp

commit 1cbea6a4df7993f4d6cdc2714b9689e2666e2fc7
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 20:01:32 2016 -0800

    open in binary mode

commit 8362d893af625043e6e0429c68065efddc9dd46c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Wed Nov 23 20:00:54 2016 -0800

    quote path

commit 9ff73d21e2f24238fb8de83ccc2def9c64612dca
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 22:42:33 2016 -0800

    esc quotes

commit c55ce810f6f9c7a4b3276e0dc801bd51d0f172a4
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 22:40:27 2016 -0800

    debug

commit 6b9eecba196a4a80e234ebf5fb1c1106986a5f4a
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 22:19:23 2016 -0800

    this probably shouldn't be different

commit 6ca6b73636703ce06d6f0088ad77dddc7443fef6
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 22:15:56 2016 -0800

    spaces....

commit 9eda76899194d9a49168926195d85319ac8991a5
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 21:54:40 2016 -0800

    quotes

commit 39a658582d12a1fbe61c69b1ad9be30591facfe0
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 21:36:03 2016 -0800

    more debugging

commit 9593c43cc28330876d63530127f650bdeb3cb0de
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 21:30:16 2016 -0800

    cleanup string

commit 5caf6e7c19be47aa9bd0ead476680296305a6cd0
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 21:01:19 2016 -0800

    debug

commit 42faee7ff9cbf3ac23eda55b37cd1d986e9ceff4
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 20:56:39 2016 -0800

    spaces

commit d04a114e7e509538b3aff660a380a72b5c1bc88f
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 20:50:27 2016 -0800

    video title

commit cdb955f8af9d330e2b61494c41c5378929153684
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 20:25:00 2016 -0800

    fix bash errors

commit 7b36271630b15175b9d3bee2a145f9ce7d01f766
Author: Benjamin Bryan <ben@b3n.org>
Date:   Tue Nov 22 20:05:12 2016 -0800

    fix transcoding call

commit f674c812fc417f217fc5c46102b499371cf622df
Merge: c428b57 462e766
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 22:54:15 2016 -0800

    Merge branch 'identifydvdbluraytitle' of github.com:ahnooie/automatic-ripping-machine into identifydvdbluraytitle

commit c428b57d66f1ef4d55d36677fb23f30e71a1cfc6
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 22:53:59 2016 -0800

    force python3 for now

commit 462e766c6fbf2d962eeb922c83285f4e8528939d
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 22:53:41 2016 -0800

    fix path

commit 797f32bf500ac62af0ab928001b543cd5ec891d0
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 22:39:11 2016 -0800

    param devname

commit 91f90d707cb01671da9fffe9e3a740ae6e783d26
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 22:38:29 2016 -0800

    get video title

commit 51cdb4085980669ae46b41378f579c434165d32e
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 21:45:36 2016 -0800

    fix bluray replace and fix type error for python3

commit 3e214abe2ec72e497d97ed896de3f307dc83d3e6
Author: Benjamin Bryan <ben@b3n.org>
Date:   Mon Nov 21 21:19:59 2016 -0800

    Rip option using backup method in MakeMKV and main-feature in HandBrake (#6) (#8)

    * Add ability to rip using backup method in MakeMKV and main-feature in Handbrake
    * Added logic for when backup method is selected but all files wanted.

commit f3a9da4e0ae07cf6a123cbe9f9b05d607005164c
Author: Benjamin Bryan <ben@b3n.org>
Date:   Sun Nov 20 07:49:55 2016 -0800

    desc

commit f2a423d4eb7c39eae206086a6612816eaa714213
Author: Benjamin Bryan <ben@b3n.org>
Date:   Sun Nov 20 07:48:44 2016 -0800

    clean up

commit 5466d33e24cd82d3d608eb63779b4a8fed1b221f
Author: Benjamin Bryan <ben@b3n.org>
Date:   Sat Nov 19 21:27:43 2016 -0800

    added bluray

commit dd06df5dde9f90dee67399fff6592e530180e6fd
Author: Benjamin Bryan <ben@b3n.org>
Date:   Sat Nov 19 19:45:19 2016 -0800

    parse xml

commit 91fb6fc68f1faea19690b56090b40b5ed3e9e3ca
Author: Benjamin Bryan <ben@b3n.org>
Date:   Sat Nov 19 19:00:32 2016 -0800

    get crc64 of dvd

# Conflicts:
#	video_rip.sh
#	video_transcode.sh
2016-11-23 22:03:28 -08:00
muckngrind4
4c57df2672 Rip option using backup method in MakeMKV and main-feature in HandBrake (#6)
* Add ability to rip using backup method in MakeMKV and main-feature in Handbrake
* Added logic for when backup method is selected but all files wanted.
2016-11-21 21:12:16 -08:00
Benjamin Bryan
2a4a2ff7e1 Merge pull request #7 from ahnooie/udev_debug
add udev info to log
2016-10-23 19:44:39 -07:00
Benjamin Bryan
8572a0b21f add udev info to log 2016-10-23 19:35:57 -07:00
18 changed files with 501 additions and 100 deletions

2
.gitignore vendored
View File

@@ -2,4 +2,4 @@ logs/*
test.sh
archive/
config
temp/

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = https://github.com/caarlos0/shell-travis-build.git

12
.travis.yml Normal file
View File

@@ -0,0 +1,12 @@
language: bash
sudo: required
os:
- linux
before_script:
- cp ./config.sample config
install:
- ./build/install.sh
script:
- ./build/build.sh
notifications:
email: false

View File

35
CHANGELOG.md Normal file
View File

@@ -0,0 +1,35 @@
# Changelog
## v1.3.0
- Get Title for DVD and Blu-Rays so that media servesr can identify them easily.
- Determine if video is Movie or TV-Show from OMDB API query so that different actions can be taken (TV shows usually require manual episode identification)
- Option for MakeMKV to rip using backup method.
- Option to rip only main feature if so desired.
## v1.2.0
- Distinguish UDF data from UDF video discs
## v1.1.1
- Added devname to abcde command
- Added logging stats (timers). "grep STAT" to see parse them out.
## v1.1.0
- Added ability to rip from multiple drives at the same time
- Added a config file for parameters
- Changed logging
- Log name is based on ID_FS_LABEL (dvd name) variable set by udev in order to isolate logging from multiple process running simultaneously
- Log file name and path set in config file
- Log file cleanup based on parameter set in config file
- Added phone notification options for Pushbullet and IFTTT
- Remove MakeMKV destination directory after HandBrake finishes transcoding
- Misc stuff
## v1.0.1
- Fix ripping "Audio CDs" in ISO9660 format like LOTR.
## v1.0.0
- Initial Release

5
README
View File

@@ -1,5 +0,0 @@
Automatic Ripping Machine (ARM)
See: https://b3n.org/automatic-ripping-machine

81
README.md Normal file
View File

@@ -0,0 +1,81 @@
# Automatic Ripping Machine (ARM)
[![Build Status](https://travis-ci.org/ahnooie/automatic-ripping-machine.svg?branch=master)](https://travis-ci.org/ahnooie/automatic-ripping-machine)
## Overview
Insert an optical disc (Blu-Ray, DVD, CD) and checks to see if it's audio, video (Movie or TV), or data, then rips it.
See: https://b3n.org/automatic-ripping-machine
## Features
- Detects insertion of disc using udev
- Determines disc type...
- If video (Blu-Ray or DVD)
- Retrieve title from disc or Windows Media MetaServices API to name the folder "movie title (year)" so that Plex or Emby can pick it up
- Determine if video is Movie or TV using OMDb API
- Rip using MakeMKV (can rip all features or main feature)
- Eject disc and queue up Handbrake transcoding when done
- Transcoding jobs are asynchronusly batched from ripping
- Send notification when done via IFTTT or Pushbullet
- If audio (CD) - rip using abcde
- If data (Blu-Ray, DVD, or CD) - make an ISO backup
- Headless, designed to be run from a server
- Can rip from multiple-optical drives in parallel
## Requirements
- Ubuntu Server 16.04 (should work with other Linux distros)
- One or more optical drives to rip Blu-Rays, DVDs, and CDs
- Lots of drive space (I suggest using a NAS like FreeNAS) to store your movies
## Install
sudo su
add-apt-repository ppa:heyarje/makemkv-beta
add-apt-repository ppa:stebbins/handbrake-releases
add-apt-repository ppa:mc3man/xerus-media
apt update
apt install makemkv-bin makemkv-oss
apt install handbrake-cli libavcodec-extra
apt install abcde flac imagemagick glyrc cdparanoia
apt install at
apt install python3 python3-pip
apt-get install libdvd-pkg
dpkg-reconfigure libdvd-pkg
cd /opt
git clone https://github.com/ahnooie/automatic-ripping-machine.git arm
cd arm
pip3 install -r requirements.txt
ln -s /opt/arm/51-automedia.rules /lib/udev/rules.d/
ln -s /opt/arm/.abcde.conf /root/
cp config.sample config
- Edit your "config" file to determine what options you'd like to use
- To rip Blu-Rays after the MakeMKV trial is up you will need to purchase a license key or while MakeMKV is in BETA you can get a free key (which you will need to update from time to time) here: https://www.makemkv.com/forum2/viewtopic.php?f=5&t=1053 and create /root/.MakeMKV/settings.conf with the contents:
app_Key = "insertlicensekeyhere"
Optionally if you want something more stable than master you can download the latest release from the releases page.
## Usage
- Insert disc
- Wait for disc to eject
- Repeat
## Troubleshooting
Check /opt/arm/log to see if you can find where the script failed. If you need any help feel free to open an issue.
## Contributing
Pull requests are welcome
## License
[MIT License](LICENSE)

View File

@@ -1,2 +1,2 @@
#!/bin/bash
echo bash /opt/arm/identify.sh | at now
echo bash /opt/arm/identify.sh /opt/arm/config | at now

1
build Submodule

Submodule build added at 5f3e72c711

View File

@@ -1,4 +1,3 @@
#!/bin/bash
# ARM (Automatic Ripping Machine) oonfig file
#################
@@ -8,6 +7,9 @@
# Distinguish UDF video discs from UDF data discs. Requires mounting disc so adds a few seconds to the identify script.
ARM_CHECK_UDF=true
# When enabled if the disc is a DVD use dvdid to calculate a crc64 and query Windows Media Meta Services for the Movie Title.
# For BluRays attempts to extract the title from an XML file on the disc
GET_VIDEO_TITLE=true
#####################
## Directory setup ##
@@ -21,6 +23,10 @@ ARMPATH="/mnt/media/ARM/"
#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
MEDIA_DIR="/mnt/media/ARM/emby/movies/"
#Path to directory to hold log files
#Make sure to include trailing /
LOGPATH="/opt/arm/logs/"
@@ -35,6 +41,13 @@ LOGLIFE=1
#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.
RIPMETHOD="mkv"
##########################
## HandBrake Parameters ##
@@ -50,13 +63,22 @@ DEST_EXT=mkv
#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
MAINFEATURE=false
#############################
## Notification Parameters ##
#############################
#Pushbullet API Key
#Leave empty or comment out to disable Pushbullet notifications
#PB_KEY=""
PB_KEY=""
#IFTTT API KEY
#Leave empty or comment out to disable IFTTT notifications
@@ -69,7 +91,7 @@ IFTTT_EVENT="arm_event"
#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
if [ -z "$ID_FS_LABEL" ]; then
LOGFILE="empty.log"
else
LOGFILE=${ID_FS_LABEL}".log"
@@ -77,3 +99,4 @@ fi
#Set full logfile path
LOG=$LOGPATH$LOGFILE

View File

@@ -1,22 +1,24 @@
#!/bin/bash
#
# Rip Data using DD
source /opt/arm/config
# shellcheck disable=SC1091
# shellcheck source=config
source "$ARM_CONFIG"
{
TIMESTAMP=`date '+%Y%m%d_%H%M%S'`;
DEST=/mnt/media/ARM/${TIMESTAMP}_${ID_FS_LABEL}
mkdir $DEST
TIMESTAMP=$(date '+%Y%m%d_%H%M%S');
DEST="/mnt/media/ARM/${TIMESTAMP}_${ID_FS_LABEL}"
mkdir "$DEST"
FILENAME=${ID_FS_LABEL}_disc.iso
#dd if=/dev/sr0 of=$DEST/$FILENAME
cat /dev/sr0 > $DEST/$FILENAME
cat "$DEVNAME" > "$DEST/$FILENAME"
eject
} >> $LOG
} >> "$LOG"

74
getmovietitle.py Executable file
View File

@@ -0,0 +1,74 @@
#!/usr/bin/python3
import argparse
import urllib
import os
import datetime
import pydvdid
import unicodedata
import xmltodict
import sys
import re
def entry():
""" Entry to program, parses arguments"""
parser = argparse.ArgumentParser(description='Get Movie Title from DVD or Blu-Ray')
parser.add_argument('-p', '--path', help='Mount path to disc', required=True)
return parser.parse_args()
def getdvdtitle():
""" Calculates CRC64 for the DVD and calls Windows Media
Metaservices and returns the Title and year of DVD """
crc64 = pydvdid.compute(args.path)
# print (crc64)
dvd_info_xml = urllib.request.urlopen(
"http://metaservices.windowsmedia.com/pas_dvd_B/template/GetMDRDVDByCRC.xml?CRC={0}".
format(crc64)).read()
doc = xmltodict.parse(dvd_info_xml)
dvd_title = doc['METADATA']['MDR-DVD']['dvdTitle']
dvd_release_date = doc['METADATA']['MDR-DVD']['releaseDate']
# title + release year
return dvd_title + " (" + dvd_release_date.split()[0] + ")"
def getbluraytitle():
""" Get's Blu-Ray title by parsing XML in bdmt_eng.xml """
with open(args.path + '/BDMV/META/DL/bdmt_eng.xml', "rb") as xml_file:
doc = xmltodict.parse(xml_file.read())
bluray_title = doc['disclib']['di:discinfo']['di:title']['di:name']
bluray_modified_timestamp = os.path.getmtime(args.path + '/BDMV/META/DL/bdmt_eng.xml')
bluray_year = (datetime.datetime.fromtimestamp(bluray_modified_timestamp).strftime('%Y'))
bluray_title = unicodedata.normalize('NFKD', bluray_title).encode('ascii', 'ignore').decode()
bluray_title = bluray_title.replace(' - Blu-rayTM', '')
bluray_title = bluray_title.replace(' - BLU-RAYTM', '')
bluray_title = bluray_title.replace(' - BLU-RAY', '')
bluray_title = bluray_title.replace(' - Blu-ray', '')
return bluray_title + " (" + bluray_year + ")"
def clean_for_filename(string):
""" Cleans up string for use in filename """
string = re.sub('\[(.*?)\]', '', string)
string = re.sub( '\s+', ' ', string)
string = string.replace(' : ',' - ')
string = string.replace(': ',' - ')
return re.sub('[^\w\-_\.\(\) ]', '', string)
#pylint: disable=C0103
args = entry()
try:
disc_title = clean_for_filename(getdvdtitle())
except:
disc_title = clean_for_filename(getbluraytitle())
print(disc_title)
else:
print(disc_title)

54
getvideotype.py Executable file
View File

@@ -0,0 +1,54 @@
#!/usr/bin/python3
import sys
import argparse
import urllib
import os
import xmltodict
import json
import re
def entry():
""" Entry to program, parses arguments"""
parser = argparse.ArgumentParser(description='Get type of dvd--movie or tv series')
parser.add_argument('-t', '--title', help='Title', required=True)
return parser.parse_args()
def getdvdtype():
""" Queries OMDbapi.org for title information and parses if it's a movie
or a tv series """
dvd_title = args.title
year = dvd_title[(dvd_title.rindex('(')):len(dvd_title)]
year = re.sub('[()]','', year)
dvd_title = dvd_title[0:(dvd_title.rindex('('))].strip()
dvd_title = 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']
def cleanupstring(string):
# clean up title string to pass to OMDbapi.org
return re.sub('[_ ]',"+",string)
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")

View File

@@ -1,62 +1,106 @@
#!/bin/bash
#
source /opt/arm/config
export ARM_CONFIG=$1
echo "$ARM_CONFIG"
# shellcheck source=config
# shellcheck disable=SC1091
source "$ARM_CONFIG"
# Create log dir if needed
mkdir -p $LOGPATH
mkdir -p "$LOGPATH"
#shellcheck disable=SC2094
{
echo "Starting Identify Script..." >> $LOG
echo "Starting Identify Script..." >> "$LOG"
VIDEO_TITLE=""
HAS_NICE_TITLE=""
#Clean up old log files
FILESFOUND=( $(find $LOGPATH -mtime +$LOGLIFE -type f))
echo "Deleting ${#FILESFOUND[@]} old log files:"${FILESFOUND[@]} >> $LOG
find $LOGPATH -mtime +$LOGLIFE -type f -delete
FILESFOUND=( $(find "$LOGPATH" -mtime +"$LOGLIFE" -type f))
echo "Deleting ${#FILESFOUND[@]} old log files: ${FILESFOUND[*]}" >> "$LOG"
find "$LOGPATH" -mtime +"$LOGLIFE" -type f -delete
# Set Home to home folder of user that is setup to run MakeMKV
export HOME="/root/"
# Output UDEV info
udevadm info -q env -n "$DEVNAME" >> "$LOG"
if [ $ID_FS_TYPE == "udf" ]; then
echo "identified udf" >> $LOG
echo "found ${ID_FS_LABEL} on ${DEVNAME}" >> $LOG
if [ "$ID_FS_TYPE" == "udf" ]; then
echo "identified udf" >> "$LOG"
echo "found ${ID_FS_LABEL} on ${DEVNAME}" >> "$LOG"
if [ $ARM_CHECK_UDF == true ]; then
if [ "$ARM_CHECK_UDF" == true ]; then
# check to see if this is really a video
mkdir -p /mnt/${DEVNAME}
mount ${DEVNAME} /mnt/${DEVNAME}
mkdir -p /mnt/"$DEVNAME"
mount "$DEVNAME" /mnt/"$DEVNAME"
if [[ -d /mnt/${DEVNAME}/VIDEO_TS || -d /mnt/${DEVNAME}/BDMV ]]; then
echo "identified udf as video" >> $LOG
umount /mnt/${DEVNAME}
/opt/arm/video_rip.sh $LOG
echo "identified udf as video" >> "$LOG"
if [ "$GET_VIDEO_TITLE" == true ]; then
GET_TITLE_OUTPUT=$(/opt/arm/getmovietitle.py -p /mnt"${DEVNAME}" 2>&1)
GET_TITLE_RESULT=$?
if [ $GET_TITLE_RESULT = 0 ]; then
echo "Obtained Title $GET_TITLE_OUTPUT"
HAS_NICE_TITLE=true
VIDEO_TITLE=${GET_TITLE_OUTPUT}
else
echo "failed to get title $GET_TITLE_OUTPUT"
HAS_NICE_TITLE=false
VIDEO_TITLE=${ID_FS_LABEL}
fi
else
HAS_NICE_TITLE=false
VIDEO_TITLE=${ID_FS_LABEL}
fi
if [ $HAS_NICE_TITLE == true ]; then
VIDEO_TYPE=$(/opt/arm/getvideotype.py -t "${VIDEO_TITLE}" 2>&1)
else
VIDEO_TYPE="unknown"
fi
echo "got to here"
echo "HAS_NICE_TITLE is ${HAS_NICE_TITLE}"
echo "video title is now ${VIDEO_TITLE}"
echo "video type is ${VIDEO_TYPE}"
umount "/mnt/$DEVNAME"
/opt/arm/video_rip.sh "$VIDEO_TITLE" "$HAS_NICE_TITLE" "$VIDEO_TYPE" "$LOG"
else
umount /mnt/${DEVNAME}
echo "identified udf as data" >> $LOG
/opt/arm/data_rip.sh $LOG
eject $DEVNAME
umount "/mnt/$DEVNAME"
echo "identified udf as data" >> "$LOG"
/opt/arm/data_rip.sh
eject "$DEVNAME"
fi
else
echo "ARM_CHECK_UDF is false, assuming udf is video" >> $LOG
/opt/arm/video_rip.sh $LOG
echo "ARM_CHECK_UDF is false, assuming udf is video" >> "$LOG"
/opt/arm/video_rip.sh "$LOG"
fi
elif (($ID_CDROM_MEDIA_TRACK_COUNT_AUDIO > 0 )); then
echo "identified audio" >> $LOG
abcde -d $DEVNAME
elif (("$ID_CDROM_MEDIA_TRACK_COUNT_AUDIO" > 0 )); then
echo "identified audio" >> "$LOG"
abcde -d "$DEVNAME"
elif [ $ID_FS_TYPE == "iso9660" ]; then
echo "identified data" >> $LOG
/opt/arm/data_rip.sh $LOG
eject $DEVNAME
elif [ "$ID_FS_TYPE" == "iso9660" ]; then
echo "identified data" >> "$LOG"
/opt/arm/data_rip.sh "$LOG"
eject "$DEVNAME"
else
echo "unable to identify" >> $LOG
echo $ID_CDROM_MEDIA_TRACK_COUNT_AUDIO >> $LOG
echo $ID_FS_TYPE >> $LOG
eject $DEVNAME
echo "unable to identify"
echo "$ID_CDROM_MEDIA_TRACK_COUNT_AUDIO" >> "$LOG"
echo "$ID_FS_TYPE" >> "$LOG"
eject "$DEVNAME"
fi
} >> $LOG
} >> "$LOG"

View File

@@ -1,28 +1,30 @@
#!/bin/bash
source /opt/arm/config
# shellcheck source=config
# shellcheck disable=SC1091
source "$ARM_CONFIG"
MSG=$1
{
#Notification via pushbullet
#Trigger onl if variable is set
if [ -z "$PB_KEY" ]; then
echo "Pushbullet notifications not enabled" >> $LOG
echo "Pushbullet notifications not enabled" >> "$LOG"
else
echo "Sending Pushbullet notification" >> $LOG
curl -s -u $PB_KEY: https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="$MSG"
echo "Pushbullet notification sent" >> $LOG
echo "Sending Pushbullet notification" >> "$LOG"
curl -s -u "$PB_KEY": https://api.pushbullet.com/v2/pushes -d type=note -d title="Alert" -d body="$MSG"
echo "Pushbullet notification sent" >> "$LOG"
fi
#Notification via IFTTT
#Trigger only if variable is set
if [ -z "$IFTTT_KEY" ]; then
echo "IFTTT notifications not enabled" >> $LOG
echo "IFTTT notifications not enabled" >> "$LOG"
else
echo "Sending IFTTT notification" >> $LOG
curl -s -X POST -H "Content-Type: application/json" -d '{"value1":"'"$MSG"'"}' https://maker.ifttt.com/trigger/${IFTTT_EVENT}/with/key/${IFTTT_KEY}
printf "\nIFTTT notification sent" >> $LOG
echo "Sending IFTTT notification" >> "$LOG"
curl -s -X POST -H "Content-Type: application/json" -d '{"value1":"'"$MSG"'"}' https://maker.ifttt.com/trigger/"$IFTTT_EVENT"/with/key/"$IFTTT_KEY"
printf "\nIFTTT notification sent" >> "$LOG"
fi
} >> $LOG
} >> "$LOG"

5
requirements.txt Normal file
View File

@@ -0,0 +1,5 @@
pycurl>=7.43.0
pydvdid>=1.0
requests>=2.9.1
urllib3>=1.13.1
xmltodict>=0.10.2

View File

@@ -1,33 +1,57 @@
#!/bin/bash
#
# Rip video using MakeMKV then eject and call transcode script
source /opt/arm/config
# shellcheck source=config
# shellcheck disable=SC1091
source "$ARM_CONFIG"
VIDEO_TITLE=$1
HAS_NICE_TITLE=$2
VIDEO_TYPE=$3
{
echo "Ripping video ${ID_FS_LABEL} from ${DEVNAME}" >> $LOG
TIMESTAMP=`date '+%Y%m%d_%H%M%S'`;
DEST=${RAWPATH}/${ID_FS_LABEL}_${TIMESTAMP}
echo "Video Title is ${VIDEO_TITLE}"
echo "Ripping video ${ID_FS_LABEL} from ${DEVNAME}" >> "$LOG"
TIMESTAMP=$(date '+%Y%m%d_%H%M%S');
DEST="${RAWPATH}/${VIDEO_TITLE}_${TIMESTAMP}"
RIPSTART=$(date +%s);
mkdir $DEST
mkdir "$DEST"
#echo /opt/arm/video_transcode.sh \"$DEST\" \"$VIDEO_TITLE\" $TIMESTAMP >> $LOG
if [ "$RIPMETHOD" = "backup" ] && [ "$ID_CDROM_MEDIA_BD" = "1" ]; then
echo "Using backup method of ripping." >> "$LOG"
DISC="${DEVNAME: -1}"
echo "Sending command: makemkvcon backup --decrypt -r disc:$DISC $DEST"
makemkvcon backup --decrypt -r disc:"$DISC" "$DEST"/
eject "$DEVNAME"
elif [ "$MAINFEATURE" = true ] && [ "$ID_CDROM_MEDIA_DVD" = "1" ] && [ -z "$ID_CDROM_MEDIA_BD" ]; then
echo "Media is DVD and Main Feature parameter in config file is true. Bypassing MakeMKV." >> "$LOG"
# rmdir "$DEST"
makemkvcon mkv dev:$DEVNAME all $DEST --minlength=$MINLENGTH -r
echo "DEST is ${DEST}"
else
echo "Using mkv method of ripping." >> "$LOG"
makemkvcon mkv dev:"$DEVNAME" all "$DEST" --minlength="$MINLENGTH" -r
eject "$DEVNAME"
fi
RIPEND=$(date +%s);
RIPSEC=$(($RIPEND-$RIPSTART));
RIPTIME="$(($RIPSEC / 3600)) hours, $((($RIPSEC / 60) % 60)) minutes and $(($RIPSEC % 60)) seconds."
RIPSEC=$((RIPEND-RIPSTART));
RIPTIME="$((RIPSEC / 3600)) hours, $(((RIPSEC / 60) % 60)) minutes and $((RIPSEC % 60)) seconds."
eject $DEVNAME
#eject $DEVNAME
echo /opt/arm/notify.sh "\"Ripped: ${ID_FS_LABEL} completed from ${DEVNAME} in ${RIPTIME}\"" |at now
#echo /opt/arm/notify.sh "\"Ripped: ${ID_FS_LABEL} completed from ${DEVNAME} in ${RIPTIME}\"" |at now
echo "STAT: ${ID_FS_LABEL} ripped in ${RIPTIME}" >> $LOG
echo /opt/arm/video_transcode.sh $DEST $ID_FS_LABEL $TIMESTAMP | batch
echo "STAT: ${ID_FS_LABEL} ripped in ${RIPTIME}" >> "$LOG"
echo "${ID_FS_LABEL} sent to transcoding queue..." >> $LOG
echo "/opt/arm/video_transcode.sh \"$DEST\" \"$VIDEO_TITLE\" \"$HAS_NICE_TITLE\" \"$VIDEO_TYPE\" $TIMESTAMP"
echo "/opt/arm/video_transcode.sh \"$DEST\" \"$VIDEO_TITLE\" \"$HAS_NICE_TITLE\" \"$VIDEO_TYPE\" \"$TIMESTAMP\"" | batch
echo "${ID_FS_LABEL} sent to transcoding queue..." >> "$LOG"
} >> $LOG
} >> "$LOG"

View File

@@ -1,41 +1,87 @@
#!/bin/bash
# Transcodes Video files using HandBrake and removes source files when done
source /opt/arm/config
# shellcheck source=config
# shellcheck disable=SC1091
source "$ARM_CONFIG"
SRC=$1
LABEL=$2
TIMESTAMP=$3
TRANSSTART=$(date +%s);
HAS_NICE_TITLE=$3
VIDEO_TYPE=$4
TIMESTAMP=$5
echo "Start video transcoding script" >> $LOG
DEST=${ARMPATH}/${LABEL}_${TIMESTAMP}
mkdir $DEST
TRANSSTART=$(date +%s);
echo "Start video transcoding script" >> "$LOG"
for FILE in `ls $SRC`
do
filename=$(basename $FILE)
extension=${filename##*.}
filename=${filename%.*}
echo "Transcoding file $FILE" >> $LOG
if [ "$HAS_NICE_TITLE" = true ]; then
echo "transcoding with a nice title" >> "$LOG"
DEST="${ARMPATH}/${LABEL}"
echo "dest ${DEST} variable created"
if [ -d "$DEST" ]; then
echo "directory already exists... adding timestamp" >> "$LOG"
DEST="${ARMPATH}/${LABEL}_${TIMESTAMP}"
fi
else
echo "transcoding without a nice title" >> "$LOG"
DEST="${ARMPATH}/${LABEL}_${TIMESTAMP}"
fi
$HANDBRAKE_CLI -i $SRC/$FILE -o $DEST/$filename.$DEST_EXT --preset="$HB_PRESET" --subtitle scan -F 2>> $LOG
#TIMESTAMP=`date '+%Y_%m_%d__%H_%M_%S'`;
#mv $SRC/$FILE $SRC/done/$TIMESTAMP.$FILE
#mv $DEST/$FILE $DEST/done/$FILE
rm $SRC/$FILE
# DEST="${ARMPATH}/${LABEL}_${TIMESTAMP}"
mkdir "$DEST"
if [ "$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"
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"
# shellcheck disable=SC2045
for FILE in $(ls "$SRC")
do
filename=$(basename "$FILE")
done
#extension=${filename##*.}
filename=${filename%.*}
rmdir $SRC
echo "Transcoding file $FILE" >> "$LOG"
$HANDBRAKE_CLI -i "$SRC/$FILE" -o "$DEST/$filename.$DEST_EXT" --preset="$HB_PRESET" --subtitle scan -F 2>> "$LOG"
rm "$SRC/$FILE"
done
rmdir "$SRC"
fi
if [ "$VIDEO_TYPE" = "movie" ] && [ "$MAINFEATURE" = true ] && [ "$HAS_NICE_TITLE" = true ]; then
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"
else
echo "Warning: $MEDIA_DIR/$LABEL.$DEST_EXT File exists! File moving aborted" >> "$LOG"
fi
else
echo "Nothing here..." >> "$LOG"
fi
rmdir "$SRC"
TRANSEND=$(date +%s);
TRANSSEC=$(($TRANSEND-$TRANSSTART));
TRANSTIME="$(($TRANSSEC / 3600)) hours, $((($TRANSSEC / 60) % 60)) minutes and $(($TRANSSEC % 60)) seconds."
TRANSSEC=$((TRANSEND-TRANSSTART));
TRANSTIME="$((TRANSSEC / 3600)) hours, $(((TRANSSEC / 60) % 60)) minutes and $((TRANSSEC % 60)) seconds."
echo "STAT: ${ID_FS_LABEL} transcoded in ${TRANSTIME}" >> $LOG
echo "STAT: ${ID_FS_LABEL} transcoded in ${TRANSTIME}" >> "$LOG"
#echo /opt/arm/rename.sh $DEST
echo /opt/arm/notify.sh "\"Transcode: ${ID_FS_LABEL} completed in ${TRANSTIME}\"" |at now