2021-06-04, 02:17
I recently noticed my extrafanart was not showing, and with a bit of reading found that extrafanart folders are passé. I think the same must be true for extrathumbs. I wrote a bash script that does the following:
- Iterate through all the movie folders that contain an extrafanart folder.
- Go into extrafanart/
- Delete fanart.<ext> if it exists (for me this is a duplicate of fanart.ext in the parent folder).
- Rename all the image files (jpg, jpeg, png) as fanart1, fanart2, etc, retaining the original file extension. It is set to sort images by size on the assumption larger is better. So fanart1 is the largest file and the last one is the smallest.
- Move all the files from extrafanart to its parent folder.
- Do approximately the same with the extrathumbs folder, if there is one.
- Delete the extrafanart and extrathumbs folders.
- Paste the code into a raw text file.
- Adjust the shebang at the top to point to your bash (find it with command 'which bash').
- Change the variable 'movie_folder' on line 5 to the path to your TEST MOVIES. If you have spaces in the path, you'll need to put it in quotes and give the full path (no '~')
- Save it. I call mine fanart.sh
- Make it executable: 'chmod +x fanart.sh'
- Run it on your test directory. If all goes well you can change 'movies_folder' to the real one.
bash:#!/bin/bash # for my Mac
# movie_folder=~/Media/Movies # for my Mac
# movie_folder=/mnt/Ark/Media/Movies # for my FreeNAS
movie_folder=~/Media/Movies
for dir in "$movie_folder"/*/extrafanart
do
echo $dir
cd "$dir"
# First remove fanart.ext.
# For me, if it exists, it's a duplicate of one in parent folder
rm -f fanart.jpg
rm -f fanart.jpeg
rm -f fanart.png
# Now the extrafanart. This is where the magic happens:
# ls -1pS 1 makes one entry per line, p puts slash after directory names, S sorts by size
# egrep makes sure we're just going to do images, for safety
# cat -n numbers output lines
# while read reads each line, splitting into words, so n is the number, f the filename
# mv -n prevents overwriting
ls -1pS | egrep "(jpg|jpeg|png)$" | cat -n | while read n f; do mv -n "${f}" "../fanart$n.${f#*.}"; done
cd ..
# Same for extrathumbs if exists, but don't need to rename
if [ -d extrathumbs ]; then
cd extrathumbs
ls | egrep "(jpg|jpeg|png)$" | cat -n | while read n f; do mv -n "${f}" "../${f}"; done
cd ..
fi
rm -Rf extrafanart/
rm -Rf extrathumbs/
done