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

5 thoughts on “How to quote from your media.

    • I’ve no interest in ‘frostwire’, for all purposes. I exclusively use ktorrent as an ‘non privileged’ (kde allows this! when logged in as the initial) user and so far I am VERY pleased.
      For example:
      ALT+F2 – means run, similar to win+r mind you… 😉
      Then for konqueror; do

      kdesudo -u "yourUser" -c konqueror
      

      done
      And for ktorrent; do

      kdesudo -u "yourUser" -c ktorrent
      

      done

      Like

  1. Pingback: Grab that screen! « Bohemian Wildebeest's Blog

Comments are closed.