547b96d39809486093397de17afc03ae322c063c
[id3fs.git] / bin / id3fs
1 #!/usr/bin/perl -w
2 # Ian Beckwith <ianb@erislabs.net>
3 #
4
5 use lib '/home/ianb/projects/id3fs/id3fs/lib';
6 use strict;
7 use Getopt::Long qw(Configure);
8 use ID3FS::DB;
9 use File::Find;
10 use vars qw($me);
11 $me=($0=~/(?:.*\/)?(.*)/)[0];
12
13 my $verbose=0;
14 my $help=0;
15 my $basedir=undef;
16 my $dbpath=undef;
17
18 my @extensions=qw(mp3); # ogg flac); # FIXME
19 Configure(qw(bundling no_ignore_case));
20 my $optret=GetOptions(
21     "verbose|v"      => \$verbose,
22     "quiet|q"        => sub { $verbose=0; },
23     "help|h"         => \$help,
24     "basedir|d=s"    => \$basedir,
25     "database|db=s"  => \$dbpath,
26     "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); },
27     );
28
29 usage() if(!@ARGV || !$optret || $help);
30
31 if(@ARGV > 1 && !defined($basedir))
32 {
33     die("$me: --basedir must be specified if multiple paths are supplied\n");
34 }
35
36 my $db=ID3FS::DB->new($me, $dbpath, $basedir, $ARGV[0]);
37
38 while(my $path=shift)
39 {
40     File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
41 }
42
43 sub wanted
44 {
45     my $ext='';
46     if(/.*\.(.*)/) { $ext=lc($1); }
47     if(-d)
48     {
49         print("$_\n") if $verbose;
50     }
51     elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
52     {
53         s/^\.\///;
54         $db->add($_);
55     }
56 }
57
58 sub usage
59 {
60     die("Usage: $me [-v] [-q] [-h] [--] file...\n".
61         " -v\tVerbose\n".
62         " -q\tQuiet (default)\n".
63         " -h\tThis help\n".
64         " --\tEnd of options\n");
65 }
66
67 __END__
68
69
70 =head1 NAME
71
72 program - description
73
74 =head1 SYNOPSIS
75
76 B<> [I<-v>] [I<-q>] [I<-h>] [I<file>...]
77
78 =head1 DESCRIPTION
79
80 =head1 OPTIONS
81
82 =over 4
83
84 =item B<-v>
85
86 Enable verbose operation.
87
88 =item B<-q>
89
90 Quiet (no output). This is the default.
91
92 =item B<-h>
93
94 Show a short help message.
95
96 =item B<-->
97
98 End of options.
99
100 =back
101
102 =head1 FILES
103
104 =head1 ENVIRONMENT
105
106 =head1 DIAGNOSTICS
107
108 =head1 BUGS
109
110 None known. Please report any found to ianb@erislabs.net
111
112 =head1 SEE ALSO
113
114 =head1 AUTHOR
115
116 Ian Beckwith <ianb@erislabs.net>
117
118 =head1 AVAILABILITY
119
120 The latest version can be found at:
121
122 B<http://erislabs.net/ianb/projects/id3fs/>
123
124 =head1 COPYRIGHT
125
126 Copyright 2010 Ian Beckwith <ianb@erislabs.net>
127
128 This program is free software: you can redistribute it and/or modify
129 it under the terms of the GNU General Public License as published by
130 the Free Software Foundation; either version 3 of the License, or
131 (at your option) any later version.
132
133 This program is distributed in the hope that it will be useful,
134 but WITHOUT ANY WARRANTY; without even the implied warranty of
135 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
136 GNU General Public License for more details.
137
138 You should have received a copy of the GNU General Public License
139 along with this program.  If not, see <http://www.gnu.org/licenses/>.
140
141 =cut