LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-02-2016, 05:26 PM   #1
seanbw
LQ Newbie
 
Registered: May 2016
Posts: 7

Rep: Reputation: Disabled
Please help finish this code.


I am using openmediavault and so far so good. I need a code that moves different categories of download to different folders. The problem is that the code i got from pastie is quite old and the extensions are many. I have customised the TV section to sort on TV-SD and TV-HD but the movies section is way out of my league. I am a beginner to Linux and the way the code is linked looks unnecessarily complex but I'll take what I can get.
There are two areas I need help with. The movie areas - my downloads end with .avi, .mp4, .mkv and so on. I need the .avi to change to pick up anything where the extension is any of the following: .avi, .mkv, .mpg, .mp4, .vog,.mov,.3gp.
They all go into a ovies folder.
The second area is to make the code neater. The log is repeated throughout the file and I wanted to shorten it by using this definition: LOG_FOLDER="/home/USERNAME/.sabnzbd/logs/sab_proc.log" And then call it as $LOG_FOLDER but I noticed that the original developer used sed with his definition and that is just out of my league.
Can anyone please help? I really need this.

Code:
set -u
 
CATEGORY_NAME=`echo $1 | awk -F [/] '{print $(NF-1)}'`
 
echo $2 >> /home/.sabnzbd/logs/sab_proc.log
 
echo "Category: $CATEGORY_NAME" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
 
FOLDER_PATH="$1"
FOLDER_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $NF}'`
 
echo "Folder Path: $FOLDER_PATH" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
 
cd "$FOLDER_PATH"
 
####################
# Movie Processing #
####################
 
if [ $CATEGORY_NAME = "Movies" ]
then
        # Where do you want to put the movies that this script processes?
        MOVIE_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/Movies/"
 
        MOVIE_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
        echo "Movie Name: $MOVIE_NAME" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
       
        if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 2 ]
                then
                FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '1p' | sed 's/^\.//'`"
                FILEZ[2]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | sed -n '2p' | sed 's/^\.//'`"
                echo "Joining Files..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                mencoder -forceidx -ovc copy -oac copy -o "$FOLDER_PATH/$MOVIE_NAME".avi "${FILEZ[1]}" "${FILEZ[2]}"
                #Get the path for the avi
                FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sed 's/^\.//'`"
                echo "Making Folder..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                #Make Folder for the avi
                mkdir "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME"
                echo "Moving Files..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                #Move the avi to the folder
                mv "$FOLDER_PATH/$MOVIE_NAME.avi" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.avi"
                #If there's an nfo, move that into the folder as well
                        if [ `find . -regex '.*/.*\.nfo' | wc -l` -gt 0 ]
                                then
                                FILEZ[2]="$FOLDER_PATH`find . -regex '.*/.*\.nfo' | sed 's/^\.//'`"
                                mv "${FILEZ[2]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.nfo"
                                chmod 777 -R "${MOVIE_DESTINATION_DIRECTORY}"/"${MOVIE_NAME}"
                        fi
                rm -r "$FOLDER_PATH"  
                echo "Removing Folder: $FOLDER_NAME..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                else
                        if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
                                then
                                #Get the path for the avi
                                FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sed 's/^\.//'`"
                                echo "Making Folder..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                                #Make Folder for the avi
                                mkdir "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME"
                                echo "Moving Files..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                                #Move the avi to the folder
                                mv "${FILEZ[1]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.avi"
                                #If there's an nfo, move that into the folder as well
                                if [ `find . -regex '.*/.*\.nfo' | wc -l` -gt 0 ]
                                        then
                                        FILEZ[2]="$FOLDER_PATH`find . -regex '.*/.*\.nfo' | sed 's/^\.//'`"
                                        mv "${FILEZ[2]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.nfo"
                                        chmod 777 -R "${MOVIE_DESTINATION_DIRECTORY}"/"${MOVIE_NAME}"
                                fi
                                rm -r "$FOLDER_PATH"  
                                echo "Removing Folder: $FOLDER_NAME..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                        else
                                echo "Couldn't copy(too many files or no files?)" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                        fi
        fi
fi
 
#################
# TV-HD Processing #
#################
 
