don't touch files with hardlinks (unless -f)
[soepkiptng.git] / soepkiptng_add_shoutcast
blob3aaac8dd4a83b87435a4108497280038287ebbc1
1 #!/usr/bin/perl
2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 ############################################################################
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License, version 2, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # A copy of the GNU General Public License is available on the World Wide Web
15 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
16 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18 ############################################################################
20 use Cwd 'abs_path';
21 use Getopt::Std;
23 # find program directory
24 $_ = $0;
25 while(-l) {
26 my $l = readlink or die "readlink $_: $!\n";
27 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
29 m|(.*)/|;
30 my $progdir = abs_path($1);
32 require "$progdir/soepkiptng.lib";
34 getopts('c:');
36 read_configfile(\%conf, $opt_c);
38 $ENV{PATH} = "$progdir/bin:$ENV{PATH}";
39 use lib "$progdir/lib";
41 sub add_shout($$) {
42 my ($url, $desc) = @_;
44 my $arid = get_id($dbh, "artist", '') or die;
45 my $alid = get_id($dbh, "album", '') or die;
46 $dbh->do("REPLACE INTO song SET title=?, filename=?, album_id=?, " .
47 "artist_id=?, present=1, encoding=\"Shoutcast\", track=0, " .
48 "length=0, time_added=NULL", undef,
49 $desc, $url, $alid, $arid) or die;
51 warn "Added $url: $desc\n";
52 if($have_stream{$url}) { $num_updated++; }
53 else { $num_added++; }
57 use DBI;
59 $dbh = connect_to_db(\%conf);
61 my $shc = $dbh->selectcol_arrayref("SELECT filename FROM song WHERE filename LIKE \"http:%\"");
62 foreach(@$shc) {
63 $have_stream{$_} = 1;
64 # warn "have $_\n";
67 foreach(@ARGV) {
68 open F, $_ or do {
69 warn "$_: $!\n";
70 next;
72 my (@url, @title);
73 while(<F>) {
74 if(/^File(\d+)\s*=\s*(http:\S+)/) {
75 $url[$1] = $2;
76 next;
78 if(/^Title(\d+)\s*=\s*(.*\S+)/) {
79 $title[$1] = $2;
80 next;
82 if(/^(http:\S+)/) {
83 add_shout($1, $1);
84 next;
87 close F;
89 for($i = 0; $i < @url; $i++) {
90 add_shout($url[$i], $title[$i] || $url[$i])
91 if $url[$i];
95 $dbh->disconnect();
97 printf <<EOF, $num_added, $num_updated;
98 %4d Shoutcast streams added.
99 %4d Shoutcast streams updated.