This is my first post on StackOverflow. Be gentle. :)
I have a linux server on which I download television shows and manually move the files to the appropriate folders for my Plex server. I would like to automate this process. I got as low as possible.
Show.Name.SeasonNumberEpisodeNumber.HDTV.X264.etc File Naming Convention ...
Example: almost. Person. S01E01.720p.HDTV.X264.mkv
NOTE. The display name may have a different length with. between each word in the name.
I can extract the show folder name from the file name.
#!/bin/bash
readonly FILEPATH=~/downloads
readonly SAVEPATH=~/shows
for file in $FILEPATH/*.mkv
do
foldername=$(basename "${file%.S0*}" | tr '.' ' ')
done
Problems:
- .
SxxExx, .
, , S01 1,
.
Resulting Copy ( )
cp Almost.Human.S01E01.720p.HDTV.X264.mkv shows/Almost Human/Season 1
sed regex, , , "".
!
UPDATE
! , .
. Plex , " ", .
, CRON.
#!/bin/bash
readonly FILEPATH=~/downloads
readonly SAVEPATH=~/shows
for file in $FILEPATH/*.mkv
do
dfile="$SAVEPATH/$(basename "$file" | sed -e 's/\./ /g' -e 's?\(.*\) [Ss]\([0-9][0-9]\)[Ee]\([0-9][0-9]\) .*?\1/Season \2/\1 - S\2E\3.mkv?')"
if [ ! -f "$dfile" ]
then
cp -v "$file" "$dfile"
mkdir -p "$(dirname "$dfile")"
else
echo "file exists "$dfile""
fi
done