last_update: store in id3fs table, update when index is updated,
[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 $db->last_update(time());
38
39 while(my $path=shift)
40 {
41     File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
42 }
43
44 sub wanted
45 {
46     my $ext='';
47     if(/.*\.(.*)/) { $ext=lc($1); }
48     if(-d)
49     {
50         print("$_\n") if $verbose;
51     }
52     elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
53     {
54         s/^\.\///;
55         $db->add($_);
56     }
57 }
58
59 sub usage
60 {
61     die("Usage: $me [-v] [-q] [-h] [--] file...\n".
62         " -v\tVerbose\n".
63         " -q\tQuiet (default)\n".
64         " -h\tThis help\n".
65         " --\tEnd of options\n");
66 }
67
68 __END__
69
70
71 =head1 NAME
72
73 program - description
74
75 =head1 SYNOPSIS
76
77 B<> [I<-v>] [I<-q>] [I<-h>] [I<file>...]
78
79 =head1 DESCRIPTION
80
81 =head1 OPTIONS
82
83 =over 4
84
85 =item B<-v>
86
87 Enable verbose operation.
88
89 =item B<-q>
90
91 Quiet (no output). This is the default.
92
93 =item B<-h>
94
95 Show a short help message.
96
97 =item B<-->
98
99 End of options.
100
101 =back
102
103 =head1 FILES
104
105 =head1 ENVIRONMENT
106
107 =head1 DIAGNOSTICS
108
109 =head1 BUGS
110
111 None known. Please report any found to ianb@erislabs.net
112
113 =head1 SEE ALSO
114
115 =head1 AUTHOR
116
117 Ian Beckwith <ianb@erislabs.net>
118
119 =head1 AVAILABILITY
120
121 The latest version can be found at:
122
123 B<http://erislabs.net/ianb/projects/id3fs/>
124
125 =head1 COPYRIGHT
126
127 Copyright 2010 Ian Beckwith <ianb@erislabs.net>
128
129 This program is free software: you can redistribute it and/or modify
130 it under the terms of the GNU General Public License as published by
131 the Free Software Foundation; either version 3 of the License, or
132 (at your option) any later version.
133
134 This program is distributed in the hope that it will be useful,
135 but WITHOUT ANY WARRANTY; without even the implied warranty of
136 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
137 GNU General Public License for more details.
138
139 You should have received a copy of the GNU General Public License
140 along with this program.  If not, see <http://www.gnu.org/licenses/>.
141
142 =cut