if [ $CATEGORY_NAME = "TV-HD" ]
        then
       
        echo "Beginning TV Processing..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
       
        ##Where is your root TV directory? This script will create folders in it, i.e. ROOT_TV/Seinfeld/Season 8/...
        TV_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV-HD"
 
        if [ `echo $FOLDER_NAME | awk -F " - " '{print NF}'` -ne 3 ]
                then
                echo "Folder name incorrect, quitting..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                exit 0
        fi
        OPT_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
       
        SHOW_NAME=`echo $OPT_NAME | awk -F " - " '{print $1}'`
       
 
        echo "Show Name: $SHOW_NAME" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        SEASON_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $1}'`
        echo "Season Number: $SEASON_NUMBER" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        EPISODE_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $2}'`
       
        if [ `find . -size +73400320c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
                then
                FILEZ[1]="$FOLDER_PATH`find . -size +73400320c -regex '.*/.*\.avi' | sed 's/^\.//'`"
                echo "One file found, making directories..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME"
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER"
                echo "Moving File..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                mv "${FILEZ[1]}" "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER/$OPT_NAME.avi"
                echo "Removing Folder..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                chmod 777 -R "${TV_DESTINATION_DIRECTORY}"/"${SHOW_NAME}"
                rm -r "$FOLDER_PATH"
                else
                echo "Couldn't copy(too many files or no files?)" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        fi
 
#################
# TV-SD Processing #
#################
 
if [ $CATEGORY_NAME = "TV-SD" ]
        then
       
        echo "Beginning TV Processing..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
       
        ##Where is your root TV directory? This script will create folders in it, i.e. ROOT_TV/Seinfeld/Season 8/...
        TV_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV-SD"
 
        if [ `echo $FOLDER_NAME | awk -F " - " '{print NF}'` -ne 3 ]
                then
                echo "Folder name incorrect, quitting..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                exit 0
        fi
        OPT_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
       
        SHOW_NAME=`echo $OPT_NAME | awk -F " - " '{print $1}'`
       
 
        echo "Show Name: $SHOW_NAME" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        SEASON_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $1}'`
        echo "Season Number: $SEASON_NUMBER" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        EPISODE_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $2}'`
       
        if [ `find . -size +73400320c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
                then
                FILEZ[1]="$FOLDER_PATH`find . -size +73400320c -regex '.*/.*\.avi' | sed 's/^\.//'`"
                echo "One file found, making directories..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME"
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER"
                echo "Moving File..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                mv "${FILEZ[1]}" "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER/$OPT_NAME.avi"
                echo "Removing Folder..." >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
                chmod 777 -R "${TV_DESTINATION_DIRECTORY}"/"${SHOW_NAME}"
                rm -r "$FOLDER_PATH"
                else
                echo "Couldn't copy(too many files or no files?)" >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
        fi
 

        echo "Done!" >> /home/sabnzbd/.sabnzbd/logs
fi
 
Old 05-03-2016, 01:41 AM   #2
rigor
Member
 
Registered: Sep 2011
Posts: 212

Rep: Reputation: Disabled
As far as shortening it and perhaps making it a bit easier to read, maybe something roughly like this:
Code:
#!/bin/bash

shopt -s expand_aliases

alias remove_leading_dot='cut -c2-'
alias grab_first_line='head -n 1'
alias grab_second_line='sed -n "2p"'

set -u

LOG_FOLDER="/home/$LOGNAME/.sabnzbd/logs/sab_proc.log"

function log_mesg()
{
    echo  $@  >>  $LOG_FOLDER
}

 
CATEGORY_NAME=`echo $1 | awk -F [/] '{print $(NF-1)}'`
 
echo $2 >> /home/.sabnzbd/logs/sab_proc.log
 
log_mesg  "Category: $CATEGORY_NAME" >> $LOG_FOLDER
 
FOLDER_PATH="$1"
FOLDER_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $NF}'`
 
log_mesg  "Folder Path: $FOLDER_PATH"
 
cd "$FOLDER_PATH"
 
####################
# Movie Processing #
####################
 
if [ $CATEGORY_NAME = "Movies" ]
    then
        # Where do you want to put the movies that this script processes?
        MOVIE_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/Movies/"
 
        MOVIE_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
        log_mesg  "Movie Name: $MOVIE_NAME"
       
        if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 2 ]
            then
                FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | grab_first_line | remove_leading_dot`"
                FILEZ[2]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | sort | grab_second_line | remove_leading_dot`"
                log_mesg  "Joining Files..."
                mencoder -forceidx -ovc copy -oac copy -o "$FOLDER_PATH/$MOVIE_NAME".avi "${FILEZ[1]}" "${FILEZ[2]}"

                # Get the path for the avi
                FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | remove_leading_dot`"

                # Make Folder for the avi
                echo "Making Folder..."
                mkdir "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME"

                # Move the avi to the folder
                log_mesg  "Moving Files..."
                mv "$FOLDER_PATH/$MOVIE_NAME.avi" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.avi"

                # If there's an nfo, move that into the folder as well
                if [ `find . -regex '.*/.*\.nfo' | wc -l` -gt 0 ]
                    then
                        FILEZ[2]="$FOLDER_PATH`find . -regex '.*/.*\.nfo' | remove_leading_dot`"
                        mv "${FILEZ[2]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.nfo"
                        chmod 777 -R "${MOVIE_DESTINATION_DIRECTORY}"/"${MOVIE_NAME}"
                fi

                ## Should this say removing $FOLDER_NAME or $FOLDER_PATH ?!
                log_mesg  "Removing Folder: $FOLDER_NAME..."
                rm -r "$FOLDER_PATH"  
            else
                if [ `find . -size +629145600c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
                    then

                        # Get the path for the avi
                        FILEZ[1]="$FOLDER_PATH`find . -size +629145600c -regex '.*/.*\.avi' | remove_leading_dot`"

                        # Make Folder for the avi
                        log_mesg  "Making Folder..."
                        mkdir "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME"

                        # Move the avi to the folder
                        log_mesg  "Moving Files..."
                        mv "${FILEZ[1]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.avi"

                        # If there's an nfo, move that into the folder as well
                        if [ `find . -regex '.*/.*\.nfo' | wc -l` -gt 0 ]
                            then
                                FILEZ[2]="$FOLDER_PATH`find . -regex '.*/.*\.nfo' | remove_leading_dot`"
                                mv "${FILEZ[2]}" "$MOVIE_DESTINATION_DIRECTORY/$MOVIE_NAME/$MOVIE_NAME.nfo"
                                chmod 777 -R "${MOVIE_DESTINATION_DIRECTORY}"/"${MOVIE_NAME}"
                        fi

                        ## Should this say removing $FOLDER_NAME or $FOLDER_PATH ?!
                        log_mesg  "Removing Folder: $FOLDER_NAME..."
                        rm -r "$FOLDER_PATH"  
                    else
                        echo "Couldn't copy(too many files or no files?)"
                fi
        fi
