Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am working on a script that reads all folders inside a Movie folder and outputs the information for each video in a file.

The current one I have is this:

movies=0
rm movielist
for dir in Movies/*
do
  (cd "$dir" && pwd|cut -d \/ -f5|tr -s '\n' ', ' >> ../../movielist &&
  >> ../../movielist )
echo "Movie $movies - $dir ADDED!"
let movies=movies+1
done

rm moviefinal
cat movielist | while read MovieName;
do 
    echo "$MovieName" | cut -d ',' -f2 | cut -d 'x' -f2 | sort | uniq | while read MovieRes;
    do
        case $MovieRes in
        [461-660]*)
            echo "$MovieName,480p" >> moviefinal
        ;;
        [661-890]*)
            echo "$MovieName,720p" >> moviefinal
        ;;
        [891-1200]*)
            echo "$MovieName,1080p" >> moviefinal
        ;;
        *)
            echo "$MovieName,DVD" >> moviefinal
        ;;
        esac
    done    
done

Which reads from the Movies folder each movie (eg: Movies/The Matrix/Matrix.mkv) and sends it to a file called moviex inside the Movies folder. The info inside the file is something like this:

The Matrix, 1920x1080, MKV
The Matrix 2, 1280x720, AVI
....

What I want to add now is a way to read the Height and Width (Which are the SourceImageHeight and SourceImageWidth with exiftool) and do a CASE or IF where, if the height is X and width is Z then add to the output file another variable which is the quality (ie: 720p, 1080p, DVD...). The above would look something like this:

The Matrix, 1920x1080, MKV, 1080p
The Matrix 2, 1280x720, AVI, 720p

UPDATE - The script is now showing the Quality (720p, 1080p) but the CASE part is wrong. It sometimes grabs for example a 720 video and gives it a DVD quaility, when in fact, in the script I explicitly said 720.

share|improve this question
add comment

1 Answer

Well the finished script is this if anybody in the future would want to do the same:

movies=0
rm movielist
for dir in Movies/*
do
  (cd "$dir" && pwd|cut -d \/ -f5|tr -s '\n' ', ' >> ../../movielist &&
    exiftool * -t -s3 -ImageSize -FileType|tr -s '\t' ',' >> ../../movielist )
echo "Movie $movies - $dir ADDED!"
let movies=movies+1
done

rm moviefinal
cat movielist | while read MovieName;
do 
    echo "$MovieName" | cut -d ',' -f2 | cut -d 'x' -f2 | sort | uniq | while read MovieRes;
    do
        if (($MovieRes>=461 && $MovieRes<=660))
        then
            echo "$MovieName,480p" 
        elif (($MovieRes>=661 && $MovieRes<=890))
        then
            echo "$MovieName,720p" 
        elif (($MovieRes>=891 && $MovieRes<=1200))
        then
            echo "$MovieName,1080p"
        else
            echo "$MovieName,DVD" 
        fi >> moviefinal
    done    
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.