0

I am not sure how to approach on moving files based on their name into their respective directories. Basically, I have a bunch of tv shows that start like tvshowname.season.episode.ext or tv.show.name.season.episode.ext. I have directories named Show Name, Show Name1, Show Name2, etc. I would like to copy the files based on their name into the directories with the same name.

Current Files

Game of Thrones
Shooter
The Curse of Oak Island  
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mkv
Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA.mp4
Real Vikings
Van Helsing

So far I have made this

    #!/bin/bash
for FILE in "`ls *.{mp4,mkv}`"
do
        filename=$(basename "$FILE")
        extension=${filename##*.}
        filename=${filename%.*}
echo $filename
done

The issue that I am running into now, is how to get the first few words or at least the name of the show from the file name itself. Then move it into the directory based on that name. Each directory is listed as The Flash, The Curse of Oak Island, etc.

  • For starters, don't parse ls. You should be able to look at the manual for mmfpeg for extracting titles and other metadata from video files. What have you tried? – DopeGhoti Dec 8 '16 at 21:05
  • Please provide a sample set of source file names and the corresponding results that you would like to see. (In your question.) – roaima Dec 8 '16 at 21:19
  • Added the info, hopefully its what you were looking for. @DopeGhoti So far, I have looked into using mediainfo but I am having trouble parsing its data. I have also noticed that some of the files fail to actually list a proper name. So the name within mediainfo, is show the exact same name as the file name – Ryahn Dec 8 '16 at 21:24
0

Maybe this will help you start:

#!/bin/bash
for f in *.{mp4,mkv}           # no need to use ls.
do
    filename=${f##*/}          # Use the last part of a path.
    extension=${f##*.}         # Remove up to the last dot.
    filename=${filename%.*}    # Remove from the last dot.
    dir=${filename#tv}         # Remove "tv" in front of filename.
    dir=${dir%.*}              # Remove episode
    dir=${dir%.*}              # Remove season
    dir=${dir//.}              # Remove all dots.
    echo "$filename $dir"
    if [[ -d $dir ]]; then     # If the directory exists
        mv "$filename" "$dir"/ # Move file there.
    fi
done
  • It seems to do what I would like but the directory its listing is not correct. I will try an play with it but so far its listing Van.Helsing.S01E08.Little.Things.720p.WEB-DL.DD5.1.H264-DRACULA VanHelsingS01E08LittleThings720pWEB-DLDD5 and VanHelsingS01E08LittleThings720pWEB-DLDD5 would need to be Van Helsing Thank you for the answer. Its a step in the right direction – Ryahn Dec 8 '16 at 21:28
  • @Ryahn Your question stated season.episode.ext, the script is assuming that. Not season.episode.Little.Things.720p.WEB-DL.DD5.1.H264-DRAC‌​ULA and what not. Please be specific on what you ask so we can be more specific on what we answer. – sorontar Dec 8 '16 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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