#!/bin/sh
mkdir -p 720p 1080p 2160p SD FIX
find . -type f | while read file;
do
    unset w
    w="$(mediainfo --Output="Video;%Width%" "$file")"
    [ -z $w ] && continue
    printf '%s | %s\n' "$w" "$file";
    if [ $w -ge 16000 ]; then
        mv "$file" FIX/
    elif [ $w -ge 3200 ]; then
        mv "$file" 2160p/
    elif [ $w -ge 1700 ]; then
        mv "$file" 1080p/
    elif [ $w -ge 1200 ]; then
        mv "$file" 720p/
    else
        mv "$file" SD/
    fi
done
find . -empty -delete
