fix .ogg info update
[soepkiptng.git] / soepkiptng_add_shoutcast
blobff1e00069efb715e940ad3eaaf0a2881ba42393a
1 #!/usr/bin/perl
2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 # $Id$
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # A copy of the GNU General Public License is available on the World Wide Web
16 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
17 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19 ############################################################################
21 use Cwd 'abs_path';
22 use Getopt::Std;
24 # find program directory
25 $_ = $0;
26 while(-l) {
27 my $l = readlink or die "readlink $_: $!\n";
28 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
30 m|(.*)/|;
31 my $progdir = abs_path($1);
33 require "$progdir/soepkiptng.lib";
35 getopts('c:');
37 read_configfile(\%conf, $opt_c);
39 $ENV{PATH} = "$progdir/bin:$ENV{PATH}";
40 use lib "$progdir/lib";
42 sub add_shout($$) {
43 my ($url, $desc) = @_;
45 my $arid = get_id($dbh, "artist", '') or die;
46 my $alid = get_id($dbh, "album", '') or die;
47 $dbh->do("REPLACE INTO song SET title=?, filename=?, album_id=?, " .
48 "artist_id=?, present=1, encoding=\"Shoutcast\", track=0, " .
49 "length=0, time_added=NULL", undef,
50 $desc, $url, $alid, $arid) or die;
52 warn "Added $url: $desc\n";
53 if($have_stream{$url}) { $num_updated++; }
54 else { $num_added++; }
58 use DBI;
60 $dbh = DBI->connect("DBI:$conf{'db_type'}:$conf{'db_name'}:$conf{'db_host'}", $conf{'db_user'}, $conf{'db_pass'})
61 or die "can't connect to database";
63 my $shc = $dbh->selectcol_arrayref("SELECT filename FROM song WHERE filename LIKE \"http:%\"");
64 foreach(@$shc) {
65 $have_stream{$_} = 1;
66 # warn "have $_\n";
69 foreach(@ARGV) {
70 open F, $_ or do {
71 warn "$_: $!\n";
72 next;
74 my (@url, @title);
75 while(<F>) {
76 if(/^File(\d+)\s*=\s*(http:\S+)/) {
77 $url[$1] = $2;
78 next;
80 if(/^Title(\d+)\s*=\s*(.*\S+)/) {
81 $title[$1] = $2;
82 next;
84 if(/^(http:\S+)/) {
85 add_shout($1, $1);
86 next;
89 close F;
91 for($i = 0; $i < @url; $i++) {
92 add_shout($url[$i], $title[$i] || $url[$i])
93 if $url[$i];
97 $dbh->disconnect();
99 printf <<EOF, $num_added, $num_updated;
100 %4d Shoutcast streams added.
101 %4d Shoutcast streams updated.