Advertisement
roderickvd

renamesubs.sh

Dec 5th, 2013
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.32 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # renamesubs.sh - Rename .en.srt and .nl.srt to .srt files
  4. # Tested on Synology DSM 4.3-3810 Update 1 (BusyBox v1.16.1)
  5.  
  6. # INSTALLATION INSTRUCTIONS:
  7. #
  8. #  1. Place script somewhere, e.g. /usr/local/scripts/renamesubs.sh
  9. #  2. Configure DIRECTORY and PERMS variables below
  10. #  3. Make script executable: chmod a+x /usr/local/scripts/renamesubs.sh
  11. #  4. Optionally: schedule script to run using Task Scheduler or cron
  12.  
  13. # Directory to scan for SRT files (will follow symbolic links)
  14. DIRECTORY=/volume1/video
  15.  
  16. # Permissions to set SRT files to
  17. PERMS=666
  18.  
  19. # Step 1: Remove English subtitles if they have a Dutch counterpart,
  20. # otherwise rename them into place and fix permissions
  21. find "$DIRECTORY" -follow -iname \*.en.srt | while read EN_SUB
  22. do
  23.     NL_SUB=`echo "$EN_SUB" | sed 's/\.en\.srt$/\.nl\.srt/I'`  
  24.     STRIPPED_SUB=`echo "$EN_SUB" | sed 's/\.en\.srt$/\.srt/I'`  
  25.     if [ -e "$NL_SUB" -o -e "$STRIPPED_SUB" ]; then
  26.         rm "$EN_SUB"
  27.     else
  28.         mv "$EN_SUB" "$STRIPPED_SUB"
  29.     fi
  30. done
  31.  
  32. # Step 2: Rename Dutch subtitles into place
  33. find "$DIRECTORY" -follow -iname \*.nl.srt | while read NL_SUB
  34. do
  35.     STRIPPED_SUB=`echo "$NL_SUB" | sed 's/\.nl\.srt$/\.srt/I'`
  36.     mv "$NL_SUB" "$STRIPPED_SUB"
  37. done
  38.  
  39. # Step 3: Fix permissions
  40. find "$DIRECTORY" -follow -iname \*.srt -exec chmod $PERMS {} \;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement