[vorbis-dev] using vorbiscomment

Alex Shinn foof at debian.org
Sun Oct 15 13:57:42 PDT 2000



>>>>> "Kenneth" == Kenneth Arnold <ken at arnoldnet.net> writes:

[snip repetitive code]

    Kenneth> It would seem like there should be an easier way to
    Kenneth> implement that...  Don't ask me, though.

Ah, you're right... I've been ignoring some features of Getopt::Long.

    Kenneth> How about custom comments? The script should provide a
    Kenneth> means to insert, delete, and move these around. Also, it
    Kenneth> is possible (and indeed useful) to have multiple artist,
    Kenneth> description, title, location, etc. tags. Maybe you need
    Kenneth> to rethink the interface just a little.

I didn't want to allow commands like

$ ogginfo COLOR=BLUE foo.ogg

because theoretically you could have a file called COLOR=BLUE.  Maybe
that's overly cautious... you could ignore files that don't end in
.ogg.  Anyway, I just added support for

$ ogginfo --comment COLOR=BLUE foo.ogg

or 

$ ogginfo -C QUEST="To seek the Grail" foo.ogg

... etc.

Note about Perl path included, changes attached.


-- 
Alex





#!/usr/bin/perl -w

# If your Perl implementation resides somewhere other than
# /usr/bin/perl, change the above line to reflect that.

## ogginfo -- Ogg Vorbis Comment Editor

## Created:    <Sun Oct 15 02:57:05 EDT 2000>
## Time-stamp: <Sun Oct 15 16:49:08 EDT 2000>
## Author:     Alex Shinn <foof at debian.org>

# Modules
use strict;
use Getopt::Long;

# Variables
my $version = '0.2';
my (%opt, %old, %new);
my ($k, $v);

# Parse Options
GetOptions(\%opt, 'help|h|?!','ogg-version|V!','title|t:s',
           'version|v:s','album|l:s','artist|a:s',
           'organization|o:s','description|D:s','genre|g:s',
           'date|d:s','location|p:s','copyright|c:s','comment|C:s%')
  or usage();
usage() if $opt{help};
version() if $opt{'ogg-version'};
# Read comment options
$new{title} = $opt{title} if exists $opt{title};
$new{version} = $opt{version} if exists $opt{version};
$new{album} = $opt{album} if exists $opt{album};
$new{artist} = $opt{artist} if exists $opt{artist};
$new{organization} = $opt{organization} if exists $opt{organization};
$new{description} = $opt{description} if exists $opt{description};
$new{genre} = $opt{genre} if exists $opt{genre};
$new{date} = $opt{date} if exists $opt{date};
$new{location} = $opt{location} if exists $opt{location};
$new{copyright} = $opt{copyright} if exists $opt{copyright};
# Add custom comments
while (($k, $v) = each(%{$opt{comment}})) {
  $new{$k} = $v;
}

# Act on each remaining arg
foreach my $ogg (@ARGV) {
  # Get existing comments
  %old = map { my ($tag, $value) = split(/=/,$_,2); chop($value);
               "\L$tag", $value }
    `vorbiscomment -l $ogg 2>/dev/null`;
  next if $?;
  # Merge new comments
  while (($k, $v) = each(%new)) {
    $old{$k} = $v;
  }
  if (%new) {
    # Set new comments
    open(OUTPUT, "| vorbiscomment $ogg 2>/dev/null") || next;
    while (($k, $v) = each(%old)) {
      if ($v) {
        print OUTPUT "\U$k", "=$v\n";
      }
    }
    close(OUTPUT);
  }
  else {
    while (($k, $v) = each(%old)) {
      print "\U$k", "=$v\n";
    }
  }
}

# Print a usage summary
sub usage {
  print <<EOF;
usage: $0 [options] [file ...]

  -h, --help                 display this message
  -V, --ogg-version          print version info
  -t, --title TITLE          set title
  -v, --version VERSION      set title version
  -l, --album ALBUM          set album
  -a, --artist ARTIST        set artist
  -o, --organization ORG     set organization/record label
  -D, --description DESC     set brief contents description
  -g, --genre GENRE          set short genre description
  -d, --date DATE            set date
  -p, --location PLACE       set recording location info
  -c, --copyright COPY       set copyright info
  -C, --comment TAG=VALUE    set a custom comment
EOF
  exit 0;
}

# Print version info
sub version {
  print "$0 $version\n";
  exit 0;
}

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list