In light of religious terrorist attacks in Paris, please see Category:blasphemy!

Freedom Porn:free technology/theoracomment

From Freedom Porn
Jump to: navigation, search

theoracomment is a shell-script which allows a user to do the same thing that vorbiscomment from libogg package does, but to an Ogg Theora file. It uses liboggz package to do the work.

Licence

Available under the terms of GNU General Public License 3.0

Produced in the year 2010.
GPLv3
For more information please see Freedom Porn:copyrights.


Known bugs

  • If there are other metadata available (on other streams) it will be deleted. It is probably liboggz bug.

Code

#!/bin/bash
 
# Name: theoracomment
# Version: 0,1a
# Author: Volodya
# Year: 2010
# Licence: GPL 3.0
 
# this is an theoracomment, wrapper around oggz-comment that changes theora comments inside a file
# it is intended to have the same parameters as vorbiscomment
 
# the command line should be in the form
# theoracomment [-a | -w] [-c metadata.txt | -t "name=value"] [-q] input.ogv output.ogv
# or
# theoracomment [-l] input.ogv
# theoracomment -h|--help
 
#if help
if [ -z "$1" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
	echo "theoracomment version 0,1a. written by VolodyA! V Anarhist"
	echo "The command line should look like this:"
	echo "theoracomment [-a | -w] [-c metadata.txt | -t "name=value"] [-q] input.ogv output.ogv"
	exit
fi
 
 
#go through all the command line a word at a time
OUTPUT=""
DELETE="--delete"
STREAMS="--content-type theora"
METADATA=""
INPUT=""
 
STATE=""
for COMMAND in "$@"; do
	if [ ${COMMAND:0:1} = "-" ]; then
		if [ "$COMMAND" = "-a" ] || [ "$COMMAND" = "--append" ] || [ "$COMMAND" = "--add" ]; then
			DELETE=""
			STATE=""
		elif [ "$COMMAND" = "-w" ] || [ "$COMMAND" = "--write" ] || [ "$COMMAND" = "--wipe" ]; then
			DELETE="--delete"
			STATE=""
		elif [ "$COMMAND" = "-l" ] || [ "$COMMAND" = "--list" ]; then
			STATE="--list"
		elif [ "$COMMAND" = "-c" ] || [ "$COMMAND" = "--comment-file" ] || [ "$COMMAND" = "--commentfile" ]; then
			STATE="--comment-file"
		elif [ "$COMMAND" = "-t" ] || [ "$COMMAND" = "--tag" ]; then
			STATE="--tag"
		elif [ "$COMMAND" = "-R" ] || [ "$COMMAND" = "--raw" ]; then
			#ignore, is meant to read/write in UTF-8
			STATE=""
		elif [ "$COMMAND" = "-q" ] || [ "$COMMAND" = "--quiet" ]; then
			#ignore, is meant to read/write in UTF-8
			STATE=""
		else
			echo "Wrong command command '$COMMAND'"
			echo "Use oggz-comments --help for useage information."
			exit 1
		fi
	elif [ -n "$STATE" ]; then # if the STATE is not zero-length
		if [ "$STATE" = "--list" ]; then
			if [ ! -f "$1" ] || [ ! -r "$1" ]; then
				echo "File '$1' doesn't exist or is not readable"
				exit 2
			fi
			# h - hold the old line, G - append the old line to new
			# it's used to capitalise only before ': ', the substitution is needed
			# but we combine the substitution to change ': ' to '='
			eval oggz-comment --content-type theora -l "$1" | sed ' {
				/^[^\t]/d
				s/^\t//g
				/^Vendor/d
				h
				y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
				G
				s/: .*: /=/
			}'
			exit 0 #everything is done
		elif [ "$STATE" = "--tag" ]; then
			METADATA="$METADATA $1"
		elif [ "$STATE" = "--comment-file" ]; then
			if [ ! -f "$1" ] || [ ! -r "$1" ]; then
				echo "File '$1' doesn't exist or is not readable"
				exit 2
			fi
			while read LINE
			do
				METADATA="$METADATA \"$LINE\""
			done < "$1"
		fi
		STATE=""
	else
		if [ -n "$INPUT" ]; then
			OUTPUT="--output $1"
		else
			if [ ! -f "$1" ] || [ ! -r "$1" ]; then
				echo "File '$1' doesn't exist or is not readable"
				exit 2
			fi
			INPUT="$1"
		fi
	fi
	shift
done
 
if [ -z "$METADATA" ]; then # need to read metadata from console
	while read LINE
	do
		METADATA="$METADATA \"$LINE\""
	done
fi
 
if [ -n "$OUTPUT" ]; then
	eval oggz-comment $OUTPUT $DELETE $STREAMS $INPUT $METADATA
	# Letting people know what was done
	echo "oggz-comment $OUTPUT $DELETE $STREAMS $INPUT $METADATA"
else
	for i in {1..100}
	do
		if [ ! -f "$INPUT~$i~" ] && [ ! -r "$INPUT~$i~" ] && [ ! -d "$INPUT~$i~" ]; then
			eval mv "$INPUT" "$INPUT~$i~"
			OUTPUT="--output $INPUT"
			INPUT="$INPUT~$i~"
			break
		fi
	done
	if [ -n "$OUTPUT" ]; then
		echo oggz-comment $OUTPUT $DELETE $STREAMS $INPUT $METADATA
		eval oggz-comment $OUTPUT $DELETE $STREAMS $INPUT $METADATA
		eval rm $INPUT
	else
		echo Unable to create a temporary file name
	fi
fi