File: OGG.pm

package info (click to toggle)
lltag 0.14.4-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 448 kB
  • ctags: 301
  • sloc: perl: 2,833; makefile: 120; sh: 17
file content (90 lines) | stat: -rw-r--r-- 2,319 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package Lltag::OGG ;

use strict ;

require Lltag::Tags ;
require Lltag::Misc ;

sub test_vorbiscomment {
    my $self = shift ;
    my ($status, @output) = Lltag::Misc::system_with_output ("vorbiscomment", "-h") ;
    print "vorbiscomment does not seem to work (is the 'vorbis-tools' package installed?), disabling 'OGG' backend.\n"
	if $status and $self->{verbose_opt} ;
    return $status ;
}

sub read_tags {
    my $self = shift ;
    my $file = shift ;
    my ($status, @output) = Lltag::Misc::system_with_output
	("vorbiscomment", "-l", $file) ;
    return undef
	if $status ;
    @output = map {
	my $line = $_ ;
	$line =~ s/^TRACKNUMBER=/NUMBER=/ ;
	$line
	} @output ;
    return Lltag::Tags::convert_tag_stream_to_values ($self, @output) ;
}

sub set_tags {
    my $self = shift ;
    my $file = shift ;
    my $values = shift ;

    my %field_name_ogg_translations =
	(
	 'NUMBER'  => 'TRACKNUMBER',
	 ) ;
    my @ogg_tagging_cmd = ( 'vorbiscomment', '-q' ) ;
    my @ogg_tagging_clear_option = ( '-w' ) ;

    # apply regular tags
    my @regular_tags_args =
	    ( map {
		my $oggname = $_ ;
		$oggname = $field_name_ogg_translations{$_} if defined $field_name_ogg_translations{$_} ;
		my @tags = (Lltag::Tags::get_tag_value_array $self, $values, $_) ;
		map { ( "-t" , $oggname."=".$_ ) } @tags
		} @{$self->{field_names}}
	      ) ;
    # apply non-regular tags
    my @non_regular_tags_args =
	    ( map {
		my $oggname = $_ ;
		my @tags = (Lltag::Tags::get_tag_value_array $self, $values, $_) ;
		map { ( "-t" , $oggname."=".$_ ) } @tags
		} Lltag::Tags::get_values_non_regular_keys ($self, $values)
	      ) ;
    # work-around vorbiscomment which does not like when tags is passed
    my @workaround_args = (scalar @regular_tags_args + @non_regular_tags_args) ? () : ("-c", "/dev/null") ;

    my @system_args
	= ( @ogg_tagging_cmd ,
	    # clear all tags
	    @ogg_tagging_clear_option ,
	    @regular_tags_args ,
	    @non_regular_tags_args ,
	    @workaround_args ,	    
	    $file ) ;

    Lltag::Tags::set_tags_with_external_prog ($self, @system_args) ;
}

sub new {
    my $self = shift ;

    return undef
	if test_vorbiscomment $self ;

    return {
	name => "OGG (using vorbiscomment)",
	type => "ogg",
	extension => "ogg",
	read_tags => \&read_tags,
	set_tags => \&set_tags,
    } ;
}

1 ;