Skip to content

Instantly share code, notes, and snippets.

@devinberry
Created July 13, 2016 18:40
Show Gist options
  • Save devinberry/d6cefa67e6433736839939c51969d1bc to your computer and use it in GitHub Desktop.
Save devinberry/d6cefa67e6433736839939c51969d1bc to your computer and use it in GitHub Desktop.
beta version still some bugs and issues to work out thought I would share current efforts enjoy ;)
#!/usr/bin/env bash
#######################################################################################
## ##
## movieFileExpander.sh ##
## ##
## A utility script to help in the decompression extraction file renaming ##
## and finally moving to a final destination for viewing purposes ##
## Created out of the need to be lazy and to automate all this manual work ##
## Gathered from other various articles blogs and scripts, tweaked to personal ##
## usage and need. Feel free to change to best suit your needs. ##
## ##
#######################################################################################
#@todo: Conversion of all movie files into mp4 format
#@todo: Ability to check for drive space in working and destination dirs
#@todo: handle the merge of cd1 and cd2 if not avi files ?
#@todo: flip checking for network drive exists into function, check in more places to avoid script errors.
#@TODO: need to incorporate dealing with .mov files
#@TODO: cd1 and cd2 are .bin files need to add logic to deal with
archiveDir="/home/user/media/networkDrive"
failedVerifyDir="$archiveDir/failed_verification_archives"
finalHomeDir="/home/user/media/networkLocation"
baseHomeDir="/home/user/media/networkDrive2"
date=$(date +"%m-%d-%Y")
shopt -s nullglob
#verify our network drive | path is up and exists
if mount | grep "$baseHomeDir" > /dev/null;
then
#change dir to our archive file full of movie tar files
echo "Moving to network volume $archiveDir/"
cd "$archiveDir/" || exit
#loop to get list of all files grab the first one and work on it
for i in *.tar *.rar;
do
#to help this script become more friendly to parallel execution
#we need to check if the next file in the list exists, or rather if another instance
#of this script has already grabbed the file if so we should move on
#this is the current cause of some of the weird output errors and or the script stopping execution
if [ -f "$i" ];
then
#create a folder based on PID so that we can contain work away from other instances of script run
PID=$$
#Make pid file to resolve concurrency and allow for parrallel runs of this shell script
echo "Making pid directory to work in PID DIR $PID"
mkdir -p "$archiveDir/$PID"
f="${i##*/}"
#do we have a tar or rar main movie file lets find out
#doWeHaveATarFile=$(ls "$i" | grep "\.[Tt][Aa][Rr]$")
#doWeHaveARarFile=$(ls "$i" | grep "\.[Rr][Aa][Rr]$")
#whatArchiveExtType="${i##*.}"
#extractFileName=`echo $f | awk -F'/' '{print $NF}'`
#if [ "$whatArchiveExtType" = rar ];
#then
#the main file extraction and testing for corrupt below is rar
#mainFileUnCompress="! unrar t -idq $i &> /dev/null;"
#secMainFileUnCompress="unrar x $extractFileName $archiveDir/$PID/"
#baseName="basename $extractFileName .rar"
#else
#the main file extraction and testing for corrup below is tar
#mainFileUnCompress="! tar tf $i &> /dev/null"
#secMainFileUnCompress="pv $extractFileName | tar -xf - -C $archiveDir/$PID/"
#baseName="basename $extractFileName .tar"
#fi
if ! tar tf "$i" &> /dev/null;
then
echo "Bad archive moving to failed archive folder for review"
mv "$i" "$failedVerifyDir/" #& progress -mp $!
#clean up created pid dir
echo "Removing pid dir used to do work on movie tar file"
rm -rf "$archiveDir/$PID"
else
#means archive is good we should proceed with work
# Filename : 'file.1.0.x.tar.gz'
extractFileName=$(echo "$f" | awk -F'/' '{print $NF}')
echo "File archive to extract $extractFileName"
#move movie archive to our pid dir to complete work
mv "$extractFileName" "$archiveDir/$PID/" #& progress -mp $!
#on linux options are different progress -zf file.tar.gz tar xf -
#now we should cd to pid dir and complete chores
cd "$archiveDir/$PID/" || exit
#get basename of file no extension (used later to rename move file)
#baseFileName=$( "$baseName" )
#baseFileName=$(basename "$extractFileName" ."$whatArchiveExtType")
baseFileName=$(basename "$extractFileName" .tar)
#replace spaces with underscores
filterFileName=`echo "$baseFileName"|tr " " "."`
#remove any group signatures on dealing with [group]
filteredFileName=`echo "$filterFileName" | sed -e 's/\[[^][]*\]//g' | sed -e "s/]/']/" -e "s/\[/['/"`
#now we have what the destination folder name should look like
destinationPathAndFolder="$finalHomeDir/$filteredFileName"
echo "Extracting $extractFileName to $archiveDir/$PID"
#this should get reset on down in logic if it is present
doWeHaveCd1AndCd2=false
START=$(date +%s)
#so this completes the first layer of extraction then we have the second layer to do
#echo `pv "$extractFileName" | tar -xzf - -C "$archiveDir/$PID/"`
#tar -xzf "$extractFileName" -C "$archiveDir/$PID/" & progress -mp $!
pv "$extractFileName" | tar -xf - -C "$archiveDir/$PID/"
#this grabs the exit code of the last fired command here this would be tar
retcode=$?
if [ $retcode != 0 ] ;
then
exit
fi
END=$(date +%s)
#Compute the time it took extraction to complete
DIFF=$(( $END - $START ))
echo "[ $date ] file extraction completed in $DIFF seconds"
#now cd into the newly created extracted dir and do second layer of uncompress
cd "$archiveDir/$PID/$baseFileName/" || exit
#@todo: Right here seems we are having trouble when CRC files are present in and dir
#@todo: they start with -- and this is cauings problems so right here lets eliminate them.
#@todo: traverse recursive into all dirs from this level down and nuke those files.
#find * -iname "--*" -delete
find * -iname "-*" -delete
isThereASampleDir=`find * -type d -print | grep -v '\.[Rr][Aa0-9][Rr0-9]$' | grep -v '\.[0-9][0-9][0-9]$' | grep '[Ss][Aa][Mm][Pp][Ll][Ee]'`
if [ -n "$isThereASampleDir" ]
then
rm -rf "$isThereASampleDir"
fi
ls -p | grep -v '\.[Rr][Aa0-9][Rr0-9]$' | grep -v '\.[0-9][0-9][0-9]$' | grep -v / | xargs rm -f
#ls -p | | grep -v /
#do we have a cd1 and cd2 situation check to see if not then use the rest of the below codebase
#we are going to check only for cd1 if so then im sure there is cd2
#@todo: support for subs with cd1 and cd2
#turning on case insensitive matching
shopt -s nocasematch
isThereCD1Dir=`find * -type d -print | grep '[Cc][Dd][1]'`
isThereCD2Dir=`find * -type d -print | grep '[Cc][Dd][2]'`
if [[ -n "$isThereCD1Dir" ]] && [[ -n "$isThereCD2Dir" ]];
then
#turning off case insensitive matching
shopt -u nocasematch
#so that means we do have cd1 and cd2
doWeHaveCd1AndCd2=true
#lets handle one at a time then at the end move both movie files to same dir and merge
cd "$archiveDir/$PID/$baseFileName/$isThereCD1Dir/" || exit
#now need to extract for cd 1 or part 1 of movie file
for cd1File in *.rar *.tar;
do
#extract and then rename
cd1FileEx="${cd1File##*.}"
echo "Changed to extraction dir $archiveDir/$PID/$baseFileName/$isThereCD1Dir now extracting movie file "
START1=$(date +%s)
if [ "$cd1FileEx" = tar ];
then
pv "$cd1File" | tar -xf - -C "$archiveDir/$PID/$baseFileName/$isThereCD1Dir/"
else
#echo `pv "$exFile" | rar x - "$finalHomeDir/$baseFileName/"`
#echo `pv "$exFile"` | `unrar "$exFile"`
#ls *.r[0-9][0-9] | parallel unrar
#tar -cf - "${filestobackup[@]}" | pv -s $(du -cb "${filestobackup[@]}" | tail -1 | awk '{print $1}') | gzip > archive.tar.gz
#unrar e "${exFile[@]}" | pv $(du -c "${exFile[@]}" | tail -1 | awk '{print $1}')
#checking if sfv file exists in the first place
#if [ -f *.sfv ];
#then
#clear && echo "" && echo "Found sfv file going to check all rar files"
#cksfv -q -c -f *.sfv>tmp
#sfvfine=`cat tmp|grep "Everything OK" `
#if [ $sfvfine=="Everything OK" ];
#then
# didRarFilePassCheck=true
unrar e "$cd1File" #& progress -mp $!
#this grabs the exit code of the last fired command here this would be tar
# else
#clear && echo "" && echo "Something must be corrupt or missing files need to redownload"
#@todo: need to create list here of movie files that need to be redownloaded
#set variable here to let the rest of flow know stop processing and redownload
#didRarFilePassCheck=false
#fi
#fi
fi
END1=$(date +%s)
DIFF1=$(( $END1 - $START1 ))
echo "[ $date ] file extraction completed in $DIFF1 seconds"
#get full real path including new filename this will be used to then move them into same
cd1MovieFile=`find * -maxdepth 0 -type f | egrep '.avi$|.mp4$|.mkv$'`
cd1MovieFilex=$(echo "$cd1MovieFile" | tr -d '\n')
cd1FileExtension="${cd1MovieFilex##*.}"
echo "Renaming cd1 movie file to $filteredFileName.CD1.$cd1FileExtension"
mv "$archiveDir/$PID/$baseFileName/$isThereCD1Dir/$cd1MovieFilex" "$archiveDir/$PID/$baseFileName/$isThereCD1Dir/$filteredFileName.CD1.$cd1FileExtension" #& progress -mp $!
#finally get full path with new name for cd1 movie file
fullPathAndFileNameCD1="$archiveDir/$PID/$baseFileName/$isThereCD1Dir/$filteredFileName.CD1.$cd1FileExtension"
finalFileNameCD1="$filteredFileName.CD1.$cd1FileExtension"
done
cd "$archiveDir/$PID/$baseFileName/$isThereCD2Dir/" || exit
#now need to extract for cd 1 or part 1 of movie file
for cd2File in *.rar *.tar;
do
#extract and then rename
cd2FileEx="${cd2File##*.}"
echo "Changed to extraction dir $archiveDir/$PID/$baseFileName/$isThereCD2Dir now extracting movie file "
START1=$(date +%s)
if [ "$cd2FileEx" = tar ]
then
pv "$cd2File" | tar -xf - -C "$archiveDir/$PID/$baseFileName/$isThereCD2Dir/"
#this grabs the exit code of the last fired command here this would be tar
else
#echo `pv "$exFile" | rar x - "$finalHomeDir/$baseFileName/"`
#echo `pv "$exFile"` | `unrar "$exFile"`
#ls *.r[0-9][0-9] | parallel unrar
unrar e "$cd2File" #& progress -mp $!
#tar -cf - "${filestobackup[@]}" | pv -s $(du -cb "${filestobackup[@]}" | tail -1 | awk '{print $1}') | gzip > archive.tar.gz
#unrar e "${exFile[@]}" | pv $(du -c "${exFile[@]}" | tail -1 | awk '{print $1}')
#this grabs the exit code of the last fired command here this would be tar
fi
END1=$(date +%s)
DIFF1=$(( $END1 - $START1 ))
echo "[ $date ] file extraction completed in $DIFF1 seconds"
#get full real path including new filename this will be used to then move them into same
cd2MovieFile=`find * -maxdepth 0 -type f | egrep '.avi$|.mp4$|.mkv$'`
cd2MovieFilex=$(echo "$cd2MovieFile"|tr -d '\n')
cd2FileExtension="${cd2MovieFilex##*.}"
echo "Renaming cd2 movie file to $filteredFileName.CD2.$cd2FileExtension"
mv "$archiveDir/$PID/$baseFileName/$isThereCD2Dir/$cd2MovieFilex" "$archiveDir/$PID/$baseFileName/$isThereCD2Dir/$filteredFileName.CD2.$cd2FileExtension" #& progress -mp $!
#finally get full path with new name for cd1 movie file
fullPathAndFileNameCD2="$archiveDir/$PID/$baseFileName/$isThereCD2Dir/$filteredFileName.CD2.$cd2FileExtension"
finalFileNameCD2="$filteredFileName.CD2.$cd2FileExtension"
done
#fi
#once here cd back into parent dir of cd1 and cd2 dirs
cd "$archiveDir/$PID/$baseFileName/" || exit
#move both movie files here
mv "$fullPathAndFileNameCD1" "$archiveDir/$PID/$baseFileName/"
mv "$fullPathAndFileNameCD2" "$archiveDir/$PID/$baseFileName/"
#prepare to merge them
#@todo: Here is where we will now deal with subs if they exist
#@todo: The sub files and further level deep of another .rar file to get sub files
#@todo: Will be in the form like the above split out to cd1 and cd2
#@todo: Need to extract all, concat all, rename both and then move them to join the merged movie file
#@todo: only dealing with merging avi at the moment
if [ "$cd2FileExtension" = 'avi' ]
then
#mergedFile=merged_cd1_cd2.avi
#cat avi1.avi avi2.avi avix.avi > avi_all.avi
clear && echo "" && echo "Now combining the two movie files..."
#cat "$finalFileNameCD1" "$finalFileNameCD2" > "$mergedFile" & progress -mp $!
#ffmpeg -i avi_all.avi -acodec copy -vcodec copy avi_all_reindexed.avi
clear && echo "" && echo "Will now convert using mencoder ...."
#ffmpeg -i "$mergedFile" -threads 4 -acodec copy -vcodec copy "$baseFileName.$cd2FileExtension"
mencoder -oac copy -ovc copy "$finalFileNameCD1" "$finalFileNameCD2" -o "$filteredFileName.$cd2FileExtension" #& progress -mp $!
finalMovieFileName=`echo "$filteredFileName.$cd2FileExtension"`
else
exit 1 #@todo: only handling avi files need to address handling more
fi
############################### CODE TO DEAL WITH SUBS CD1 CD2 ########################################
#turning on case insensitive matching
shopt -s nocasematch
#lets see if we can find it first, if present this should output Subs/
#subsDir=`ls -d *[sub]*/ | awk '{print $10}'`
subsDir=`find * -type d -print | grep -v '\.avi$|\.mp4$|\.mkv$' | grep -v '\.[Rr][Aa0-9][Rr0-9]$' | grep '[Ss][Uu][Bb][Ss]'`
#first lets cd into the subs dir or only do so if it exists
#if [[ -d "$archiveDir/$PID/$baseFileName/subs" ]] || [[ -d "$archiveDir/$PID/$baseFileName/Subs" ]]
if [ -n "$subsDir" ]
then
#so we do have a subs dir now time to handle
#subsDir=`ls -d *[sub]*/ | awk '{print $10}'`
#change dirs into sub and continue with work this will already have a trialing /
cd "$archiveDir/$PID/$baseFileName/$subsDir" || exit
#here we have our first *should be* rar file
for s in *.rar;
do
mkdir -p "$archiveDir/$PID/$baseFileName/$subsDir/subSecond"
secondSubDir="$archiveDir/$PID/$baseFileName/$subsDir/subSecond"
#this will create a new dir inside the current dir we are in which should be subs
unrar e "$s" "$secondSubDir" #& progress -mp $!
#this grabs the exit code of the last fired command here this would be tar
#cd into this dir
cd "$secondSubDir" || exit
#need to discover what we have in here do we have both .idx and .sub files
#do we only have an .idx file and another rar to uncompress
subRarFileCD1=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][1]\.rar'`
subRarFileCD2=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][2]\.rar'`
#idx files should already be present so map them
idxFileCD1=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][1]\.idx'`
idxFileCD2=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][2]\.idx'`
#This will return true if a variable is unset or set to the empty string ("").
if [ -n "$subRarFileCD1" ]
then
#this means we do have another rar file to extract and then we should have both files
unrar e "$subRarFileCD1"
unrar e "$subRarFileCD2"
subFileCD1=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][1]\.sub'`
subFileCD2=`find * -maxdepth 0 -type f -print | grep '.*[Cc][Dd][2]\.sub'`
idxFileCd1Ext="${idxFileCD1##*.}"
idxFileCd2Ext="${idxFileCD2##*.}"
subFileCd1Ext="${subFileCD1##*.}"
subFileCd2Ext="${subFileCD2##*.}"
#shall we merge them since we are here might as well
cat "$idxFileCD1" "$idxFileCD2" > "$filteredFileName.$idxFileCd1Ext"
finalIdxSubFile=`echo "$filteredFileName.$idxFileCd1Ext"`
#just move it to base parent dir
mv "$filteredFileName.$idxFileCd1Ext" "$archiveDir/$PID/$baseFileName/"
#concat the sub files
cat "$subFileCD1" "$subFileCD2" > "$filteredFileName.$subFileCd1Ext"
finalSubSubFile=`echo "$baseFileName.$subFileCd1Ext"`
#just move it to base parent dir
mv "$filteredFileName.$subFileCd1Ext" "$archiveDir/$PID/$baseFileName/"
#now move back to main movie dir where we were before we found we had subs
cd "$archiveDir/$PID/$baseFileName/" || exit
doWeHaveSubs=true
fi
done
else
doWeHaveSubs=false
fi
#turning off case insensitive matching
shopt -u nocasematch
############################### END OF CODE TO DEAL WITH SUBS CD1 CD2 #################################
#exit 1
#get full real path to final created movie file this will be used later to move it to destination
#once move is complete remove the pid dir and continue loop
#make sure to check that the network location destination volume exists
if mount | grep "$finalHomeDir" > /dev/null;
then
#its there exists and is up lets move the movie file
clear && echo "" && echo "Moving movie dir and file created to final destination"
mkdir -p "$finalHomeDir/$baseFileName"
#echo `mv "$finalMovieFileName" "$finalHomeDir/$baseFileName/" & progress -mp $!`
#@todo: should consider using this rsync -avP src/ dst/
#mv "$finalMovieFileName" "$finalHomeDir/$baseFileName/" & progress -mp $!
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$cd2FileExtension" --exclude="*" "$finalMovieFileName" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line is to be run if we are on linux and the network viewport is different
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$cd2FileExtension" --exclude="*" "$finalMovieFileName" "$finalHomeDir/$baseFileName/"
#check to see if we have subs if so move them over too
if [ "$doWeHaveSubs" = true ]
then
#mv "$finalIdxSubFile" "$finalHomeDir/$baseFileName/"
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$idxFileCd1Ext" --exclude="*" "$finalIdxSubFile" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line to only be run on linux
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$idxFileCd1Ext" --exclude="*" "$finalIdxSubFile" "$finalHomeDir/$baseFileName/"
#mv "$finalSubSubFile" "$finalHomeDir/$baseFileName/"
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$subFileCd1Ext" --exclude="*" "$finalSubSubFile" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line to only be run on linux
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$subFileCd1Ext" --exclude="*" "$finalSubSubFile" "$finalHomeDir/$baseFileName/"
fi
#move completed then cleanup
cd "$archiveDir/" || exit
echo "Removing pid dir "
rm -rf "$archiveDir/$PID"
#exit 1
else
echo "Network $finalHomeDir not present, aborting script"
exit 1
fi
fi
#@todo: this does not deal with subs for this kind of tree struct cd1 cd2
#@todo: i think this needds to change to test cd1 and cd2 to be negative
if [ "$doWeHaveCd1AndCd2" = false ];
then
#turning off case insensitive matching
shopt -u nocasematch
#kick off further decompression to get movie file
for exFile in *.rar *.tar *.RAR *.TAR;
do
extension="${exFile##*.}"
echo "Changed to extraction dir $archiveDir/$PID/$baseFileName now extracting movie file "
START1=$(date +%s)
if [ "$extension" = tar ]
then
pv "$exFile" | tar -xf - "$archiveDir/$PID/$baseFileName/"
#this grabs the exit code of the last fired command here this would be tar
else
#echo `pv "$exFile" | rar x - "$finalHomeDir/$baseFileName/"`
#echo `pv "$exFile"` | `unrar "$exFile"`
#ls *.r[0-9][0-9] | parallel unrar
unrar e "$exFile" #& progress -mp $!
#tar -cf - "${filestobackup[@]}" | pv -s $(du -cb "${filestobackup[@]}" | tail -1 | awk '{print $1}') | gzip > archive.tar.gz
#unrar e "${exFile[@]}" | pv $(du -c "${exFile[@]}" | tail -1 | awk '{print $1}')
#this grabs the exit code of the last fired command here this would be tar
fi
END1=$(date +%s)
DIFF1=$(( $END1 - $START1 ))
echo "[ $date ] file extraction completed in $DIFF1 seconds"
movieFile=`find * -maxdepth 0 -type f | egrep '.avi$|.mp4$|.mkv$'`
#sampleDir=`find * -type d -iname 'sample*'`
#here lets rename movie file
movieFileExt="${movieFile##*.}"
echo "Renaming movie file to $filteredFileName.$movieFileExt"
mv "$movieFile" "$filteredFileName.$movieFileExt" #& progress -mp $!
finalMovieFileName=`echo "$filteredFileName.$movieFileExt"`
#@todo: another issue has cropped up how to deal with subs, here is the purposed logic flow
#subs dir is created on first layer of extraction
#inside subs dir we have a .rar when this is extracted we get an new dir this contains an .idx file and another .rar file
#this new dir will contain the word sub or subs (we need to use regex to search find this folder as its name is unique per movie file)
#then once into this dir we have another .rar to extract this then produces a .sub file
#so we now have a .idx file and a .sub file that need to get moved over and renamed to same name as movie file
#we will also need to rename the .idx and .sub files to match movie file
#turning on case insensitive matching
shopt -s nocasematch
#lets see if we can find it first, if present this should output Subs/
#subsDir=`ls -d *[sub]*/ | awk '{print $10}'`
#subsDir=`find * -maxdepth 0 -type d -print | grep '[Ss][Uu][Bb][Ss]'`
subsDir=`find * -type d -print | grep -v '\.avi$|\.mp4$|\.mkv$' | grep -v '\.[Rr][Aa0-9][Rr0-9]$' | grep '[Ss][Uu][Bb][Ss]'`
#first lets cd into the subs dir or only do so if it exists
#if [[ -d "$archiveDir/$PID/$baseFileName/subs" ]] || [[ -d "$archiveDir/$PID/$baseFileName/Subs" ]]
if [ -n "$subsDir" ]
then
#so we do have a subs dir now time to handle
#subsDir=`ls -d *[sub]*/ | awk '{print $10}'`
#change dirs into sub and continue with work this will already have a trialing /
cd "$archiveDir/$PID/$baseFileName/$subsDir" || exit
#here we have our first *should be* rar file
for s in *.rar;
do
mkdir -p "$archiveDir/$PID/$baseFileName/$subsDir/subSecond"
secondSubDir="$archiveDir/$PID/$baseFileName/$subsDir/subSecond"
#this will create a new dir inside the current dir we are in which should be subs
unrar e "$s" "$secondSubDir" #& progress -mp $!
#this grabs the exit code of the last fired command here this would be tar
#cd into this dir
cd "$secondSubDir" || exit
#need to discover what we have in here do we have both .idx and .sub files
#do we only have an .idx file and another rar to uncompress
subRarFile=`find * -maxdepth 0 -type f -iname "*.rar"`
#This will return true if a variable is unset or set to the empty string ("").
if [ -z "$subRarFile" ]
then
#@todo: new race condition presented what if there is cd1 and cd2 already extracted .idx and .sub
subIdxFile=`find * -maxdepth 0 -type f -iname "*.idx"`
subSubFile=`find * -maxdepth 0 -type f -iname "*.sub"`
#this means no other rars to decompress and we should have both our .idx and .sub files
#add full path info to both and return to main dir from previous where movie file is
#first lets rename both files and then move them to main work dir for this movie
subsIdxFileExt="${subIdxFile##*.}"
subsSubFileExt="${subSubFile##*.}"
mv "$subIdxFile" "$filteredFileName.$subsIdxFileExt"
mv "$subSubFile" "$filteredFileName.$subsSubFileExt"
#now move this to the main processing dir for movie file
#then load var to check if we have other files to then move when we move movie file
mv "$filteredFileName.$subsIdxFileExt" "$archiveDir/$PID/$baseFileName/"
mv "$filteredFileName.$subsSubFileExt" "$archiveDir/$PID/$baseFileName/"
#now move back to main movie dir where we were before we found we had subs
cd "$archiveDir/$PID/$baseFileName/" || exit
doWeHaveSubs=true
else
#this means we do have another rar file to extract and then we should have both files
unrar e "$subRarFile"
subIdxFile=`find * -maxdepth 0 -type f -name "*.idx"`
subSubFile=`find * -maxdepth 0 -type f -name "*.sub"`
subsIdxFileExt="${subIdxFile##*.}"
subsSubFileExt="${subSubFile##*.}"
mv "$subIdxFile" "$filteredFileName.$subsIdxFileExt"
mv "$subSubFile" "$filteredFileName.$subsSubFileExt"
#now move this to the main processing dir for movie file
#then load var to check if we have other files to then move when we move movie file
mv "$filteredFileName.$subsIdxFileExt" "$archiveDir/$PID/$baseFileName/"
mv "$filteredFileName.$subsSubFileExt" "$archiveDir/$PID/$baseFileName/"
#now move back to main movie dir where we were before we found we had subs
cd "$archiveDir/$PID/$baseFileName/" || exit
doWeHaveSubs=true
fi
done
else
doWeHaveSubs=false
fi
#turning off case insensitive matching
shopt -u nocasematch
#we should now have a newly created dir and movie file extracted and renamed next step
echo "Now moving created movie file to final destination"
#make sure to check that the network location destination volume exists
if mount | grep "$finalHomeDir" > /dev/null;
then
#its there exists and is up lets move the movie file
clear && echo "" && echo "Moving movie dir and file created to final destination"
mkdir -p "$finalHomeDir/$baseFileName"
#echo `mv "$finalMovieFileName" "$finalHomeDir/$baseFileName/" & progress -mp $!`
#mv "$finalMovieFileName" "$finalHomeDir/$baseFileName/" & progress -mp $!
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$movieFileExt" --exclude="*" "$finalMovieFileName" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line to only be run on linux
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.$movieFileExt" --exclude="*" "$finalMovieFileName" "$finalHomeDir/$baseFileName/"
#we need to move two more files if they exists subs .idx and .sub
#check our boolean var to see if we do need to include them in the move
if [ "$doWeHaveSubs" = true ]
then
finalSubIdxFile=`find * -maxdepth 0 -type f -name "*.idx"`
finalSubSubFile=`find * -maxdepth 0 -type f -name "*.sub"`
#mv "$finalSubIdxFile" "$finalHomeDir/$baseFileName/" & progress -mp $!
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.idx" --exclude="*" "$finalSubIdxFile" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line to only be run on linux
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.idx" --exclude="*" "$finalSubIdxFile" "$finalHomeDir/$baseFileName/"
#mv "$finalSubSubFile" "$finalHomeDir/$baseFileName/" & progress -mp $!
#rsync -p -a -v -z --stats --progress --protocol=30 --include="*.sub" --exclude="*" "$finalSubSubFile" root@192.168.0.44:/home/dberry/media/StorageDisk/"$baseFileName/"
#this line to only be run on linux
rsync -p -a -v -z --stats --progress --protocol=30 --include="*.sub" --exclude="*" "$finalSubSubFile" "$finalHomeDir/$baseFileName/"
fi
#move completed then cleanup
cd "$archiveDir/" || exit
echo "Removing pid dir "
rm -rf "$archiveDir/$PID"
#exit 1
else
echo "Network $finalHomeDir not present, aborting script"
exit 1
fi
done #second layer of decompress no cd1 cd2 dirs
fi
fi #checking if tar passes valid archive test
fi #checking if file exists
done
else
echo "Network mount for XtraLarge has gone away, fail"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment