blob: 7a40a4b44e10d836a0cf02d2daa0fa8001137ddb (
plain)
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
|
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use Audio::Scan;
use File::HomeDir;
# Keep track of columns that need to be created in the database
our %columns = (
ID => '1'
);
# Variables to be set by user (TODO)
our $music_dir = File::HomeDir->my_home . "/Music/";
# Scan a directory recursively, return an array of files (optionally, matching a certain file extension or extensions TODO)
sub scan_dir {
my @file_list;
# Remove extra /'s from the end of $_[0]
$_[0] =~ s/\/+$//g;
my $dir_path = $_[0];
my @extensions = $_[1]; #TODO
opendir my $dh, "$dir_path" or die "$!";
while (my $file = readdir($dh)) {
# Skip . and .. directories
if ($file eq "." or $file eq ".."){
next;
}
if (-d "$dir_path/$file"){
push(@file_list, scan_dir("$dir_path/$file", @extensions));
}
elsif (-f "$dir_path/$file" and -r "$dir_path/$file"){
push(@file_list, "$dir_path/$file");
}
}
closedir $dh;
return @file_list;
}
# Test scan for Audio::Scan module
sub scan_test {
my $data = Audio::Scan->scan("/home/louie/Music/Bjork/Debut/01 Human Behaviour.flac");
$data = $data->{tags};
for (keys %$data){
print "$_ -> $data->{$_}\n";
}
}
# TODO parse flags and arguments
# Test to ensure $music_dir is a valid directory
if (! -d $music_dir){
die "Error: \"$music_dir\" is not a directory\n";
}
# Look through files in $music_dir
print "Looking through files in $music_dir\n";
my @file_list = scan_dir($music_dir);
for my $i (sort @file_list){
print "$i\n";
}
|