Quick 'n dirty...
Assuming a file structure like:
Code: Select all
/home/mypc/movies/
|__ Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ folder.jpg
|__ movie.nfo
|__ logo.png
Code: Select all
#!/bin/bash
for folder in /home/mypc/movies/*
do
cd "$folder";
filename_for_rename_with_extension=$(find . -name *.avi -o -name *.mkv -o -name *.mp4);
filename_for_rename_trimmed=$(basename "$filename_for_rename_with_extension");
filename_for_rename="${filename_for_rename_trimmed%.*}";
for file in *;
do
foldername="$(basename "$folder")";
filename=$(basename "$file");
extension="${file##*.}"
if [ "$extension" = "jpg" ] || [ "$extension" = "png" ] || [ "$extension" = "nfo" ]; then
echo "$filename" "$filename_for_rename"-"$filename";
cp "$filename" "$filename_for_rename"-"$filename";
fi
done
cd ..;
done
Run in movie root (ex. /home/mypc/movies/), it jumps into the first folder (ex. /home/mypc/movies/Star Wars (1978)), looks for the movie file (ex. Star Wars 720p AC3.avi) .mkv .avi .mp4 and saves the name. Then, it takes all files in that folder and checks if they are .jpg .png .nfo and if they are, they 'll get renamed from folder.jpg to Star Wars 720p AC3-folder.jpg BUT the original folder.jpg will NOT be deleted. You have 2 files now! If you want the folder.jpg deleted after it was renamed use mv (move) instead of cp (copy) in the code!
Change
Code: Select all
cp "$filename" "$filename_for_rename"-"$filename";
to
Code: Select all
mv "$filename" "$filename_for_rename"-"$filename";
If you prefer the foldername-folder.jpg (Star Wars (1978)) you can change the code to
Code: Select all
cp "$filename" "$foldername"-"$filename";
which should give you Star Wars (1978)-folder.jpg
So, if chosing filename, this will be:
Code: Select all
Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ folder.jpg
|__ movie.nfo
|__ logo.png
|__ Star Wars 720p AC3-folder.jpg
|__ Star Wars 720p AC3-movie.nfo
|__ Star Wars 720p AC3-logo.png
if chosing the foldername, this will be:
Code: Select all
Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ folder.jpg
|__ movie.nfo
|__ logo.png
|__ Star Wars (1978)-folder.jpg
|__ Star Wars (1978)-movie.nfo
|__ Star Wars (1978)-logo.png
and with changing cp to mv the source files will be deleted:
Code: Select all
Star Wars (1978)
|__ Star Wars 720p AC3.avi
|__ Star Wars 720p AC3-folder.jpg
|__ Star Wars 720p AC3-movie.nfo
|__ Star Wars 720p AC3-logo.png
I'm not the best programmer in the world, but the script should do the trick.
Proposals for improvement are highly appreciated!
I hope this will help someone else regaring the artwork problem.