Advertisement
Guest User

process_tv_episode.sh

a guest
Jun 27th, 2010
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.00 KB | None | 0 0
  1. #!/bin/bash
  2. if [ ! -d "$1" ]; then
  3.     echo "Usage: `basename $0` <dir>"
  4.     echo "Processes files in <dir>"
  5.     exit 1
  6. fi
  7.  
  8. ERROR=0
  9. NODE="192.168.1.100"
  10. TARGETDIR=$1
  11. DATE=`date +%s`
  12.  
  13. find "$TARGETDIR" \( -name '*.mkv' -or -name '*.avi' \) -print0 | while read -d $'\0' VIDEO; do
  14.     FOLDER=`dirname "$VIDEO"`
  15.     FILE=`basename "$VIDEO"`
  16.     cd "$FOLDER"
  17.     FOLDERREMOTE=`echo "$FOLDER" | sed 's/\/media\/media/\/Volumes\/Media/g'`
  18.     START1=`date +%s`
  19.     echo `date +%H:%M:%S`": Processing ${FILE}..."
  20.     if [ `mediainfo "${FILE}" | grep DTS | wc -l` -gt 0 ]; then
  21.         echo `date +%H:%M:%S`": DTS track detected. Converting to AC3... "
  22.         ~/Dropbox/bin/mkvdts2ac3.sh -n "${FILE}"
  23.         if [ $? -eq 0 ]; then
  24.             echo `date +%H:%M:%S`": DTS->AC3 conversion complete. Continuing with encoding... "
  25.         else
  26.             echo `date +%H:%M:%S`": DTS->AC3 conversion failed. Skipping file..."
  27.             ERROR=1
  28.             continue
  29.         fi
  30.     fi
  31.     if [ "`ssh ${NODE} whoami`"  = "magu" ]; then
  32.         ssh $NODE "chmod 755 ~/Dropbox/bin/*; cd \"${FOLDERREMOTE}\" && ~/Dropbox/bin/convert_onepass.sh \"${FILE}\"" > "/tmp/convert.${FILE}.log" 2>&1
  33.         if [ ! $? -eq 0 ]; then
  34.             echo `date +%H:%M:%S`": Failed to convert ${FILE} to H.264"
  35.             ERROR=1
  36.             continue
  37.         fi
  38.     else
  39.         echo `date +%H:%M:%S`": Processing node not available. Using local CPU."
  40.         chmod 755 ~/Dropbox/bin/*
  41.         cd "${FOLDER}"
  42.         ~/Dropbox/bin/convert_onepass.sh "${FILE}" > "/tmp/convert.${FILE}.log" 2>&1
  43.         if [ ! $? -eq 0 ]; then
  44.             echo `date +%H:%M:%S`": Failed to convert ${FILE} to H.264"
  45.             ERROR=1
  46.             continue
  47.         fi
  48.     fi
  49.  
  50.     ~/Dropbox/bin/rename-file.py -a -f "${FILE%.*}.m4v" >> "/tmp/convert.${FILE}.log"
  51.  
  52.     if [ ! $ERROR -eq 0 ]; then
  53.         echo "Failed to rename ${FILE%.*}.m4v"
  54.         ERROR=1
  55.         continue
  56.     fi
  57. done
  58.  
  59. if [ $ERROR -eq 0 ]; then
  60.     cd "$TARGETDIR"
  61.     find . -size +100M -name '*.m4v' -exec mv '{}' "/media/media/Library/Automatically Add to iTunes" \;
  62.     exit 0
  63. else
  64.     exit 1
  65. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement