Introducing… *drum rollz*

The One Script to rule them all… 😆

Updated today Nov. 17, 2011

This post will be the natural successor to this one.

## Source of inspiration.
/etc/init.d/SCRIPT -> /lib/init/upstart-job

I took the liberty to recombine my three most used scripts into one. 😉
Its usage is simple:

## The scale and quote scripts take additional parameter(s).
## For 'scale': 4cif, pal or hd are the only options at the moment.
## But feel free to add your own.
## All others: script.name file.name
you@somewhere:~$ ./scale.avi name-of-your-movie.avi (4cif, pal, hd)
e.g.: ./scale.avi name-of-your-movie.avi hd # Upscale file to "$HD" i.e. 1280x720
you@somewhere:~$ ./quote.avi name-of-your-movie.avi (Start End (Either in whole seconds or HH:MM:SS.MSS))
e.g.: ./quote.avi name-of-your-movie.avi 30 60 # Starts at 30s and has a duration of 60s.
e.g.: ./quote.avi name-of-your-movie.avi 60 # Starts at 0s and has a duration of 60s.
you@somewhere:~$ ./xtract.z.avi name-of-your-movie.avi
## Or: (if the script is within your "$PATH"?
scale.avi name-of-your-movie.avi hd # Upscale file to "$HD" i.e. 1280x720
quote.avi name-of-your-movie.avi 30 60 # Starts at 30s and has a duration of 60s.
quote.avi name-of-your-movie.avi 59,04 # Starts at 0s and has a duration of 59.040s.
xtract.z.avi name-of-your-movie.avi
xtract.z.flv name-of-your-movie.flv # I.e. Youtube or equiv. ; - )
## 'z'? equals 'from' ; - )

As for one’s “$PATH”.

# http://linuxcommand.org/wss0010.php
## His Pah is very strong. : - )
## Insert the following in your ~/.bashrc
## Preferably at the end!
## What I use.
# PATH=$PATH:$HOME/.usr/bin
PATH=$PATH:$HOME/your/folder/of/choice
export PATH
## Then all scripts you create and which are placed in "$PATH"
## Can be executed from anywhere you have permission to execute those.
#
## Otherwise you'll have to 'cd' to the folder where your script lives and
## do: ./your-script with-whatever-options-you-have-concocted with-file.ext
## Oh, don't forget to do: chmod u+x on your script first.

In my enthusiasm to post this asap I forgot to mention that for one this script allows you to copy and paste directly from e.g. nautilus. 🙂

But (what I as well forgot to mention):
Your folders and files will be RENAMED if either of those contains space(s)!!! If you don’t want that to happen then simply renaming your file(s), and if applicable your folder(s), before running this script should do the trick. 😉

## When copied from nautilus:
## From:
file:///your/file/at%20some%20where/with%20nasty%20spaces.ext
## To:
/your/file/at.some.where/with.nasty.spaces.ext
## When using tab completion in your shell.
## Type and, if exist, tab until completion.
## From:
/your/file/at\ some\ where/with\ nasty\ spaces.ext
## To:
/your/file/at.some.where/with.nasty.spaces.ext

You might just want to save the following few lines just below for posterity’s sake!? 😉 Why? Well… In order for the script posted on this page to work you’ll have to embrace the concept of linking!

## You might just want to save the following few lines just below for posterity's sake. ; - )
SCRIPT="$(basename "$0")"
for FILE in quote.o{ga,gg,gm} quote.flac quote.avi quote.m{p2,p3,p4,pe,peg,pg,kv} quote.w{mv,av};do ln -s -T "${SCRIPT}" "$(echo "${FILE}")";done
for FILE in scale.o{gg,gm} scale.flac scale.avi scale.m{p4,pe,peg,pg,kv} scale.wmv;do ln -s -T "${SCRIPT}" "$(echo "${FILE}")";done
for FILE in xtract.z.o{gg,gm} xtract.z.avi xtract.z.flv xtract.z.m{p4,pe,peg,pg,kv} xtract.z.wmv;do ln -s -T "${SCRIPT}" "$(echo "${FILE}")";done

Part 1. Its head.

#!/bin/bash
# Modified: Today by E.L.F.
#
## Licensed as:
## http://www.opensource.org/licenses/mit-license.php
#
## Script-name - skel.sh
#
set -e
if [ "$USER" = root ];then
  echo -e ${RED}"Are you Insane!"${NC}
  echo -e ${RED}"Error: In order to use this script, one must NOT be "$USER""${NC}
  echo -e ${YELLOW}"Exiting..."${NC}
  exit 0
else
  echo ""
  echo -e ${BLUE}"    "$USER" may proceed."${NC}
  echo -e ${CYAN}"    May peace be with you."${NC}
fi
clear
for COMMAND in mencoder ffmpeg oggenc cat
do COMMAND=$(which "$COMMAND")
if [ ! -x "$COMMAND" ];then RESULT=NO
echo -e ${YELLOW}"    Please install "${COMMAND}" first before continuing.${NC}
${CYAN}sudo apt-get install "$(basename "${COMMAND}")""${NC};fi
done
if [ "$RESULT" = NO ]; then echo -e ${BLUE}"See (for example):${NC}${YELLOW} http://ubuntuforums.org/showthread.php?t=766683${NC}${BLUE} for more info on the matter."${NC};exit 0;fi
## Variables for the 'scale' command.
date="$(date +"%A, %B %-d, %Y")"
copy=$(echo "Up to you.")
publisher=$(echo "Up to you.")
UPS_EXT=.mkv
HD=1280x720
PAL=720x576
_4CIF=704x576
## Variables for the 'quote' command.
## If 'START' is 'empty' then.
ZERO=00:00:00.000
## If 'END' is 'empty' then.
HALF=00:00:30.000
## Variables for the 'xtract.z' command.
## Print working directory.
PWD=$(pwd)
## Scriptname.
SCRIPT="$(basename "$0")"
## 'basename' of the script.
BASE="$(basename ${SCRIPT%.*})"
## Its 'extension'.
EXT="${SCRIPT/${BASE}/}"
## End variables!
## What would you have your 'arbiter' do.
for OPTION in "${BASE}";do OPTION="${OPTION}";done
for CHOICE in "${EXT}";do CHOICE="${CHOICE}";done
#  ## When no argument is given, print its usage.
  if [ "$BASE" = scale ];then USAGE=$(echo "Usage: "${SCRIPT}" yourfile"${EXT}" 4cif, pal, hd")
  elif [ "$BASE" = quote ];then USAGE=$(echo "Usage: "${SCRIPT}" yourfile"${EXT}" Start End (Either in whole seconds or HH:MM:SS.MSS)")
  else USAGE="Usage: "${SCRIPT}" yourfile"${EXT}"";fi
  if [ "$#" == "0" ];then echo -e ${YELLOW}"$USAGE"${NC};exit 0;fi

Part 2. Its body part 1.

case "$OPTION" in
"cat" | "create")
  if [ "$#" == 1 ];then OUTPUT="$1";OUTPUT+="${EXT}";else echo -n "Enter filename: ";read OUTPUT;OUTPUT+="${EXT}";fi
  echo "$OUTPUT"
  case "$OPTION" in
  "cat")
    case "$CHOICE" in
    ".avi" | ".vob" | ".wmv")
    # LS=$(ls *.{avi,mp{e,eg,g},wmv} 2>/dev/null)
    LS=$(ls *"${EXT}" 2>/dev/null)
    echo "$LS"
    mencoder -forceidx -oac copy -ovc copy $(ls *.avi | sort -n) -o "$OUTPUT"
    mv "$OUTPUT" ../"$OUTPUT"
    \rm *"${EXT}" 2>/dev/null
    mv ../"$OUTPUT" .
    ;;
    ".mpg")
    VAR="mpg-files.txt"
    ls *.mp{e,eg,g} 2>/dev/null | sort > $VAR
    cat $VAR | while read line; do
    INPUT=$(echo ${line})
    cat "$INPUT" >> "$OUTPUT"
    done
    \rm $VAR
    mv "$OUTPUT" ../"$OUTPUT"
    \rm *.mp{e,eg,g} 2>/dev/null
    mv ../"$OUTPUT" .
    ;;
    esac
  ;;
  "create")
    echo "#EXTM3U" > "$OUTPUT"
    find -iname '*.ogg' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp2' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp3' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp4' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mpg' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.wma' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.flv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.f4v' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.avi' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mkv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.wmv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    ;;
  esac
;;

Part 3. Its body part 2 (Ah, IT has no tail :lol:).

"scale" | "quote" | "xtract.z")
  ## Does the filename contain spaces.
  URLENC=$(echo "$1" | sed -e "s_%20_\\ _g")
  if [ -n "${URLENC}" ];then DIR=${URLENC/file:\/\//};else DIR="${DIR}";fi
  ## If so, then move the file into a more 'workable' state.
  MOVED=$(echo "${DIR}" | sed -e "s_\\ _._g")
  if [ -f "${MOVED}" ];then DIR="${DIR}";else mv "${DIR}" "${MOVED}";DIR=${MOVED};fi
  ## Filename. <-- Everything is a 'file' or should I say 'object'.
  FILE=$(basename "${DIR}")
  ## Its 'basename'.
  BASEF=$(basename ${FILE%.*})
  ## Its 'extension'.
  EXTF="${FILE/${BASEF}/}"
  ## Name of out-file.
  OUTPUT=$(basename ${DIR%.*})
  ## Uh oh! 'Error' time.
  if [ ! -f "$DIR" ];then echo -e ${YELLOW}"    The file: "$DIR" doesn't exist!${NC}\n${RED}    Exiting...!!!"${NC}; exit 0;fi
  if [ ! "$EXT" = "$EXTF" ];then
  echo -e ${YELLOW}"  You made a typo!?${NC} ${CYAN}*auto-correcting*${NC}\n
  ${BLUE}From:${NC} ${YELLOW}"$SCRIPT" "${DIR}"${NC}\n
  ${BLUE}To:${NC} ${YELLOW}  "$BASE""$EXTF" "${DIR}""${NC}
  echo
  SCRIPT="$BASE""$EXTF"
  unset EXT
  EXT="${SCRIPT/${BASE}/}"
  sleep 1
  fi
  case "$OPTION" in
  "scale")
    if [ -f "$DIR" ];then
    if [ "$#" == "1" ];then DIR="$DIR";RES=pal;else
    for RES in "$2";do RES=${RES};done
    case "${RES}" in
      "4cif" )
      RES="$HD"
      ;;
      "pal" )
      RES="$PAL"
      ;;
      "pal" )
      RES="$_4CIF"
      ;;
      *)
      echo -e ${YELLOW}"    Please choose a valid option!"${NC}
      echo -e ${BLUE}"    "Usage:"${NC} ${CYAN}"$SCRIPT" "$DIR"${NC} |${CYAN}"4cif"${NC}|${CYAN}"pal"${NC}|${CYAN}"hd"${NC}|"
      exit 0
      ;;
    esac
    fi
    OUTPUT+="$UPS_EXT"
    ffmpeg -y -i "$DIR" \
    -acodec copy \
    -alang eng \
    -vlang eng \
    -metadata title=""$(basename "$OUTPUT" "$UPS_EXT")". ®" \
    -metadata artist=""$USER"" \
    -metadata date="$date" \
    -metadata publisher="$publisher" \
    -metadata copyright="$copy" \
    -vcodec libx264 -vpre lossless_ultrafast -crf 18 \
    -s "$RES" \
    "$OUTPUT"
    fi
  ;;
  "quote")
    if [ -f "$1" ];then
      if [ "$#" == "3" ];then START="$2" && DUR="$3"
      elif [ "$#" == "2" ];then START="${ZERO}" && DUR="$2"
      else [ "$#" == "1" ]
        echo -e ${BLUE}"\tEither in seconds or...,"${NC}
        echo -e ${BLUE}"\tHH:MM:SS.MSS or...,"${NC}
        echo -e ${BLUE}"\tPress enter for starts at 0."${NC}
        echo -en "\tEnter Start Position : "
        read START
        echo -e ${BLUE}"\tEither in seconds or...,"${NC}
        echo -e ${BLUE}"\tHH:MM:SS.MSS"${NC}
        echo -e ${BLUE}"\tPress enter for lasts 30 seconds."${NC}        
        echo -en "\tEnter Duration : "
        read DUR
      fi
      if [ -z "$START" ];then START="${ZERO}";fi
      if [ -z "$DUR" ];then DUR="${HALF}";fi
      for DIGITS in "$START" "$DUR";do
      if [[ "$DIGITS" =~ [^\ 0-9.,:]+ ]];then exit 0;fi
      done
      ## Arg "$2" NEEDS TO BE "QUOTED", e.g. "00 01 30.200"! But at least it works now. ; - )
      SPACE=$(echo "$START" | sed -e "s_\\ _:_g")
      if [ -n "$SPACE" ];then START="$SPACE"
      else start=${START%[ .,_-]*};end=${START/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        START="$start"."$end"
      fi
      ## My num pad doesn't have a dot but uses comma instead.
      COMMA=$(echo "$START" | sed -e "s_,_._g")      
      if [ "$COMMA" = . ];then COMMA="${ZERO}";fi
      if [ -n "$COMMA" ];then START="$COMMA"
      else start=${START%[ .,_-]*};end=${START/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        START="$start"."$end"
      fi
      SPACE=$(echo "$DUR" | sed -e "s_\\ _:_g")
      if [ -n "$SPACE" ];then DUR="$SPACE"
      else start=${DUR%[ .,_-]*};end=${DUR/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        DUR="$start"."$end"
      fi
      COMMA=$(echo "$DUR" | sed -e "s_,_._g")
      if [ "$COMMA" = . ];then COMMA="${HALF}";fi      
      if [ -n "$COMMA" ];then DUR="$COMMA"
      else start=${DUR%[ .,_-]*};end=${DUR/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        DUR="$start"."$end"
      fi
      echo -e ${YELLOW}""${START}""${NC}
      echo -e ${YELLOW}""${DUR}""${NC}      
    OUTPUT+=.quote"$EXT"
    if [ "$EXT" = .oga ] || [ "$EXT" = .ogg ] || [ "$EXT" = .flac ] || [ "$EXT" = .wav ] || [ "$EXT" = .mp3 ];then Choice=AUDIO;else Choice=VIDEO;fi
      case "$Choice" in
      "AUDIO")
      echo -e ${BLUE}"\tffmpeg -y -i "$1" -ss "${START}" -t "${DUR}" -acodec copy -vn "${OUTPUT}""${NC}
      ;;
      "VIDEO")
      echo -e ${BLUE}"\tmencoder -ss "${START}" -endpos "${DUR}" -oac copy -ovc copy "$1" -o "${OUTPUT}""${NC}
      ;;
      esac
    fi
  ;;
  "xtract.z")
    if [ -f "$DIR" ];then WD=ripped/"${BASEF}";OUTPUT=${PWD}"/"${WD}"/"${BASEF};[ ! -d "${WD}" ] && mkdir -p "${WD}"
    ffmpeg -y -threads 2 -i "${DIR}" -vn -acodec pcm_s16le -ac 2 "${WD}"/${BASEF}.wav
    ffmpeg -y -threads 2 -i "${WD}"/${BASEF}.wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "${WD}"/${BASEF}.mp3
    oggenc "${WD}"/${BASEF}.wav -q 9
    ffmpeg -y -threads 2 -i "${DIR}" -an -vcodec copy "${WD}"/${BASEF}.rip.avi
    fi
  ;;
  esac
;;
esac
exit 0

Part 4. Its “tail” (Well sort of. :lol:).

Questions, suggestions, bugs found!? Feel free to let me know at this address: http://wp.me/PNJrg-p. Will I answer? That depends entirely upon you. ; - ) If you found a flaw/bug and you want me to point you out for that on here, then just say so. Otherwise all other email will be processed confidentially.

The actual script live and for the taking.

#!/bin/bash
# Modified: Today by E.L.F.
#
## Licensed as:
## http://www.opensource.org/licenses/mit-license.php
#
## Script-name - skel.sh
#
set -e
if [ "$USER" = root ];then
  echo -e ${RED}"\tError:${CYAN} \""$USER"\"${YELLOW} isn't allowed to use this script!"${NC};exit 0
else
  echo -e ${BLUE}"\t"$USER" may proceed.\n\t${CYAN}May peace be with you."${NC}
  echo
fi
clear
if [ "$(basename "$0")" = skel.sh ];then
  echo -e "${YELLOW}\tIf the${CYAN} \"Van\"${YELLOW} is${CYAN} Rockin'
  ${YELLOW}\tThen Don't Come a${CYAN} Knockin'"${NC};exit 0
fi
for COMMAND in mencoder ffmpeg oggenc cat
do COMMAND=$(which "$COMMAND")
if [ ! -x "$COMMAND" ];then RESULT=NO
echo -e ${YELLOW}"\tPlease install "${COMMAND}" first before continuing.${NC}
${CYAN}\tsudo apt-get install "$(basename "${COMMAND}")""${NC};fi
done
if [ "$RESULT" = NO ]; then echo -e ${BLUE}"\tSee (for example):${YELLOW} http://ubuntuforums.org/showthread.php?t=766683${BLUE} for more info on the matter."${NC};exit 0;fi
## Variables for the 'scale' command.
date="$(date +"%A, %B %-d, %Y")"
copy=$(echo "Up to you.")
publisher=$(echo "Up to you.")
UPS_EXT=.mkv
HD=1280x720
PAL=720x576
_4CIF=704x576
## Variables for the 'quote' command.
## If 'START' is 'empty' then.
ZERO=00:00:00.000
## If 'END' is 'empty' then.
HALF=00:00:30.000
## Variables for the 'xtract.z' command.
## Print working directory.
PWD=$(pwd)
## Scriptname.
SCRIPT="$(basename "$0")"
## 'basename' of the script.
BASE="$(basename ${SCRIPT%.*})"
## Its 'extension'.
EXT="${SCRIPT/${BASE}/}"
## End variables!
## What would you have your 'arbiter' do.
for OPTION in "${BASE}";do OPTION="${OPTION}";done
for CHOICE in "${EXT}";do CHOICE="${CHOICE}";done
#  ## When no argument is given, print its usage.
  if [ "$BASE" = scale ];then USAGE=$(echo "Usage: "${SCRIPT}" yourfile"${EXT}" 4cif, pal, hd")
  elif [ "$BASE" = quote ];then USAGE=$(echo "Usage: "${SCRIPT}" yourfile"${EXT}" Start End (Either in whole seconds or HH:MM:SS.MSS)")
  elif [ "$BASE" = clean.up ];then USAGE=$(echo "Usage: "${SCRIPT}" yourfile"${EXT}" norm, clean, rev, flash")
  else USAGE="Usage: "${SCRIPT}" yourfile"${EXT}"";fi
  if [ "$#" == "0" ];then echo -e ${YELLOW}"$USAGE"${NC};exit 0;fi
case "$OPTION" in
"cat" | "create")
  if [ "$#" == 1 ];then OUTPUT="$1";OUTPUT+="${EXT}";else echo -en "Enter filename: ";read OUTPUT;OUTPUT+="${EXT}";fi
  echo "$OUTPUT"
  case "$OPTION" in
  "cat")
    case "$CHOICE" in
    ".avi" | ".vob" | ".wmv")
    # LS=$(ls *.{avi,mp{e,eg,g},wmv} 2>/dev/null)
    LS=$(ls *"${EXT}" 2>/dev/null)
    echo "$LS"
    mencoder -forceidx -oac copy -ovc copy $(ls *"$EXT" | sort -n) -o "$OUTPUT"
    mv "$OUTPUT" ../"$OUTPUT"
    \rm *"${EXT}" 2>/dev/null
    mv ../"$OUTPUT" .
    ;;
    ".mpg")
    VAR="mpg-files.txt"
    ls *.mp{e,eg,g} 2>/dev/null | sort > $VAR
    cat $VAR | while read line; do
    INPUT=$(echo ${line})
    cat "$INPUT" >> "$OUTPUT"
    done
    \rm $VAR
    mv "$OUTPUT" ../"$OUTPUT"
    \rm *.mp{e,eg,g} 2>/dev/null
    mv ../"$OUTPUT" .
    ;;
    esac
  ;;
  "create")
    echo "#EXTM3U" > "$OUTPUT"
    find -iname '*.ogg' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp2' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp3' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mp4' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mpg' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.wma' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.flv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.f4v' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.avi' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.mkv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    find -iname '*.wmv' -exec ls "{}" \; | sort -n >> "$OUTPUT"
    ;;
  esac
;;
"scale" | "quote" | "xtract.z")
  ## Does the filename contain spaces.
  URLENC=$(echo "$1" | sed -e "s_%20_\\ _g")
  if [ -n "${URLENC}" ];then DIR=${URLENC/file:\/\//};else DIR="${DIR}";fi
  ## If so, then move the file into a more 'workable' state.
  MOVED=$(echo "${DIR}" | sed -e "s_\\ _._g")
  if [ -f "${MOVED}" ];then DIR="${DIR}";else mv "${DIR}" "${MOVED}";DIR=${MOVED};fi
  ## Filename. <-- Everything is a 'file' or should I say 'object'.
  FILE=$(basename "${DIR}")
  ## Its 'basename'.
  BASEF=$(basename ${FILE%.*})
  ## Its 'extension'.
  EXTF="${FILE/${BASEF}/}"
  ## Name of out-file.
  OUTPUT=$(basename ${DIR%.*})
  ## Uh oh! 'Error' time.
  if [ ! -f "$DIR" ];then echo -e ${YELLOW}"\tThe file: "$DIR" doesn't exist!\n${RED}    Exiting...!!!"${NC}; exit 0;fi
  if [ ! "$EXT" = "$EXTF" ];then
  echo -e ${YELLOW}"\tYou made a typo!? ${CYAN}*auto-correcting*\n
  ${BLUE}\tFrom: ${YELLOW}"$SCRIPT" "${DIR}"\n
  ${BLUE}\tTo: ${YELLOW}  "$BASE""$EXTF" "${DIR}""${NC}
  echo
  SCRIPT="$BASE""$EXTF"
  unset EXT
  EXT="${SCRIPT/${BASE}/}"
  sleep 1
  fi
  case "$OPTION" in
  "scale")
    if [ -f "$DIR" ];then
    if [ "$#" == "1" ];then DIR="$DIR";RES=pal;else
    for RES in "$2";do RES=${RES};done
    case "${RES}" in
      "4cif" )
      RES="$HD"
      ;;
      "pal" )
      RES="$PAL"
      ;;
      "pal" )
      RES="$_4CIF"
      ;;
      *)
      echo -e ${YELLOW}"\tPlease choose a valid option!"${NC}
      echo -e ${BLUE}"\t"Usage:" ${CYAN}"$SCRIPT" "$DIR" |${CYAN}"4cif"|${CYAN}"pal"|${CYAN}"hd"${NC}|"
      exit 0
      ;;
    esac
    fi
    OUTPUT+="$UPS_EXT"
    ffmpeg -y -i "$DIR" \
    -acodec copy \
    -alang eng \
    -vlang eng \
    -metadata title=""$(basename "$OUTPUT" "$UPS_EXT")". ®" \
    -metadata artist=""$USER"" \
    -metadata date="$date" \
    -metadata publisher="$publisher" \
    -metadata copyright="$copy" \
    -vcodec libx264 -vpre lossless_ultrafast -crf 18 \
    -s "$RES" \
    "$OUTPUT"
    fi
  ;;
  "quote")
    if [ -f "$DIR" ];then
      if [ "$#" == "3" ];then START="$2" && DUR="$3"
      elif [ "$#" == "2" ];then START="${ZERO}" && DUR="$2"
      else [ "$#" == "1" ]
        echo -e ${BLUE}"\tEither in seconds or...,"${NC}
        echo -e ${BLUE}"\tHH:MM:SS.MSS or...,"${NC}
        echo -e ${BLUE}"\tPress enter for starts at 0."${NC}
        echo -en "\tEnter Start Position : "
        read START
        echo -e ${BLUE}"\tEither in seconds or...,"${NC}
        echo -e ${BLUE}"\tHH:MM:SS.MSS"${NC}
        echo -e ${BLUE}"\tPress enter for lasts 30 seconds."${NC}
        echo -en "\tEnter Duration : "
        read DUR
      fi
      if [ -z "$START" ];then START="${ZERO}";fi
      if [ -z "$DUR" ];then DUR="${HALF}";fi
      for DIGITS in "$START" "$DUR";do
      if [[ "$DIGITS" =~ [^\ 0-9.,:]+ ]];then exit 0;fi
      done
      ## Arg "$2" NEEDS TO BE "QUOTED", e.g. "00 01 30.200"! But at least it works now. ; - )
      SPACE=$(echo "$START" | sed -e "s_\\ _:_g")
      if [ -n "$SPACE" ];then START="$SPACE"
      else start=${START%[ .,_-]*};end=${START/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        START="$start"."$end"
      fi
      ## My num pad doesn't have a dot but uses comma instead.
      COMMA=$(echo "$START" | sed -e "s_,_._g")
      if [ "$COMMA" = . ];then COMMA="${ZERO}";fi
      if [ -n "$COMMA" ];then START="$COMMA"
      else start=${START%[ .,_-]*};end=${START/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        START="$start"."$end"
      fi
      SPACE=$(echo "$DUR" | sed -e "s_\\ _:_g")
      if [ -n "$SPACE" ];then DUR="$SPACE"
      else start=${DUR%[ .,_-]*};end=${DUR/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        DUR="$start"."$end"
      fi
      COMMA=$(echo "$DUR" | sed -e "s_,_._g")
      if [ "$COMMA" = . ];then COMMA="${HALF}";fi
      if [ -n "$COMMA" ];then DUR="$COMMA"
      else start=${DUR%[ .,_-]*};end=${DUR/${start}[ .,_-]/}
        if [ "${start}" = "${end}" ];then end=000;else end="$end";fi
        DUR="$start"."$end"
      fi
    OUTPUT+=.quote"$EXT"
    if [ "$EXT" = .oga ] || [ "$EXT" = .ogg ] || [ "$EXT" = .flac ] || [ "$EXT" = .wav ] || [ "$EXT" = .mp3 ];then Choice=AUDIO;else Choice=VIDEO;fi
      case "$Choice" in
      "AUDIO")
      ffmpeg -y -i "${DIR}" -ss "${START}" -t "${DUR}" -acodec copy -vn "${OUTPUT}"
      ;;
      "VIDEO")
      mencoder -ss "${START}" -endpos "${DUR}" -oac copy -ovc copy "${DIR}" -o "${OUTPUT}"
      ;;
      esac
    fi
  "xtract.z")
    if [ -f "$DIR" ];then WD=ripped/"${BASEF}";OUTPUT=${PWD}"/"${WD}"/"${BASEF};[ ! -d "${WD}" ] && mkdir -p "${WD}"
    ffmpeg -y -threads 2 -i "${DIR}" -vn -acodec pcm_s16le -ac 2 "${WD}"/${BASEF}.wav
    ffmpeg -y -threads 2 -i "${WD}"/${BASEF}.wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "${WD}"/${BASEF}.mp3
    oggenc "${WD}"/${BASEF}.wav -q 9
    ffmpeg -y -threads 2 -i "${DIR}" -an -vcodec copy "${WD}"/${BASEF}.rip.avi
    fi
  ;;
  esac
;;
esac
exit 0

How to quote from your media.

Just a friendly notice: This post will frequently be updated and at the discretion of the user ‘republished’.
“…under the premise that the only way to really learn scripting is to write scripts.” 😉

This post is yet another follow up on:
Conversions.

Updated today: Sunday, November 6, 2011
The main reason: I’ve combined both scripts, who were once mentioned on this page. 😉

BUT… In order for it all to work, one has to do the following:

alias link='ln -s -T'
## Assuming here ~/bin to be the user's personal script folder.
## As it usually is on Ubuntu
## (that would be ~/.usr/bin in my case. ; - )
## And assuming here that you saved the script,
## provided on this page as: 'scale.sh'
## Otherwise change 'scale.sh' to whatever has your fancy.
cd ~/bin
## This will give you the scaling abilities of the previous 'upscale.sh' script.
link scale.sh scale.avi
link scale.sh scale.mkv
link scale.sh scale.mp4
link scale.sh scale.mpg
link scale.sh scale.ogg
link scale.sh scale.ogm
link scale.sh scale.ogv
link scale.sh scale.wmv
## And this will provide you with the quoting abilities of the previous 'quote.sh' script.
link scale.sh quote.avi
link scale.sh quote.flac
link scale.sh quote.mkv
link scale.sh quote.mp3
link scale.sh quote.mp4
link scale.sh quote.mpg
link scale.sh quote.oga
link scale.sh quote.ogg
link scale.sh quote.ogm
link scale.sh quote.ogv
link scale.sh quote.wav
link scale.sh quote.wmv
## And now you have one script that you can invoke in many ways. ; - )
## But at the moment only as a demo.
## It's up to you to remove those few remaining echo statements,
## Those who do the actual work, see it as an exercise.

Also before we dive into the script, this post originally referred to, I wanted to point out a Very Nice Tool that I’ve recently discovered!

Here is a slightly altered ‘plist’ (xml based) I frequently use to for example convert my personal DVD collection. The ‘preference list’ I obtained from here: http://ubuntuforums.org/showthread.php?t=1350522

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
	<dict>
		<key>AudioList</key>
		<array>
			<dict>
				<key>AudioBitrate</key>
				<string>160</string>
				<key>AudioEncoder</key>
				<string>AAC (faac)</string>
				<key>AudioMixdown</key>
				<string>Dolby Pro Logic II</string>
				<key>AudioSamplerate</key>
				<string>48</string>
				<key>AudioTrack</key>
				<integer>1</integer>
				<key>AudioTrackDRCSlider</key>
				<real>0</real>
				<key>AudioTrackDescription</key>
				<string>English (AC3) (5.1 ch)</string>
			</dict>
		</array>
		<key>ChapterMarkers</key>
		<false />
		<key>Default</key>
		<false />
		<key>FileFormat</key>
		<string>MP4 file</string>
		<key>Folder</key>
		<false />
		<key>Mp4HttpOptimize</key>
		<false />
		<key>Mp4LargeFile</key>
		<false />
		<key>Mp4iPodCompatible</key>
		<false />
		<key>PictureAutoCrop</key>
		<true />
		<key>PictureBottomCrop</key>
		<integer>0</integer>
		<key>PictureDeblock</key>
		<integer>4</integer>
		<key>PictureDecomb</key>
		<integer>2</integer>
		<key>PictureDecombCustom</key>
		<string></string>
		<key>PictureDecombDeinterlace</key>
		<true />
		<key>PictureDeinterlace</key>
		<integer>0</integer>
		<key>PictureDeinterlaceCustom</key>
		<string></string>
		<key>PictureDenoise</key>
		<integer>0</integer>
		<key>PictureDenoiseCustom</key>
		<string></string>
		<key>PictureDetelecine</key>
		<integer>2</integer>
		<key>PictureDetelecineCustom</key>
		<string></string>
		<key>PictureHeight</key>
		<integer>0</integer>
		<key>PictureKeepRatio</key>
		<true />
		<key>PictureLeftCrop</key>
		<integer>8</integer>
		<key>PictureLooseCrop</key>
		<true />
		<key>PictureModulus</key>
		<integer>1</integer>
		<key>PicturePAR</key>
		<string>1</string>
		<key>PicturePARHeight</key>
		<integer>15</integer>
		<key>PicturePARWidth</key>
		<integer>16</integer>
		<key>PictureRightCrop</key>
		<integer>6</integer>
		<key>PictureTopCrop</key>
		<integer>0</integer>
		<key>PictureWidth</key>
		<integer>0</integer>
		<key>PresetBuildNumber</key>
		<integer>2009112300</integer>
		<key>PresetDescription</key>
		<string>HandBrake&apos;s general-purpose preset for High Profile H.264 video, with all the bells and whistles.</string>
		<key>PresetName</key>
		<string>PS3</string>
		<key>SubtitleList</key>
		<array>
		</array>
		<key>Type</key>
		<integer>1</integer>
		<key>UsesPictureFilters</key>
		<integer>1</integer>
		<key>UsesPictureSettings</key>
		<integer>2</integer>
		<key>VideoAvgBitrate</key>
		<integer>2500</integer>
		<key>VideoEncoder</key>
		<string>H.264 (x264)</string>
		<key>VideoFramerate</key>
		<string>Same as source</string>
		<key>VideoGrayScale</key>
		<false />
		<key>VideoQualitySlider</key>
		<real>20</real>
		<key>VideoQualityType</key>
		<integer>1</integer>
		<key>VideoTargetSize</key>
		<integer>700</integer>
		<key>VideoTurboTwoPass</key>
		<false />
		<key>VideoTwoPass</key>
		<false />
		<key>anamorphic</key>
		<true />
		<key>par_height</key>
		<integer>0</integer>
		<key>par_width</key>
		<integer>0</integer>
		<key>x264Option</key>
		<string>rc-lookahead=50:ref=1:bframes=0:subme=6:trellis=0:analyse=none</string>
	</dict>
</array>
</plist>

^^ I hope this helps!?

The following applies to the following script!

## Either invoke as:
you@somewhere:~$ ./scale.avi name-of-your-movie.avi
you@somewhere:~$ ./quote.avi name-of-your-movie.avi
## Or: (if the script is within your "$PATH"?
you@somewhere:~$ scale.avi name-of-your-movie.avi
you@somewhere:~$ quote.avi name-of-your-movie.avi

The newly combined script goes here:
[It’s only 185 lines long now, this includes comments. 😉 ]

What does it do? It either “quotes from” or “(up)scales” the media it is presented with by the user. By passing the filename (w/- or w/o (assumes pwd = wd)) its full path to the script (and yes the script does strip off the “file:///” thingy when copied from within nautilus or eq.)

Scriptname: scale.sh:

#!/bin/bash
# Modified: Today by E.L.F.
#
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - scale.sh
#
UPS_EXT=.mkv
HD=1280x720
PAL=720x576
_4CIF=704x576
PWD=$(pwd)
export PWD
NOPARAMS=0
MINPARAMS=1
MAXPARAMS=2
date="$(date +"%A, %B %-d, %Y")"
copy=$(echo "Whatever you like!?")
SCRIPT=$(basename "$0")
BASE=$(basename ${SCRIPT%.*})
if [ "$BASE" = scale ]; then REPLACE=scale;OPTION=_1;else [ "$BASE" = quote ]; REPLACE=quote;OPTION=_2;fi
EXT=${SCRIPT#${REPLACE}}
export EXT
export OPTION
FILE=$(basename "$1")
BASEF=$(basename ${FILE%.*})
EXTF=${FILE#${BASEF}}
export EXTF
if [ "$USER" = root ]; then
  echo -e ${RED}"Are you Insane!"${NC}
  echo -e ${RED}"Error: In order to use this script, one must NOT be "$USER""${NC}
  echo -e ${YELLOW}"Exiting..."${NC}
  exit 0
else
  echo ""
  echo -e ${BLUE}"    "$USER" may proceed."${NC}
  echo -e ${CYAN}"    May peace be with you."${NC}
fi
clear
## http://tor-relay.thruhere.net/abs-guide/
## ^^ Always learning! ; - )
echo
  if [ "$#" -eq "$MAXPARAMS" ];then DIR="$1" && RES="$2";fi
  if [ "$#" -eq "$MINPARAMS" ];then DIR="$1";RES=pal;fi
  if [ -n "$1" ]; then DIR=${DIR/file:\/\//};else DIR="$DIR";fi
  if [ -n "$2" ];then RES="$RES"; else RES="$RES";fi
  if [ "$RES" = hd ];then RES="$HD";else RES="$RES";fi
  if [ "$RES" = pal ];then RES="$PAL";else RES="$RES";fi
  if [ "$RES" = 4cif ];then RES="$_4CIF";else RES="$RES";fi
  if [ ! -f "$DIR" ]; then echo -e ${YELLOW}"    The file: "$DIR" doesn't exist! Or you didn't provide one?${NC}\n${RED}    Exiting...!!!"${NC}; exit 0;fi
  if [ ! "$EXT" = "$EXTF" ]; then
  echo -e ${YELLOW}"      You probably invoked this script the wrong way:\n
      E.g.:${NC} ${BLUE}"$BASE""$EXTF" "$FILE"${NC} ${YELLOW}is correct.\n\
      ${YELLOW}However:${NC} ${BLUE}"$SCRIPT" "$FILE"${NC} ${YELLOW}is NOT."${NC}
  exit 0
  fi
if [ "$OPTION" = _1 ]; then CHOICE=SCALE;else CHOICE=QUOTE;fi
case "$CHOICE" in
"SCALE")
  if [ -f "$DIR" ]; then
  echo -e ${CYAN}" Extension:    "$EXT""${NC}
  echo -e ${CYAN}"   In file:    "$DIR""${NC}
  OUTPUT=$(basename ${DIR%.*})
  OUTPUT+="$UPS_EXT"
  echo -e ${CYAN}"  Out file:    "$PWD"/"$OUTPUT""${NC}
  echo -e ${CYAN}"Resolution:    "$RES""${NC}
  ffmpeg -y -i "$DIR" \
  -acodec copy \
  -alang eng \
  -vlang eng \
  -metadata title=""$(basename "$OUTPUT" "$UPS_EXT")". ®" \
  -metadata artist=""$USER"" \
  -metadata date="$date" \
  -metadata publisher="Whatever you like!?" \
  -metadata copyright="$copy" \
  -vcodec libx264 -vpre lossless_ultrafast -crf 18 \
  -s "$RES" \
  "$OUTPUT"
  fi
;;
"QUOTE")
  if [ -f "$DIR" ]; then
  echo -e ${CYAN}" Extension:    "$EXT""${NC}
  echo -e ${CYAN}"   In file:    "$DIR""${NC}
  OUTPUT=$(basename ${DIR%.*})
  OUTPUT+=.quoted"$EXT"
  echo -e ${CYAN}"  Out file:    "$PWD"/"$OUTPUT""${NC}
  if [ "$EXT" = .oga ] || [ "$EXT" = .ogg ] || [ "$EXT" = .flac ] || [ "$EXT" = .wav ] || [ "$EXT" = .mp3 ]; then Choice=AUDIO;else Choice=VIDEO;fi
  echo -e ${BLUE}"    Either in seconds or...,"${NC}
  echo -e ${BLUE}"    HH:MM:SS.MSS or...,"${NC}
  echo -e ${BLUE}"    Press enter for starts at 0"${NC}
  echo -n "Enter Start Position : "
  read START
  if [ -z "$START" ]; then START=00:00:00.000;fi
  if [[ "$START" =~ [A-Za-z]+ ]];then echo -e ${RED}"    Input MUST be numerical."${NC};echo -e ${YELLOW}"    Exiting..."${NC};exit 0;fi
  start=${START%[ .,_-]*}
  end=${START/${start}[ .,_-]/}
  if [ "${start}" = "${end}" ]; then end=000;else end="$end";fi
  START="$start"."$end"
  echo -e ${BLUE}"    Either in seconds or...,"${NC}
  echo -e ${BLUE}"    HH:MM:SS.MSS"${NC}
  echo -n "Enter Duration : "
  read DUR
  if [ -z "$DUR" ]; then echo -e ${RED}"    Duration can't be zero!."${NC};echo -e ${YELLOW}"Exiting..."${NC};exit 0;fi
  if [[ "$DUR" =~ [A-Za-z]+ ]];then echo -e ${RED}"    Input MUST be numerical."${NC};echo -e ${YELLOW}"    Exiting..."${NC};exit 0;fi
  start=${DUR%[ .,_-]*}
  end=${DUR/${start}[ .,_-]/}
  if [ "${start}" = "${end}" ]; then end=000;else end="$end";fi
  DUR="$start"."$end"
    case "$Choice" in
    "AUDIO")
    echo -e ${CYAN}"ffmpeg -y -i "${DIR}" -ss "${START}" -t "${DUR}" -acodec copy -vn "${OUTPUT}""${NC}
    ffmpeg -y -i "${DIR}" -ss "${START}" -t "${DUR}" -acodec copy -vn "${OUTPUT}"
    ;;
    "VIDEO")
    mencoder -ss "${START}" -endpos "${DUR}" -oac copy -ovc copy "${DIR}" -o "${OUTPUT}"
    ;;
    *)
    echo
    echo -e ${YELLOW}"    Please try again?"${NC} ${BLUE}"Possible reason: unsupported filetype?"${NC}
    echo -e ${CYAN}"    The file used was: "$DIR"."${NC}
    ;;
    esac
  fi
;;
*)
  echo
  echo -e ${YELLOW}"    Please try again?"${NC} ${BLUE}"Possible reason: unsupported filetype?"${NC}
  echo -e ${CYAN}"    The file used was: "$DIR"."${NC}
;;
esac
exit 0

Now about those color definitions used in the script above:
(Oh noes they’re not there anymore! Did I do that on purpose!? :lol:)

## For these colors to work either insert the next 5 lines in the script above.
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"              # No Color
#
## OR...
#
## Paste the following lines in your ~/.bashrc file for a more 'global feel'. ; - )
## (At the bottom is recommended.)
## http://tldp.org/LDP/abs/html/sample-bashrc.html
## Define some colors first:
RED="\033[0;31m"
export RED
BLUE="\033[1;34m"
export BLUE
CYAN="\033[1;36m"
export CYAN
YELLOW="\033[1;33m"
export YELLOW
NC="\033[0m"              # No Color
export NC
# --> Nice. Has the same effect as using "ansi.sys" in DOS.
## Don't forget to resource your ~/.bashrc file!

Still code efficiency is everything. . <– So while I managed to greatly reduce the amount of lines used and inserted a check for numeric input only. It still doesn’t meet my standards for “Elegance”. 😦

Less is (still) more!

To do: It would be nice if I could specify my input:
e.g. HH:MM:SS.MSS as HH MM SS MSS instead.

The astute reader will for instance see that the script already allows for this format:
SEC MSS to specify either the start or end of a quote.
That would be:

[ .,_-]

To be exact (for a change :lol:)!

To do as well: To make it possible to copy and paste in URLs with spaces in both the filename as well as the folder path(s)! I might want to have a look at:

\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b

Which is a string I found here!

Next assignment: Write a nautilus script to make it easier for a user to just select his/her files and do the “conversion” (if any) from there.


^^ Or: Simply make your terminal transparent, so you can see what you’re affecting. 😉

Samples:

More free goodies? – Yes!!! 😆

