Script to move and rename images in extrafanart and extrathumbs folders
#1
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:
  1. Iterate through all the movie folders that contain an extrafanart folder.
  2. Go into extrafanart/
  3. Delete fanart.<ext> if it exists (for me this is a duplicate of fanart.ext in the parent folder).
  4. 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.
  5. Move all the files from extrafanart to its parent folder.
  6. Do approximately the same with the extrathumbs folder, if there is one.
  7. Delete the extrafanart and extrathumbs folders.
It requires a setup with each movie in a separate folder.  It reports on the terminal which folders it is acting in.  It's best if you know something about scripts before using it.  There are some safety mechanisms built in, but I suggest copying several movies to a test directory and try it on that first.  I've used it on macOS and FreeBSD with no problems, so it might do well on other unixes too. 
  1. Paste the code into a raw text file.
  2. Adjust the shebang at the top to point to your bash (find it with command 'which bash').
  3. 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 '~')
  4. Save it.  I call mine fanart.sh
  5. Make it executable: 'chmod +x fanart.sh'
  6. 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
LibreELEC 10.0.4 * ViMediaManager or TinyMediaManager | Raspberry pi 4b
Sharing media from NAS via NFS (optical out to receiver, HDMI to TV) | TV remote with CEC / Bluetooth keyboard
Reply
#2
(2021-06-04, 02:17)Glorious1 Wrote: 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:
  1. Iterate through all the movie folders that contain an extrafanart folder.
  2. Go into extrafanart/
  3. Delete fanart.<ext> if it exists (for me this is a duplicate of fanart.ext in the parent folder).
  4. 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.
  5. Move all the files from extrafanart to its parent folder.
  6. Do approximately the same with the extrathumbs folder, if there is one.
  7. Delete the extrafanart and extrathumbs folders.
It requires a setup with each movie in a separate folder.  It reports on the terminal which folders it is acting in.  It's best if you know something about scripts before using it.  There are some safety mechanisms built in, but I suggest copying several movies to a test directory and try it on that first.  I've used it on macOS and FreeBSD with no problems, so it might do well on other unixes too. 
  1. Paste the code into a raw text file.
  2. Adjust the shebang at the top to point to your bash (find it with command 'which bash').
  3. 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 '~')
  4. Save it.  I call mine fanart.sh
  5. Make it executable: 'chmod +x fanart.sh'
  6. 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
Thanks for this script, used it to rename and move all of my extra fanart and thumbs for all of my movies and tv shows. Worked perfectly.
Reply

Logout Mark Read Team Forum Stats Members Help
Script to move and rename images in extrafanart and extrathumbs folders0