2 # Ian Beckwith <ianb@erislabs.net>
5 use lib '/home/ianb/projects/id3fs/id3fs/lib'; # FIXME: remove
7 use Getopt::Long qw(Configure);
11 $me=($0=~/(?:.*\/)?(.*)/)[0];
19 my @extensions=qw(mp3 flac ogg);
22 Configure(qw(bundling no_ignore_case));
23 my $optret=GetOptions(
24 "verbose|v" => \$verbose,
25 "quiet|q" => sub { $verbose=0; },
27 "dir|d=s" => \$basedir,
28 "database|f=s" => \$dbpath,
29 "extensions|e=s" => sub { @extensions=split(/\s+|\s*,\s*/, $_[1]); },
33 usage() if(!@ARGV || !$optret || $help);
34 $init=1 unless($list);
36 if(@ARGV > 1 && !defined($basedir))
38 die("$me: --basedir must be specified if multiple paths are supplied\n");
41 my $db=ID3FS::DB->new($me, $verbose, $init, $dbpath, $basedir, $ARGV[0]);
50 $db->last_update(time());
51 my $base=$db->base_dir();
52 my $abs_base=Cwd::abs_path($base);
55 if(Cwd::abs_path($path) !~ /^$abs_base/)
57 print "$me: $path is outside $base, skipping\n";
59 File::Find::find( {wanted => \&wanted, follow => 1, no_chdir => 1}, $path);
61 my $directories_pruned=$db->prune_directories();
62 if($files_pruned || $directories_pruned)
64 print "$me: removing data from pruned files\n" if $verbose;
67 print "$me: analyzing db\n" if $verbose;
74 if(/.*\.(.*)/) { $ext=lc($1); }
77 print("$_\n") if $verbose;
80 elsif(-f && scalar(grep({ $ext eq lc($_);} @extensions)))
91 $dir=Cwd::abs_path($dir);
92 return unless(opendir(DIR, $dir));
93 my $base=Cwd::abs_path($db->base_dir());
95 my @oldfiles=$db->files_in($dir);
96 my @newfiles=grep { !/^\.\.?$/; } readdir(DIR);
98 @oldfiles=sort @oldfiles;
99 @newfiles=sort @newfiles;
102 for my $file (@oldfiles)
104 unless(exists($hash{$file}))
107 $db->unindex($dir, $file);
115 my @baretags=$db->bare_tags();
116 my $valtags=$db->tags_with_values();
120 print join(', ', sort @baretags), "\n\n";
124 print "TAGS WITH VALUES\n";
125 for my $key (sort keys %$valtags)
127 print "$key: ", join(', ', sort(@{$valtags->{$key}})), "\n";
134 die("Usage: $me [-vqh] [-d basedir] [-f dbpath] [-e mp3,ogg,flac] [--] DIR...\n".
135 " -v|--verbose\t\t\tVerbose\n".
136 " -q|--quiet\t\t\tQuiet (default)\n".
137 " -d|--dir=PATH\t\t\tBase directory of source files (default: ARGV[0])\n".
138 " -f|--database=FILE\t\tPath to database file (default: basedir/.id3fs)\n".
139 " -e|--extensions=EXT1,EXT2\tFile extensions to index (default: mp3, ogg, flac)\n".
140 " -h|--help\t\t\tThis help\n".
141 " --\t\t\t\tEnd of options\n");
148 id3fs-index - Add files to id3fs index
152 B<id3fs-index> [B<-vqh>] S<[B<-d >I<basedir>]> S<[B<-f >I<dbpath>]> S<[B<-e >I<mp3,ogg,flac>]> [B<-->] [I<DIR>...]
156 Extracts id3 tags from mp3 files (and comment tags from ogg and flac
157 files) and adds them to a sqlite database, ready for mounting
166 Enable verbose operation.
170 Quiet (no output). This is the default.
172 =item S<B<-d >I<PATH>> | S<B<--dir=>I<PATH>>
174 Specify base directory of source files. All files will be indexed
175 relative to this point.
177 If not specified, defaults to the first non-option argument on the
178 command line. Note that to avoid ambiguities, if more than one
179 directory is specified on the command line, the base directory must
180 be specified explicitly.
182 All files indexed must be under the base directory.
184 =item S<B<-f >I<FILE>> | S<B<--database=>I<FILE>>
186 Database file to use. If not specified, defaults to
187 a hidden file called B<".id3fs"> under the base directory.
189 =item S<B<-e >I<EXT1,EXT2>> | S<B<--extensions=>I<EXT1,EXT2>>
191 File extensions to consider when indexing.
192 Defaults to B<.mp3>, B<.ogg> and B<.flac>.
196 Show a short help message.
206 Index all files in the current directory:
210 Index current directory, printing each subdirectory as it recurses
215 Just index some sub-directories:
217 id3fs-index -d . dir1 dir2
219 Store the database in a custom location:
221 id3fs-index -f ~/.id3fs/index.sqlite .
223 Only index .mp3 and .flac files:
225 id3fs-index -e mp3,flac .
229 Please report any found to ianb@erislabs.net
237 Ian Beckwith <ianb@erislabs.net>
241 The latest version can be found at:
243 B<http://erislabs.net/ianb/projects/id3fs/>
247 Copyright 2010 Ian Beckwith <ianb@erislabs.net>
249 This program is free software: you can redistribute it and/or modify
250 it under the terms of the GNU General Public License as published by
251 the Free Software Foundation; either version 3 of the License, or
252 (at your option) any later version.
254 This program is distributed in the hope that it will be useful,
255 but WITHOUT ANY WARRANTY; without even the implied warranty of
256 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
257 GNU General Public License for more details.
259 You should have received a copy of the GNU General Public License
260 along with this program. If not, see <http://www.gnu.org/licenses/>.