Advertisement
Guest User

TheHobbit.mkv

a guest
Oct 29th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.51 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. # Turns out the thing we all like to hate and bash can sometimes get its use in the most unlikely places.
  4.  
  5. if [ -z "$1" ] && [ "$1" == "--help" ] || [ "$1" == "-h" ] ; then
  6.   echo "Welcome to Peter Jackson's transcoding utility."
  7.   echo "Note: if you happen to own (one way 'arr the other) Peter Jackson's hobbit movies, you don't need to have LAME installed on your computer. All you need is to have The Hobbit (either of the three by Peter Jackson will do) in your computer's blu-ray or DVD drive, or stored in a folder on your computer (note: you must be able to access said folder). Movies contain more than enough lame moments to power this script for a month at least. Turns out the things we all like to hate on and bash (pun intended) can sometimes find their use in the most unlikely of places."
  8.   echo "Note 1: I haven't tested the script using Jackson's The Hobbit instead of LAME because they're worth neither my money nor my bandwidth."
  9.   echo "NOTE 2: FFmpeg is still required (newest stable will do), and LAME (likewise, newest stable will do) is of course preferred to Peter Jackson's The Hobbit movies. Unlike LAME, the movies aren't very 'stable' as they are fundamentally broken (few examples of known bugs: Azog, stone giants, things under the goblin mountain, legolass, Smaug with his insecurities (which probably stem from the fact he isn't a dragon but a wyvern instead) and of course, neither last nor least and (ironically) probably the biggest source of lameness in the movies so far: the barrel scene). As as result, they may segfault a lot. This may result in data loss (even without the -d option)."
  10.   echo "[Note 3: I am very much aware that only two movies were released at the time I was writting this script, but based on the first two movies the third won't be different.]"
  11.   echo "NOTE 4: This utility is recursive. It starts in current directory and checks all the subfolders. If audio files contained within [alan, please add supported filetypes] are not .mp3 files, they will get converted to mp3."
  12.   echo ""
  13.   echo ""
  14.   echo "Usage:"
  15.   echo "--help: displays this help"
  16.   echo "--test: doesn't do anything"
  17.   echo "--delete: forces delete of source"
  18.   echo "-d      : also forces delete of source"
  19.   echo "<using TheHobbit movies instead of legit LAME>: Also forces delete of source"
  20.   echo ""
  21.   exit 0
  22. fi
  23.  
  24. DELETE=false
  25.  
  26. for i in seq 1 $# ; do
  27.   if [ $$i == '-d' ] || [ $$i == '--delete' ] ; then
  28.     DELETE=true
  29.   fi
  30. done
  31.  
  32. function convertOne {
  33.   convertwaw "$1" $num
  34. }
  35.  
  36. function convertwaw {
  37.   ffmpeg -i "$1" -q:a 0 "$2.wav"
  38.  
  39.   if [[ $? -ne 0 ]] ; then
  40.     return #ker se lahko zgodijo napake
  41.   fi
  42.  
  43.   ffprobe -report "$1"
  44.   ARTIST=$(cat ffprobe-*.log | grep -i "ARTIST" | awk -F ': ' '{print $2}')
  45.   ALBUM=$(cat ffprobe-*.log | grep -i "ALBUM" | awk -F ': ' '{print $2}')
  46.   TITLE=$(cat ffprobe-*.log | grep -i "TITLE" | awk -F ': ' '{print $2}')
  47.   GENRE=$(cat ffprobe-*.log | grep -i "GENRE" | awk -F ': ' '{print $2}')
  48.   track=$(cat ffprobe-*.log | grep -i "track" | awk -F ': ' '{print $2}')
  49.   DATE=$(cat ffprobe-*.log | grep -i "DATE" | awk -F ': ' '{print $2}')
  50.   rm ffprobe-*.log
  51.  
  52.   convertmp3 $2 "$ARTIST" "$TITLE" "$ALBUM" "$DATE" "$track" "$GENRE" "$1" &
  53. }
  54.  
  55. function convertmp3 {
  56.   fname="$2 - $3.mp3"
  57.  
  58.   #Utegne se zgoditi, da metapodatkov ni. Ups.
  59.  
  60.   emptyString=""
  61.   if [ -z "$2" ] || [ -z $3 ] ; then
  62.     fname="${8%.*}.mp3"
  63.   fi
  64.  
  65.   printlnYellow "------------------"
  66.   printlnYellow "Pretvarjanje v mp3"
  67.   echo          "Ime datoteke: $fname"
  68.   echo          "Naslov:    $3"
  69.   echo          "Izvajalec: $2"
  70.   echo          "Album:     $4"
  71.   echo          "Leto:      $5; Zvrst: $7; Številka skladbe: $6"
  72.   printlnYellow "------------------"
  73.  
  74.   lame -V0  "$1.wav" "$fname" --ta "$2" --tt "$3" --tl "$4" --ty "$5" --tn "$6" --tg "$7"
  75.  
  76.   rm "$1.wav"
  77.   #if [ $DELETE ] ; then
  78.     rm "$8"
  79.   #fi
  80. }
  81.  
  82. function printlnYellow {
  83.   tput setaf 3
  84.   tput bold
  85.   echo "$@"
  86.   tput sgr0
  87. }
  88.  
  89. function search {
  90.   num=0
  91.   for f in * ; do
  92.     if [ -d "$f" ] ; then
  93.       cd "$f"
  94.       search
  95.       cd ..
  96.     elif [ $(echo "$f" | egrep .m4a$\|.flac$ -c) -gt 0 ] ; then
  97.       echo "Converting $f..."
  98.       printlnYellow "------------------------------------"
  99.       echo ""
  100.       echo ""
  101.       echo ""
  102.       printlnYellow " CURRENT NUMBER: $num "
  103.       echo ""
  104.       echo ""
  105.       echo ""
  106.       printlnYellow "------------------------------------"
  107.       convertOne "$f" $num
  108.       num=$(($num + 1))
  109.     fi
  110.   done
  111. }
  112.  
  113. search
  114.  
  115. echo "Fertik je!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement