hroncok

subrnm

Dec 16th, 2011
1,050
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # BSDL Miro Hrončok <miro@hroncok.cz>
  3. # subrnm .avi .srt (or vice versa)
  4.  
  5. if [ $# -ne 2 ]; then
  6.     #echo "USAGE: subrnm .avi .srt (or vice versa)"
  7.     zenity --error --text "You have not chosen two files"
  8.     exit 1
  9. fi
  10.  
  11. # Which is which
  12. filename=$(basename "$1")
  13. extension=${filename##*.}
  14.  
  15. # Video first
  16. if [ "$extension" == "avi" ] || [ "$extension" == "mp4" ] || [ "$extension" == "crdownload" ]; then
  17.     #echo "First file is a video"
  18.     subtitles=$(basename "$2")
  19.     extension=${subtitles##*.}
  20.     if [ "$extension" != "srt" ] && [ "$extension" != "sub" ]; then
  21.         #echo "First file is a video. Second file are not subtitles"
  22.         zenity --error --text "First file is a video, but second file are not subtitles"
  23.         exit 1
  24.     fi
  25.     filename=${filename%.*}
  26.     dir=$(dirname "$1")
  27.     mv "$2" "$dir/$filename.$extension"
  28.     exit 0
  29. fi
  30.  
  31. # Subtitles first
  32. if [ "$extension" == "srt" ] || [ "$extension" == "sub" ]; then
  33.     #echo "First file are subtitles"
  34.     video=$(basename "$2")
  35.     videext=${video##*.}
  36.     if [ "$videext" != "avi" ] && [ "$videext" != "mp4" ] && [ "$videext" != "crdownload" ]; then
  37.         #echo "First file are subtitles. Second file in not a video"
  38.         zenity --error --text "First file are subtitles, but second file in not a video"
  39.         exit 1
  40.     fi
  41.     video=${video%.*}
  42.     dir=$(dirname "$2")
  43.     mv "$1" "$dir/$video.$extension"
  44.     exit 0
  45. fi
  46.  
  47. #echo "USAGE: subrnm .avi .srt (or vice versa)"
  48. zenity --error --text "First file is neither a video or subtitles"
  49. exit 1
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×