## This is from my $HOME/.bash_functions
## The mandatory: "Hello World" ; - )
hello()
{
    echo "Hello, "$1""
}
## Tidy up any html file with 'tidy'
mtidy()
{
config=$(echo "$HOME/.usr/bin/etc/config.txt")
tidy -config $config $1
}
## Extract all media from flash.
## I do all possible outcomes, just in case. ; - )
xtract.z.flv()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .flv)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -vn -acodec pcm_s16le -ac 2 "$FOLDER"/$(basename "$1" .flv).wav # <-- Rip audio from flv to wav.
ffmpeg -y -threads 2 -i "$FOLDER"/$(basename "$1" .flv).wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "$FOLDER"/$(basename "$1" .flv).mp3 # <-- Rip to mp3.
oggenc "$FOLDER"/$(basename "$1" .flv).wav -q 9 # <-- Rip to ogg.
ffmpeg -y -threads 2 -i "$1" -an -vcodec copy "$FOLDER"/$(basename "$1" .flv).rip.avi # <-- Rip the video only.
\rm "$FOLDER"/$(basename "$1" .flv).wav
}
## Extract all media from avi.
xtract.z.avi()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .avi)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -vn -acodec pcm_s16le -ac 2 "$FOLDER"/$(basename "$1" .avi).wav # <-- Rip audio from flv to wav.
ffmpeg -y -threads 2 -i "$FOLDER"/$(basename "$1" .avi).wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "$FOLDER"/$(basename "$1" .avi).mp3 # <-- Rip to mp3.
oggenc "$FOLDER"/$(basename "$1" .avi).wav -q 9 # <-- Rip to ogg.
ffmpeg -y -threads 2 -i "$1" -an -vcodec copy "$FOLDER"/$(basename "$1" .avi).rip.avi # <-- Rip the video only.
\rm "$FOLDER"/$(basename "$1" .avi).wav
}
## Extract all media from mpg.
xtract.z.mpg()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .mpg)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -vn -acodec pcm_s16le -ac 2 "$FOLDER"/$(basename "$1" .mpg).wav # <-- Rip audio from flv to wav.
ffmpeg -y -threads 2 -i "$FOLDER"/$(basename "$1" .mpg).wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "$FOLDER"/$(basename "$1" .mpg).mp3 # <-- Rip to mp3.
oggenc "$FOLDER"/$(basename "$1" .mpg).wav -q 9 # <-- Rip to ogg.
ffmpeg -y -threads 2 -i "$1" -an -vcodec copy "$FOLDER"/$(basename "$1" .mpg).rip.avi # <-- Rip the video only.
\rm "$FOLDER"/$(basename "$1" .mpg).wav
}
## Extract all media from mp4.
xtract.z.mp4()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .mp4)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -vn -acodec pcm_s16le -ac 2 "$FOLDER"/$(basename "$1" .mp4).wav # <-- Rip audio from flv to wav.
ffmpeg -y -threads 2 -i "$FOLDER"/$(basename "$1" .mp4).wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "$FOLDER"/$(basename "$1" .mp4).mp3 # <-- Rip to mp3.
oggenc "$FOLDER"/$(basename "$1" .mp4).wav -q 9 # <-- Rip to ogg.
ffmpeg -y -threads 2 -i "$1" -an -vcodec copy "$FOLDER"/$(basename "$1" .mp4).rip.avi # <-- Rip the video only.
\rm "$FOLDER"/$(basename "$1" .mp4).wav
}
## Extract all media from wmv.
xtract.z.wmv()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .wmv)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -vn -acodec pcm_s16le -ac 2 "$FOLDER"/$(basename "$1" .wmv).wav # <-- Rip audio from flv to wav.
ffmpeg -y -threads 2 -i "$FOLDER"/$(basename "$1" .wmv).wav -f mp3 -acodec libmp3lame -ac 2 -ab 320k "$FOLDER"/$(basename "$1" .wmv).mp3 # <-- Rip to mp3.
oggenc "$FOLDER"/$(basename "$1" .wmv).wav -q 9 # <-- Rip to ogg.
ffmpeg -y -threads 2 -i "$1" -an -vcodec copy "$FOLDER"/$(basename "$1" .wmv).rip.avi # <-- Rip the video only.
\rm "$FOLDER"/$(basename "$1" .wmv).wav
}
## Rip from wmv to xvid in avi container directly.
## Please note amongst things the -s switch here!
## I.e.: Please, do a...
# ffmpeg -i "$YOUR.INPUT" to show you the resolution, rate, aspect ratio and other useful telltale signs. ; - )
wmv2xvid.hd720()
{
WD=./ripped
FOLDER="$WD"/$(basename "$1" .wmv)
[ ! -d "$FOLDER" ] && mkdir -p "$FOLDER"
ffmpeg -y -threads 2 -i "$1" -f avi -r 25 -vcodec libxvid -vtag XVID -s hd720 -aspect 16:9 -maxrate 1800k -b 1400kb -qmin 3 -qmax 5 -bufsize 4096 -mbd 2 -bf 2 -flags +4mv -trellis -aic -cmp 2 -subcmp 2 -g 300 -an $(basename "$1" .wmv).xvid.avi
}
## Rip from wav to mp3.
wav2mp3()
{
ffmpeg -y -threads 2 -i "$1" -f mp3 -acodec libmp3lame -ac 2 -ab 320k $(basename "$1" .wav).mp3 # <-- Rip to mp3.
}
## Rip from wav to ogg.
wav2ogg()
{
oggenc "$1" -q 9
}
## "panavision" : - )
upscale()
{
mencoder "$1" -endpos 00:00:20 -oac copy -ovc xvid -xvidencopts \
chroma_opt:vhq=4:bvhq=1:quant_type=mpeg:bitrate=1400 \
-vf scale=1280:544,expand=1280:720 \
-o $(basename "$1" .avi).HD.men.avi
}
## Evolvotron specific.
evolve()
{
evolvotron_render -f 96 -r 8 -j -a -m 4 -s 720 576 -spheremap "$1".ppm < $HOME/Downloads/vid.edit/evolved0.xml
}
evolvehd()
{
ffmpeg -y -b 3000k -r 8 -f image2 -i "$1".f%6d.ppm -qscale 4 -qblur 1.0 -aspect 16:9 -g 300 -s hd720 "$1".avi
}
evolvepal()
{
ffmpeg -y -b 3000k -r 8 -f image2 -i "$1".f%6d.ppm -qscale 4 -qblur 1.0 -aspect 16:9 -g 300 "$1".avi
}
## This function will simulate the effect the "mod_deflate" module for Apache has, for the same named files.
## Only to be used with a server who understands the .gz format out of the box: I.e. thttpd
## Also works in a chroot'ed environment. ; - )
massedit()
{
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then
  echo -e $RED"   Are you Insane!"
  echo -e $CYAN"    Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"    Exiting..."$NC
  exit 0
else
  echo ""
  echo -e $BLUE"    $USER may proceed."
  echo -e $CYAN"    May peace be with you."$NC
fi
clear # Clear the screen.
  case "$1" in
  "HTML" | "Html" | "html")
  if [ ! "$(ls *.html 2>/dev/null)" ]
  then
  echo -e $YELLOW"$1 does not exist."$NC; echo
  else
  echo -e $BLUE"    You've chosen \"$(ls *.html | wc -l)\" file(s) to work on."$NC
  echo -e $RED"Executing..."$NC
  for i in *.html; do gzip -c --best $i > $i.gz;done
  for i in *.html; do \rm $i;done
  for i in *.html.gz; do ln -s -T "$i" $(basename "$i" .gz);done
  fi
  ;;
  "TXT" | "Txt" | "txt" | "TEXT" | "Text" | "text")
  if [ ! "$(ls *.txt 2>/dev/null)" ]
  then
  echo -e $YELLOW"$1 does not exist."$NC; echo
  else
  echo -e $BLUE"    You've chosen \"$(ls *.txt | wc -l)\" file(s) to work on."$NC
  echo -e $RED"Executing..."$NC
  for i in *.txt; do gzip -c --best $i > $i.gz;done
  for i in *.txt; do \rm $i;done
  for i in *.txt.gz; do ln -s -T "$i" $(basename "$i" .gz);done
  fi
  ;;
  "CSS" | "Css" | "css")
  if [ ! "$(ls *.css 2>/dev/null)" ]
  then
  echo -e $YELLOW"$1 does not exist."$NC; echo
  else
  echo -e $BLUE"    You've chosen \"$(ls *.css | wc -l)\" file(s) to work on."$NC
  echo -e $RED"Executing..."$NC
  for i in *.css; do gzip -c --best $i > $i.gz;done
  for i in *.css; do \rm $i;done
  for i in *.css.gz; do ln -s -T "$i" $(basename "$i" .gz);done
  fi
  ;;
  "XML" | "Xml" | "xml")
  if [ ! "$(ls *.xml 2>/dev/null)" ]
  then
  echo -e $YELLOW"$1 does not exist."$NC; echo
  else
  echo -e $BLUE"    You've chosen \"$(ls *.xml | wc -l)\" file(s) to work on."$NC
  echo -e $RED"Executing..."$NC
  for i in *.xml; do gzip -c --best $i > $i.gz;done
  for i in *.xml; do \rm $i;done
  for i in *.xml.gz; do ln -s -T "$i" $(basename "$i" .gz);done
  fi
  ;;
  "JS" | "Js" | "js")
  if [ ! "$(ls *.js 2>/dev/null)" ]
  then
  echo -e $YELLOW"$1 does not exist."$NC; echo
  else
  echo -e $BLUE"    You've chosen \"$(ls *.js | wc -l)\" file(s) to work on."$NC
  echo -e $RED"Executing..."$NC
  for i in *.js; do gzip -c --best $i > $i.gz;done
  for i in *.js; do \rm $i;done
  for i in *.js.gz; do ln -s -T "$i" $(basename "$i" .gz);done
  fi
  ;;
  *)
  echo
  echo "Please choose a valid option."
  echo "\"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
  echo -e $YELLOW"    Usage$NC: "
  echo -e $CYAN"    massedit$NC$BLUE html$NC"
  echo -e $CYAN"    massedit$NC$BLUE text$NC"
  echo -e $CYAN"    massedit$NC$BLUE js$NC"
  echo -e $CYAN"    massedit$NC$BLUE xml$NC"
  echo -e $CYAN"    massedit$NC$BLUE css$NC"
  echo
  ;;
  esac
}
## This one removes the empty lines and unnecessary spaces,
## of the text based type of file,
## you gave it to chew on. ; - )
squeeze()
{
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then
  echo -e $RED"   Are you Insane!"
  echo -e $CYAN"    Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"    Exiting..."$NC
  exit 0
else
  echo ""
  echo -e $BLUE"    $USER may proceed."
  echo -e $CYAN"    May peace be with you."$NC
fi
clear # Clear the screen.
if [ ! -e "$1" ]
then
echo -e $YELLOW"$1 does not exist."$NC; echo
else
## This removes the trailing spaces in your doc.
sed -i 's/[ \t]*$//' "$1"
## Removing those empty lines for you as well.
sed -i '/^$/d' "$1"
fi
}
## The following function might interest some of you?
## With the added bonus to either sign or verify signatures.
#
## As taken from here: https://calomel.org/openssh.html
## At the bottom of the page you can find the related
## openssl commands which will correspond to the ones
## used in the function below.
crypto()
{
  if [ -z "$1" ]; then
      echo -e $YELLOW"    Please choose a valid option!"$NC  
      echo -e $YELLOW"    Usage"$NC": "$CYAN"\"UPPER\""$NC", "$CYAN"\"lower\""$NC" and "$CYAN"\"Capitalized\""$NC" spelling are supported."
      echo -e $CYAN"    crypto"$NC" {"$CYAN"--ENCRYPT"$NC","$CYAN"--Encrypt"$NC","$CYAN"--encrypt"$NC","$CYAN"-E"$NC","$CYAN"-e"$NC"}: $BLUE Your-file $NC"
      echo -e $CYAN"    crypto"$NC" {"$CYAN"--DECRYPT"$NC","$CYAN"--Decrypt"$NC","$CYAN"--decrypt"$NC","$CYAN"-D"$NC","$CYAN"-d"$NC"}: $BLUE Your-file.aes $NC"
      echo -e $CYAN"    crypto"$NC" {"$CYAN"--SIGN"$NC","$CYAN"--Sign"$NC","$CYAN"--sign"$NC","$CYAN"-S"$NC","$CYAN"-s"$NC"}: $BLUE Your-file $NC"
      echo -e $CYAN"    crypto"$NC" {"$CYAN"--VERIFY"$NC","$CYAN"--Verify"$NC","$CYAN"--verify"$NC","$CYAN"-V"$NC","$CYAN"-v"$NC"}: $BLUE Your-file.asc $NC"
  elif [ -z "$2" ]; then
    echo -e $YELLOW"   Error: Providing a filename is MANDATORY!   "$NC
    echo -e $RED"   Exiting..."$NC
  elif [ -d "$2" ]; then
    echo -e $YELLOW"   Error: File is a directory!"$NC
    echo -e $RED"   Exiting..."$NC
  else
    case "$1" in
      "--ENCRYPT" | "--Encrypt" | "--encrypt" | "-E" | "-e")
      ## to encrypt (-e):
      openssl aes-256-cbc -a -e -salt -in "$2" -out "$2".aes
      ;;
      "--DECRYPT" | "--Decrypt" | "--decrypt" | "-D" | "-d")
      ## to decrypt (-d):
      openssl aes-256-cbc -a -d -salt -in "$2" -out $(basename "$2" .aes)
      ;;
      "--SIGN" | "--Sign" | "--sign" | "-S" | "-s")
      ## to sign (-s):
      echo -e $CYAN"    gpg -a --detach-sign \""$2"\""$NC
      gpg -a --detach-sign "$2"
      ;;
      "--VERIFY" | "--Verify" | "--verify" | "-V" | "-v")
      ## to verify (-v):
      echo -e $CYAN"    gpg --verify \""$2"\" \"$(basename "$2" .asc)\""$NC
      gpg --verify "$2" $(basename "$2" .asc)
      ;;
      *)
      echo
      echo -e $YELLOW"    Nothing done!"$NC
      echo
      ;;
    esac
  fi
}

The tidy config file as mentioned in one of the many functions above. 😉

// sample config file for HTML tidy
doctype: transitional
indent: auto
indent-spaces: 2
wrap: 76
markup: yes
bare: yes
clean: yes
preserve-entities: yes
output-xml: no
input-xml: no
output-xhtml: yes
show-warnings: yes
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
break-before-br: no
uppercase-tags: no
uppercase-attributes: no
char-encoding: utf8
input-encoding: utf8
output-bom: auto
output-encoding: utf8
new-inline-tags: cfif, cfelse, math, mroot,
  mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
  munder, mover, mmultiscripts, msup, msub, mtext,
  mprescripts, mtable, mtr, mtd, mth
new-blocklevel-tags: cfoutput, cfquery
new-empty-tags: cfelse
repeated-attributes: keep-last
error-file: errs.txt
write-back: yes

How?

## Which you can enable just like you'd for a possible .bash_aliases file
## Like so (in your $HOME/.bashrc) in my case around line 91:
## By uncommenting the following, if necessary (i.e.: removing the #'s in front)
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
## And adding this block right thereafter.
## Don't forget to create the file. ; - )
# Functions: check for a separate function file, and if we find one
# source it.
if [[ -f ~/.bash_functions ]]; then
    . ~/.bash_functions
fi

Batch processing by means of using any script of your choosing.

This script will probably always be a work in progress! Meaning that I want to give the user the choice to run the script of his her choosing. (Is it really required for me to point out that this script was specifically written for the previous posts I wrote.) Think case>select. http://tldp.org/LDP/abs/html/testbranch.html

Small update. Now=11/2/2010 23:51u

Getting closer!  Next step:  if and fi file checks, when?  Tomorrow when I’ve had my beauty sleep.  😀
Finished (for now)! File checks aren’t required, because the script will simply exit with an “command not found” error. No harm done.

Yet another update. Now=11/14/2010 14:40u
I’ve made my script more ‘bulletproof’. Though the script has become somewhat more interactive, I felt it was required due to the following: A script is completely ‘agnostic‘ about what the $USER wants? And because I want to prevent frustration (namely my own :lol:) this script requires you to answer a few more questions and also tries to inform the $USER of what it is exactly, that’s going to happen. In this case to the $USER’s media files but potentially could also be applied to any other alternative usage of this script. I.e. The Sky is the Limit (and then some)! 😉

#!/bin/bash
# Modified: Today by E.l.f.
#
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - convert.sh
## vob2ogm.sh avi2mkv.sh mpg2mkv.sh wmvloop.sh must be in your PATH
# mkdir -p $HOME/.usr/bin
## e.g. at the end of your $HOME/.bashrc put in these two lines
## (without the #'s of course >-).
# Alt+F2 > in the popup type in "gedit .bashrc" (without the quotes)
# PATH=$PATH:$HOME/.usr/bin
# export PATH
#
## Source (inspired on): http://ffmpeg.org/ffmpeg-doc.html
## And: http://ubuntuforums.org/showthread.php?t=1037517
RED="\033[0;31m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
YELLOW="\033[1;33m"
NC="\033[0m"
if [ $USER = root ]; then
  echo -e $RED"   Are you Insane!"
  echo -e $CYAN"    Error: In order to use this script, one must NOT be $USER"
  echo -e $YELLOW"    Exiting..."$NC
  exit 0
else
  echo ""
  echo -e $BLUE"    $USER may proceed."
  echo -e $CYAN"    May peace be with you."$NC
fi
clear # Clear the screen.

echo "-------------------Conversion Options List-------------------"
echo
echo "    Please choose one of the following options:              "
echo "                              Or                             "
echo "    Hit Ctrl+c (^c) to stop now."
echo "    \"UPPER\", \"lower\" and \"Capitalized\" spelling "
echo "    are valid forms of input."
echo
echo "    [quo]te from movies or audio"
echo "    [Rep]air mpg files."
echo "    Convert from [wmv]2avi"
echo "    Con[cat]enate mp(e)g files."
echo "    Convert from [flv]2avi"
echo "    Convert from [vob]2ogm"
echo "    Convert from [avi]2mkv"
echo "    Convert from [mpg]2mkv"
echo
echo "-------------------------------------------------------------"
echo ""

read Choice