fi
 
#################
# TV-HD Processing #
#################
 
if [ $CATEGORY_NAME = "TV-HD" ]
    then
       
        log_mesg  "Beginning TV Processing..."
       
        ## Where is your root TV directory? This script will create folders in it, i.e. ROOT_TV/Seinfeld/Season 8/...
        TV_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV-HD"
 
        if [ `echo $FOLDER_NAME | awk -F " - " '{print NF}'` -ne 3 ]
            then
                log_mesg  "Folder name incorrect, quitting..."
                exit 0
        fi

        OPT_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
       
        SHOW_NAME=`echo $OPT_NAME | awk -F " - " '{print $1}'`
       
 
        log_mesg  "Show Name: $SHOW_NAME"
        SEASON_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $1}'`
        log_mesg  "Season Number: $SEASON_NUMBER"
        EPISODE_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $2}'`
       
        if [ `find . -size +73400320c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
            then
                FILEZ[1]="$FOLDER_PATH`find . -size +73400320c -regex '.*/.*\.avi' | remove_leading_dot`"

                log_mesg  "One file found, making directories..."
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME"
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER"

                log_mesg  "Moving File..."
                mv "${FILEZ[1]}" "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER/$OPT_NAME.avi"

                log_mesg  "Removing Folder..."
                chmod 777 -R "${TV_DESTINATION_DIRECTORY}"/"${SHOW_NAME}"
                rm -r "$FOLDER_PATH"
            else
                log_mesg  "Couldn't copy(too many files or no files?)"
        fi
fi

#################
# TV-SD Processing #
#################
 
if [ $CATEGORY_NAME = "TV-SD" ]
    then
       
        log_mesg  "Beginning TV Processing..."
       
        ## Where is your root TV directory? This script will create folders in it, i.e. ROOT_TV/Seinfeld/Season 8/...
        TV_DESTINATION_DIRECTORY=" /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV-SD"
 
        if [ `echo $FOLDER_NAME | awk -F " - " '{print NF}'` -ne 3 ]
            then
                log_mesg  "Folder name incorrect, quitting..."
                exit 0
        fi

        OPT_NAME=`echo $FOLDER_NAME | sed 's/ (.*)//g'`
       
        SHOW_NAME=`echo $OPT_NAME | awk -F " - " '{print $1}'`
       
 
        log_mesg  "Show Name: $SHOW_NAME"
        SEASON_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $1}'`
        log_mesg  "Season Number: $SEASON_NUMBER"
        EPISODE_NUMBER=`echo $OPT_NAME | awk -F " - " '{print $2}' | awk -F "x" '{print $2}'`
       
        if [ `find . -size +73400320c -regex '.*/.*\.avi' | wc -l` -eq 1 ]
            then
                FILEZ[1]="$FOLDER_PATH`find . -size +73400320c -regex '.*/.*\.avi' | remove_leading_dot`"

                log_mesg  "One file found, making directories..."
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME"
                mkdir "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER"

                log_mesg  "Moving File..."
                mv "${FILEZ[1]}" "$TV_DESTINATION_DIRECTORY/$SHOW_NAME/Season $SEASON_NUMBER/$OPT_NAME.avi"

                log_mesg  "Removing Folder..."
                chmod 777 -R "${TV_DESTINATION_DIRECTORY}"/"${SHOW_NAME}"
                rm -r "$FOLDER_PATH"
            else
                log_mesg  "Couldn't copy(too many files or no files?)"
        fi
 

        echo "Done!" >> /home/sabnzbd/.sabnzbd/logs
fi
Also, is there supposed to be only one log file, or is there a log file for each user and a master log file as well. For example, should:
Code:
echo $2 >> /home/.sabnzbd/logs/sab_proc.log
actually be:
Code:
echo $2 >> /home/sabnzbd/.sabnzbd/logs/sab_proc.log
Beyond that it would be helpful to actually see an example list of a few files that are in the directories in which the find commands in the script are being run, to help visualize what this script is meant to handle.

Last edited by rigor; 05-03-2016 at 04:10 PM.
 
Old 05-03-2016, 04:00 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Also would be nice to see what parameters ($1, $2, so on) you are passing to the script. I say this as many of the awk invocations seem to be pointless if they are working on a file path.

You could also look through the code and see if there is any repeated code that could be shifted to a function.
 
Old 05-03-2016, 08:31 AM   #4
seanbw
LQ Newbie
 
Registered: May 2016
Posts: 7

Original Poster
Rep: Reputation: Disabled
Ok. First- thanks for even responding. I am grateful.
Second, all I want the code to do is go through a list of folders and identify which is a movie file, music file or TV show by their endings. The Tv shows are different in that they are in a separate TV folder. I attach the screenshot of the folders and the sub folders.
How do I include pictures?
http://gavitex.com/share/a4oia2xq0 This is a Music subfolder and the usual endings are .mp3 and .mp4 and .vog. .ac* does not play on the linux server so I usually move them into my windows pc and convert them manually.
This was manually sorted and the point is I want this code to look at the terminations and move the folders to the respective folders i.e. Music, TV Shows/TV-HD , TV Shows/TV-SD, Movies/Sub Folder of Movie Name/*
This is a Movies sub folder: http://gavitex.com/share/yflrjc2us and as you can see the folder structure is a sub folder/sub folders. I can live with that same structure being moved to the movies folder. If I had a choice, I would prefer the code to move all the movies sub folder files into one sub folder so Movies/Sub Folder/Sub Folders become Movies/Sub Folder/.mkv, .nfo, .srt
This is the Comics folder manually sorted. URL=http://gavitex.com/share/x1xh4ejci]http://gavitex.com/share/x1xh4ejci[/URL]
Again you can see how I manually organised them into relevant folders based on names and series. Mylar actually does that now so I am happy with what Mylar will do when it starts working.
This is the main download folder that all the folders are downloaded into. It is from here that the code sorts, organises and moves the relevant files. The permission on all these folders is 0777so the code has no restrictions.http://gavitex.com/share/8xywupzrv
The downloads folder that needs sorting http://gavitex.com/share/5uhgyll7o
This is how the movies sub folder should look if it is properly sorted: http://gavitex.com/share/bcfgc4umu
I will not be passing any parameters to the code because all the folders are fixed in location and are part of a pool.
In summary, the way I will run it is this. In sabnzbd, I will point to this code. I will also run it as a cron job - daily.
The code will go to the download folder (there is only one) and will sort through all the sub folders. Identify which of the downloads is a movie, tv show or music. It will then go through each folder and say for a movie, move the following files to the relevant folder in the movie section after it has created a sub folder for it : .mkv, .srt and .nfo. After moving hese specific files, it will move the balance of the sub folder it has just sorted and moved to the recycle bin i.e. it deletes the rest of the files it does not see as required. It does the same for music. Music files end in .mp3 or .vog.
Same for Tv shows. The peculiarity with TV shows is this. TV-HD shows have a 1080p in the description and are saved in the TV-HD sub folder. It should just move them as appropriate i.e. files in the TV-Shows/TV-HD in the download area are moved to the appropriate sub folders in the TV-HD sub folder.
Did I make this clear or have I just confused the whole issue?
Do you want to log into my system to see it?
The log issue was my error. There should be only one log - this one: /home/sabnzbd/.sabnzbd/logs/sab_proc.log
Oh finally - I did look through the code. I modified the TV section as best as I could. The movies section was just out of my competence. Also the repetition of the log was annoying. I thought it should have been a function but I can't look a gift horse in the mouth. The provider has done his/her best. I should move on with my changes but I can't as I haven't got the skills.
Thank you for even looking.
 
Old 05-03-2016, 09:55 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Still not sure you have mentioned what parameters are passed to the script?
 
Old 05-03-2016, 04:00 PM   #6
seanbw
LQ Newbie
 
Registered: May 2016
Posts: 7

Original Poster
Rep: Reputation: Disabled
Red face

I apologise. I had not thought of the problem very well.
Since posting this problem, I have sorted out the folder structure to make it easier.
I am racking my brain to see if there are any parameters apart from these but I hope there are none else..
Parameters should be:
Source and destination directories:
Source Directory: Movies: /media/c6ef2c00-8574-410a-9ce7-f29c8edff709/Downloads/Downloads
TV : /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Downloads
Destination Directories: Movies: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/Movies/
TV Shows TV-HD: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Shows/TV-HD
TV-SD: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Shows/TV-SD
And the extensions: Movies = mp4, avi, mkv and vog.; Music extensions are : mp3 and mp4 and vog.; TV terminations are the same as movies.

These are the only parameters that are extraneous to the script and they could be coded into the script.
The other information to make up the folder names come from the downloaded files themselves e.g. say /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Downloads/Toni Braxton - Live in Lagos - 1989/Toni Braxton - Live in Lagos - 1989.mp3, Toni Braxton - Live in Lagos - 1989.nfo, Toni Braxton - Live in Lagos - 1989.srt, Toni Braxton - Live in Lagos - 1989.par2, Toni Braxton - Live in Lagos - 1989.txt
The script will move the folder containing the files Toni Braxton - Live in Lagos - 1989.mp3, Toni Braxton - Live in Lagos - 1989.nfo and Toni Braxton - Live in Lagos - 1989.srt to the folder : /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Shows/TV-HD/Toni Braxton - Live in Lagos - 1989/Toni Braxton - Live in Lagos - 1989.mp3, Toni Braxton - Live in Lagos - 1989.nfo and Toni Braxton - Live in Lagos - 1989.srt and delete the remaining files in the original folder after it has finished.
Since each type of download has its own program and folder, I can run instances of the program against each download folder at different times to reduce the load on the server.
So technically I can have the source, destination folders, and extensions to be the parameters?
I hope this is what you are asking for? The movies download folder contains only movies and the TV downloads contain only TV files because they are downloaded by different programs - sabnzbd and couchpotato for movies, sickbeard for TV downloads, Mylar downloads comics and have their own folder, Music is downloaded by another program and have their own folder. so I will run the program as a cron to clear each download folder.
The script will be run by couchpotato at say 6:00 AM and I may set it up as a cron to run at 15:00 daily. There are no extra parameter to pass apart from the above.
If the above structure will make the script difficult, I can combine all the downloads in one folder - the ~/Downloads/Downloads folder and the script will know which belongs to which by the folder names and terminations and move them accordingly.
thanks for your interest. Your questions have actually helped me firm up the problem.
 
Old 05-03-2016, 04:47 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I hope you do not get sick of my questions but parts of the code don't seem to gel with some of your information.

First I wanted to look at the example you have supplied:
Code:
/media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Downloads/Toni Braxton - Live in Lagos - 1989/ <-- This the top level folder but I have no idea with the code shown how we got here?

# Files in folder
Toni Braxton - Live in Lagos - 1989.mp3
Toni Braxton - Live in Lagos - 1989.nfo
Toni Braxton - Live in Lagos - 1989.srt
Toni Braxton - Live in Lagos - 1989.par2
Toni Braxton - Live in Lagos - 1989.txt

# Files to be transfered
Toni Braxton - Live in Lagos - 1989.mp3
Toni Braxton - Live in Lagos - 1989.nfo
Toni Braxton - Live in Lagos - 1989.srt

# TV extensions
mp4, avi, mkv and vog
For now I am not so worried about where they are going, but more on how we are choosing what to move.

So here are my questions:

1. Was this a mistaken example as we are in the TV Downloads directory but this only has a music file (mp3)?

2. Whether or not it is a TV show or Music, the only extensions we are aware of are mp4, avi, mkv and vog for TV and mp3, mp4 and vog for Music, how then do we know what other files to keep and which ones to delete?? In the example you keep nfo and srt, but delete par2 and txt, yet none of these are mentioned as known extensions.

Now the reason I was asking about the parameters is because of the lines below:
Code:
CATEGORY_NAME=`echo $1 | awk -F [/] '{print $(NF-1)}'`
echo $2 >> /home/.sabnzbd/logs/sab_proc.log
FOLDER_PATH="$1"
FOLDER_NAME=`echo $FOLDER_PATH | awk -F [/] '{print $NF}'`
Based on your examples of possible input:
Code:
Source Directory:
Movies: /media/c6ef2c00-8574-410a-9ce7-f29c8edff709/Downloads/Downloads
TV : /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Downloads

Destination Directories:
Movies: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/Movies/
TV Shows
 TV-HD: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Shows/TV-HD
 TV-SD: /media/6f1b1b52-a404-4bb7-a249-382b25b75801/TV Shows/TV-SD
Some of the above will give odd output based on which you use and what order. I am guessing that the destination is the first parameter and that you may need to include the trailing slash (/) on each one
otherwise the code will have an epic fail.

May I also ask what the idea / need is to have the '-size +629145600c' option is achieving? Are all your avi files going to be larger than this?
It also shows merging of the avi files ... is this a desired feature? It also seems if you have any avi files in more than 2 pieces it will bail out ... again, is this desired?

I think if it were me, I would sit back for a second and work out exactly what it is you needed done, then it will be easier to see if this script is doing what you need or if it is simpler to just write something new?
 
Old 05-03-2016, 06:53 PM   #8
rigor
Member
 
Registered: Sep 2011
Posts: 212

Rep: Reputation: Disabled
Also, although I don't necessarily know what shell you are using to run the script, there are multiple shells for which:
Code:
set -u
would treat missing parameters as errors. So from the script code, $1 and $2 would seem to be required. Indeed the script errors out for me if I try to run it without at least 2 parameters.

What seems to be the use of the first parameter has already been mentioned, and it appears that something related to the season, etc., for a TV series, is provided with the second parameter; but what is the purpose of what seems to be the required second parameter, when it comes to processing a movie?

Last edited by rigor; 05-13-2016 at 01:26 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ePSXe - I need terminal command line/code to install this from start to finish Michael Piziak Linux - Software 5 02-17-2016 12:18 PM
[SOLVED] Finish krtaylor5 Linux - Newbie 5 04-27-2012 04:03 PM
How to finish lfs status1 Linux From Scratch 31 03-19-2007 07:53 AM
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 02:37 AM
Does not finish completely Bernhard Linux - Software 2 02-06-2002 12:28 AM


All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration