i've done a little bit of coding in my day but i'm very much out of practice, and bash scripting is not something i've ever really done. this is what i'm working on now. it's sloppy and took me a couple hours but it works (if certain conditions are met).
Code: Select all
#!/bin/bash
if [ -f $1/*.nfo ]; then
echo "Folder already has an nfo."
# folder has a nfo file, (hopefully with imdb url).. skip to end
else
echo "" > movie.txt
var1=`echo ${3%1080p*} | sed 's/\./+/g;s/2013//g;'`
# clean up release name
echo " "
echo "Searching IMDBAPI.com using:" $var1
echo " "
curl http://www.imdbapi.com/?t=$var1 >> movie.txt
# save api request to movie.txt
imdb="http://www.imdb.com/title/"
var2=`echo $imdb ``sed -e 's/^.*"imdbID":"\([^"]*\)".*$/\1/' movie.txt```
imdburl=`echo $var2 | tr -d ' '`
# find imdb id in movie.txt, append imdb prefix, and trim spaces
len=$(echo ${#imdburl})
if [ $len -eq 35 ]; then
# assuming all imdb tt's are 7 digits, if more or less, imdbapi did not find good results
echo $imdburl > movie.nfo
nfogoes=`echo $1 "/movie.nfo" | tr -d ' '`
# full path + /movie.nfo to be used later
echo " "
echo "Found IMDB URL:" $imdburl
echo " "
echo "Target location:" $nfogoes
echo " "
mv movie.nfo $nfogoes
echo "Moved movie.nfo to $1"
# move nfo to directory
echo " "
else
# if we get bad data from imdbapi..
echo "IMDB URL not found."
echo -e "Subject: No suitable NFO found: $3\n\n$1" | ssmtp -d root
# will email me so i remember to fix manually. imdbapi can be kinda picky.
fi
fi
echo " "
echo "Sending JSON to update XBMC Library.."
echo " "
echo "curl -s -H \"Content-Type: application/json\" -u xbmc:xbmc -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"VideoLibrary.Scan\", \"params\":{\"directory\":\"smb://tower/x264/rls/\"}, \"id\": \"scan\"}' http://tower:9091/jsonrpc" | sed 's_rls_'"$3"'_g' | sh
# update xbmc library for this directory
echo " "
echo " "
[*] releases are named as "1080p" and doesn't have extra stuff like DOCU, PROPER, STV, etc. before the "1080p"
[*] release name doesn't have a year, or a year other than the one i specify (which is 2013 above). couldn't find a better way to get rid of NNNN.
there's a couple other things on my list that i need this to do but for now i'd like a better way to clean up the release name. any thoughts? all i have right now is delete everything including and after 1080p and remove the year (if it's 2013).