Advertisement
nugget2021

remove duplicate trickplay folders script#!/bin/bash RED='\033[0;31m' CYAN='\033[0;36m' RESET='\033

Jun 7th, 2025
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.02 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. RED='\033[0;31m'
  4. CYAN='\033[0;36m'
  5. RESET='\033[0m'
  6.  
  7. # The script runs and trickplay folders that don't match the name of the movie are removed.
  8. # in the sample below, the first trickplay folder would be removed since the movie has [pass1][transcoded] in the name
  9.  
  10. # find trickplay folders and write to txt file
  11. # this is what the find output looks like for trickplay folders
  12. # ./movies/Example movie 1 [1252]/Example movie 1 [1252][DV HDR10].trickplay
  13. # ./movies/Example movie 1 [1252]/Example movie 1 [1252][DV HDR10][pass1][transcoded].trickplay
  14. find -name *.trickplay > trickplay.txt
  15.  
  16. # find mkv and mp4 files and write to txt file
  17. # this is what the find output looks like for a movie file
  18. # ./movies/Example movie 1 [1252]/Example movie 1 [1252][DV HDR10][pass1][transcoded].mkv
  19. find -name *.mkv -o -name *.mp4 > movies.txt
  20.  
  21. # read the movies.txt file line by line
  22. while read movie
  23. do
  24.     # write only the basename without the extension to the log.txt for comparison later
  25.     # Example movie 1 [1252][DV HDR10][pass1][transcoded]
  26.     base=$(basename -s .mkv $(basename -s .mp4 "$movie"))
  27.     echo $base >> log.txt
  28. done < movies.txt
  29.  
  30. # read the trickplay.txt file line by line
  31. while read trickplay
  32. do
  33.     # Compare only the basename without the extension to log.txt from before
  34.     # Example movie 1 [1252][DV HDR10]
  35.     # Example movie 1 [1252][DV HDR10][pass1][transcoded]
  36.     base=$(basename -s .trickplay "$trickplay")
  37.  
  38.     # if the trickplay basename matches exactly in log.txt, keep it else remove it
  39.     if ( cat log.txt | grep -qFx "$base"); then
  40.         echo $base >> keep.txt
  41.     else
  42.         echo $base >> remove.txt
  43.         # rm trickplay folders not matching
  44.         rm "$trickplay" -r
  45.     fi
  46. done < trickplay.txt
  47.  
  48.  
  49. echo -e "${CYAN}List of mp4 and mkv files\n\n${RESET}"
  50. cat log.txt
  51. echo -e "\n\n${CYAN}List of trickplay to keep\n\n${RESET}"
  52. cat keep.txt
  53. if [ -f remove.txt ]; then
  54.     echo -e "\n\n${RED}List of trickplay folders removed${RESET}"
  55.     cat remove.txt
  56. fi
  57. rm *.txt
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement