summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm104
1 files changed, 26 insertions, 78 deletions
diff --git a/rhimport.pm b/rhimport.pm
index 66e37f7..8109f7e 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -35,6 +35,8 @@ use DateTime;
use DateTime::TimeZone;
use LWP::Simple;
use XML::Feed;
+use DBI;
+use Config::IniFiles;
my $ssh_host = "airplay";
my $ssh_user = "rhimport";
@@ -89,12 +91,30 @@ sub fetch_parse_rss
return XML::Feed->parse(\$xml);
}
-sub check_key_file
+sub opendb
{
- if(-e "$ssh_key_file") {
- return 1;
- }
- return 0;
+ my $RD_CONF = "/etc/rd.conf";
+ my $cfg = Config::IniFiles->new(-file => $RD_CONF)
+ or return (undef, "Config File Error: " . join("\n", @Config::IniFiles::errors));
+
+ my $dbhost = $cfg->val('mySQL', 'Hostname');
+ my $dbname = $cfg->val('mySQL', 'Database');
+ my $dbuser = $cfg->val('mySQL', 'Loginname');
+ my $dbpasswd = $cfg->val('mySQL', 'Password');
+
+ my $dbh = DBI->connect("DBI:mysql:$dbname:$dbhost","$dbuser","$dbpasswd")
+ or return (undef, "Database Error: " . $DBI::errstr);
+
+ $dbh->do(qq{SET CHARACTER SET utf8;})
+ or return (undef, "Database Error: " . $dbh->errstr);
+
+ return ($dbh);
+}
+
+sub closedb
+{
+ my $dbh = shift;
+ $dbh->disconnect();
}
sub get_dropboxes
@@ -218,78 +238,6 @@ sub clear_carts
return $log;
}
-sub check_file_extension
-{
- my ($file) = @_;
-
- my $ext = uc((fileparse($file, qr/\.[^.]*/))[2]);
- foreach (".MP3", ".OGG", ".FLAC", ".WAV") {
- if($ext eq $_) {
- return 1;
- }
- }
- return 0;
-}
-
-sub import_playlist
-{
- my ($playlist, $dropbox, $user, $num_carts, $progress_cb, $error_cb) = @_;
-
- print "Starting import from playlist $playlist to $dropbox";
- my @entries;
- open (FILE, $playlist) or die "can't open playlist $playlist: $!";
- binmode(FILE, ":utf8");
- while (my $entry = <FILE>) {
- next if($entry =~ /^#/);
- next if($entry =~ /^\s/);
- $entry =~ s/\n$//;
- $entry =~ s/^file:\/\///;
- $entry = uri_unescape($entry);
- next if(-d $entry);
- next if(!-r $entry);
- push @entries, $entry;
- }
- close(FILE);
- my $num_entries = scalar(@entries);
- print " ($num_entries Files in list -> $num_carts available)\n";
-
- if($num_carts < $num_entries) {
- if($error_cb) {
- my $ret = $error_cb->("Achtung!\nDie Playlist beinhaltet mehr als $num_carts Dateien. Es werden nur die ersten $num_carts Dateien importiert.");
- if(!$ret) {
- return 0, "too many files in playlist";
- }
-
- $#entries = $num_carts-1;
- $num_entries = scalar(@entries);
- }
- }
- print "will import $num_entries files\n";
-
- my $cnt = 0;
- my $ret = 0;
- my $log = "";
- prepare_import($user);
- for my $entry ( @entries ) {
- $progress_cb->($cnt, $num_entries, $entry) if($progress_cb);
-
- my $out;
- ($ret, $out) = import_file($entry, $dropbox, $user, $error_cb);
- $log .= "\n--- $entry ---\n$out\n" if $out;
- last if($ret == 0);
-
- $cnt++;
- }
-
- if($ret) {
- $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!") if($progress_cb);
- } else {
- $progress_cb->($cnt, $num_entries, "Import abgebrochen!") if($progress_cb);
- }
-
- return ($ret, $log);
-}
-
sub import_single
{
my ($file, $dropbox, $user, $progress_cb, $error_cb) = @_;
@@ -409,7 +357,7 @@ sub delete_file
sub pv_add_note
{
my ( $title, $text, $id, $date, $type, $index ) = @_;
- my @script = ('/usr/bin/ssh', 'root@web', 'addnote', $id, $date, $type);
+ my @script = ('/usr/bin/ssh', 'pv@rdimport', 'addnote', $id, $date, $type);
push(@script , $index) unless (!defined $index);
my ($reader, $writer, $error ) = ( new IO::Handle, new IO::Handle, new IO::Handle );