fordon_greeman / voidfiles

Branch: 2079ec5
Switch branches/tags
main
theidioticdev add emacs 2079ec5 23h ago
100 lines · 3.2 KB Raw Blame History
1 #!/usr/bin/perl
2 # emms-print-metadata.pl --- Info function for libtag
3 # Copyright (C) 2012 Free Software Foundation, Inc.
4
5 # Author: Lucas Bonnet <lbonnet@rincevent.net>
6
7 # This file is part of EMMS.
8
9 # EMMS is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3, or (at your option)
12 # any later version.
13
14 # EMMS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with EMMS; see the file COPYING. If not, write to
21 # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 # Boston, MA 02110-1301, USA.
23
24 use strict;
25 use warnings;
26
27 use Audio::Scan;
28 use File::Basename;
29
30 # enable UTF-8 output
31 binmode(STDOUT, ":utf8");
32
33 my $file = $ARGV[0];
34
35 # Scan without reading (possibly large) artwork into memory.
36 # Instead of binary artwork data, the size of the artwork will be returned instead.
37 local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
38 my $data = Audio::Scan->scan($file);
39
40 # determines the names of tags according to file type
41 my %ext_map = ("mp3" =>
42 {'artist' => 'TPE1',
43 'title' => 'TIT2',
44 'album' => 'TALB',
45 'tracknumber' => 'TRCK',
46 'composer' => 'TCOM',
47 'performer' => 'TPE2',
48 'year' => 'TDRC',
49 'genre' => 'TCON',
50 'comment' => 'COMM'},
51 "flc" =>
52 {'artist' => 'ARTIST',
53 'title' => 'TITLE',
54 'album' => 'ALBUM',
55 'tracknumber' => 'TRACKNUMBER',
56 'composer' => 'COMPOSER',
57 'performer' => 'PERFORMER',
58 'year' => 'DATE',
59 'genre' => 'GENRE',
60 'comment' => 'COMMENT'},
61 "ogg" =>
62 {'artist' => 'ARTIST',
63 'title' => 'TITLE',
64 'album' => 'ALBUM',
65 'tracknumber' => 'TRACKNUMBER',
66 'composer' => 'COMPOSER',
67 'performer' => 'PERFORMER',
68 'year' => 'DATE',
69 'genre' => 'GENRE',
70 'comment' => 'COMMENT'},
71 );
72
73 # find out extension
74 my ($filename, $directories, $extension) = fileparse($file, qr/[^.]*/);
75 my $type = Audio::Scan->type_for(lc($extension));
76 my $tag_map = $ext_map{$type};
77
78 # print tag info
79 print "info-artist="; safe_print('artist');
80 print "info-title="; safe_print('title');
81 print "info-album="; safe_print('album');
82 print "info-tracknumber="; safe_print('tracknumber');
83 print "info-composer="; safe_print('composer');
84 print "info-performer="; safe_print('performer');
85 print "info-year="; safe_print('year');
86 print "info-genre="; safe_print('genre');
87 print "info-note=" ; safe_print('comment');
88
89 print "info-playing-time=",int($data->{'info'}->{'song_length_ms'} / 1000),"\n";
90
91 sub safe_print {
92 my $k = shift;
93
94 if (defined $data->{'tags'}->{ $tag_map->{$k} }) {
95 print $data->{'tags'}->{ $tag_map->{$k} };
96 } else {
97 print "<no $k>";
98 }
99 print "\n";
100 }