case "$Choice" in
    "Wmv" | "WMV" | "wmv")
    echo "    This one WILL change the audio and video properties"
    echo "    of the file(s) it processes."
    echo "    Please adjust the parameters"
    echo "    of the script used in this example"
    echo "    to suit your needs."
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        wmv2aviloop.sh
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
      ;;

    "Flv" | "FLV" | "flv")
    echo "    This one WILL change the audio and video properties"
    echo "    of the file(s) it processes."
    echo "    Please adjust the parameters"
    echo "    of the script used in this example"
    echo "    to suit your needs."
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        for i in *.flv; do echo "$i" | flv2avi.sh; done
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;

    "Vob" | "VOB" | "vob")
    echo "    This will process your vob files and "
    echo "    leave you with a ogm file (without sound),"
    echo "    for you to process further."
    echo "    See this ubuntuforum thread for more on that:"
    echo "    http://ubuntuforums.org/showthread.php?t=1037517"
    echo "    Source (inspired on): http://ffmpeg.org/ffmpeg-doc.html"
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        for i in *.vob; do echo "$i" | vob2ogm.sh; done
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;

    "Avi" | "AVI" | "avi")
    echo "    Swap avi container for the free mkv one."
    echo "    Please note that:"
    echo "    This doesn't play well with file%20names%20with%20spaces.avi"
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        for i in *.avi; do echo "$i" | avi2mkv.sh; done
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;

    "Mpg" | "MPG" | "mpg")
    echo "    Swap mpg container for the free mkv one."
    echo "    If unsure?"
    echo "    Then depending on your needs? "
    echo "    Either run [cat] or [rep] first. "
    echo "    Hint: [Rep] comes after [cat]."
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        for i in *.mp*; do echo "$i" | mpg2mkv.sh; done
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;

    "Cat" | "CAT" | "cat")
    echo "    The following only applies to mp*g files."
    echo "    Just make sure your mp*g files are, "
    echo "    either in alpabetical or, "
    echo "    in a numerical order!!!"
    echo "    Don't forget to run [rep] hereafter."
    echo "    Available from within this script."
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes")
        cat.files.sh
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;
    "Quo" | "quo" | "quote")
    quote.sh
    ;;
# cd ~/.usr/bin
# ln -s -T mp42aviloop.sh mpg2aviloop.sh
## So calling either one of the two accomplishes the same goal.
    "Rep" | "REP" | "rep")
    echo "    Only useful when you've cat large amounts of mp(e)g files only to find "
    echo "    their index to be a bit off.  "
    echo "    Also useful to 'rename' mp4 files into avi files"
    echo
    echo "    Did your run [cat] before?"
    echo "    Hint: [Rep] comes after [cat]."
    echo "    Do you wish to continue?"
    echo
    echo -n "Enter either yes or no: "
    read answer
    case "$answer" in
        "YES" | "Yes" | "yes" | "Y" | "y")
        mp42aviloop.sh
          ;;
        "NO" | "No" | "no")
        exit 1
          ;;
        *)
         echo "   Wrong answer!!!"
         echo "   Please rerun the script again?"
         echo "   Then: Either enter yes or no."
         echo "   \"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
         echo "   Usage: Yes|No"
         echo
         exit 1
        ;;
    esac
    ;;

    *)
     # Default option.
     # Empty input (hitting RETURN) fits here, too.
     echo
     echo "Please choose a valid option."
     echo "\"UPPER\", \"lower\" and \"Capitalized\" spelling are supported"
     echo "Usage: wmv|flv|vob|avi|mpg"
     echo
    ;;
esac

exit 0
## One might figure out to do full recursion with the use of this beauty\!
## Be careful though\!
# find -iname '*.ext' -exec someScript "{}" \;
## This script depends on:
# sudo apt-get install libdvdcss2 k9copy \
# ffmpeg2theora mkvtoolnix-gui avidemux mencoder ffmpeg
## amongst things to work properly

Which will largely be based on the one below. 😉

#!/bin/bash
# Modified: Today by E.l.f.
## # Source: http://tldp.org/LDP/abs/html/testbranch.html
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
#
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
#
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the Free Software Foundation, Inc., 51
## Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## http://www.gnu.org/copyleft/gpl.html
#
## Script-name - select_stream.sh
## Can be executed by user (no need for sudo/root access)
## Sanity check.
## The following 8 lines of code have been kindly
## ripped from 71529-ubucleaner.sh  : - )
YELLOW="\033[1;33m"
RED="\033[0;31m"
ENDCOLOR="\033[0m"
if [ $USER = root ]; then
echo -e $RED"Error: In order to use this script, one must NOT be $USER"
echo -e $YELLOW"Exiting..."$ENDCOLOR
exit 0
else
echo ""
echo "The user $USER may proceed."
fi
## These are valid streams but feel free, 
## better yet I (have to) encourage you,
## to change these values!  
## To something jazzy or classical instead, perhaps?  ; - )
BassDrive=$(echo "http://shouthostdirect13.streams.bassdrive.com:8202/")
export BassDrive
Free=$(echo "http://88.191.69.69:80/")
export Free
Folder=$(echo "$HOME/Music/Streams")
export Folder
[ ! -d "$Folder" ] && mkdir $Folder
clear # Clear the screen.
echo "          Stream List"
echo "          ------- ----"
echo "Choose one of the following streams:"
echo
echo "Hit Ctrl+c (^c) to stop recording"
echo
echo "[B]assdrive, Bassdrive.com"
echo "[F]ree hardcore, happyhardcore.com"
echo "[I]nsert something else here, uptoyou.com"
echo
read Stream
NOW="$Stream"-$(date +%F_%k-%M)
OUTFILE=$(echo "$Folder/$NOW.mp3")
export OUTFILE
case "$Stream" in
## Note variables are quoted.
## Basic syntax
# "Selection 1" | "Selection 2" )
# echo "Something to inform the user"
# echo "and then some more.  : - )"
# /usr/bin/<command> to be run with predefined selections.
# ;;
## Note the double semicolon to terminate each option.
# * )
## Default option.
## Empty input (hitting RETURN) fits here, too.
# echo
# echo "Please choose a valid <object>."
# ;;
# esac
# echo
"B" | "b" )
# Accept upper or lowercase input.
echo
echo "Bassdrive - Music Beyond (Free stream)"
echo "http://shouthostdirect13.streams.bassdrive.com:8202/"
echo "Your stream will be saved in $Folder, "
echo "with the name: $NOW.mp3. "
/usr/bin/cvlc -v "$BassDrive" \
':sout=#transcode{acodec=mp3,channels=2}\
:duplicate{dst=display,dst=std{access=file,mux=raw,dst="'$OUTFILE'"}}'
;;
# Note double semicolon to terminate each option.
"F" | "f" )
# Accept upper or lowercase input.
echo
echo "Hardcore 24/7 happyhardcore.com (Free Stream)"
echo "http://88.191.69.69:80/"
echo "Your stream will be saved in $Folder, "
echo "with the name: $NOW.mp3. "
/usr/bin/cvlc -v "$Hardcore" \
':sout=#transcode{acodec=mp3,channels=2,ab=128}\
:duplicate{dst=display,dst=std{access=file,mux=raw,dst="'$OUTFILE'"}}'
;;
# Note double semicolon to terminate each option.
# Add info here for later.
* )
# Default option.
# Empty input (hitting RETURN) fits here, too.
echo
echo "Please choose a valid stream."
;;
esac
echo
exit 0

——————————————————————————–
PS: I am currently thinking about making an ‘easy’ script to ease the installation of packages referred to by the “Comprehensive Multimedia & Video How to“. Though I must say that the last time I did this for my 64bit install, I got apt complaining about missing packages and such. But I’ll keep you posted of my progress anyway! 😆

Yes of course there are always legal matters to attend to, especially when you live in a ‘restricted area’ (take that as you like!?) But for what it is worth: http://monomaxos.com/eng.htm could offer you a possible way around this problem!? 😉

See their terms of use for what I mean.

TERMS OF USE FOR MONOMAXOS 2 ENGLISH EDITION LIVE DVD

MONOMAXOS Linux Operating System is only provided for ‘’demonstration’’ of the capabilities of Linux and Free Software for amateur PC users that haven’t the knowledge to build such a complicated Linux Operating System in their Home Computer and you cannot use it for commercial purposes. MONOMAXOS ISO in this current edition contains ‘’ free ‘’ (read more about the conditions of using free software in the links below) software packages (hardware drivers & software) that are not supposed to be provided functional, in a ‘’ready to use’’ Linux distribution (especially in the U.S.).

http://www.gnu.org/licenses/licenses.html

http://www.ubuntu.com/community/ubuntustory/licensing

For this reason you have to accept that user emcpn made this DVD ISO ‘’only’’ for you, after your request and because you didn’t have any idea how you could come up with something like this , only for educational reasons in order to test the capabilities of Linux Operating Systems.

If you are happy with all these you can proceed to the download of the DVD ISO. If you don’t like the idea of using such a piece of software you can still create your own ‘’MONOMAXOS like’’ , Live DVD using the source packages that were used for MONOMAXOS which are available for download from fast Rapishare.com servers 24 hours per day. The size of the original source packages is about 7 GB and includes everything you need up to the last byte !!! You can find all the software packages and their dependencies plus lists containing all the information of people that created them , their emails and web page address to download newest editions of them.

MONOMAXOS SOURCE PACKAGES DOWNLOAD LINKS

If you are still NOT happy with all this situation and you think that I spend your time for no reason , I have to apologize for this and ask you to leave this web page.

Any questions? I am always just a few clicks away. 😉

Cheers,

Alex

Hmm… Garbled formatting? *Cough cough* How about those smilies in the code you posted?


It might be useful to post the links to the accompanying scripts. 😆