summaryrefslogtreecommitdiff
path: root/rhimport.pm
diff options
context:
space:
mode:
Diffstat (limited to 'rhimport.pm')
-rw-r--r--rhimport.pm41
1 files changed, 34 insertions, 7 deletions
diff --git a/rhimport.pm b/rhimport.pm
index 4db154c..2541660 100644
--- a/rhimport.pm
+++ b/rhimport.pm
@@ -128,27 +128,54 @@ sub clear_carts
sub import_playlist
{
- my ($playlist, $dropbox) = @_;
-
- print "Starting import from playlist $playlist to $dropbox\n";
+ my ($playlist, $dropbox, $progress_cb) = @_;
+ print "Starting import from playlist $playlist to $dropbox";
+ my @entries;
open (FILE, $playlist) or die "can't open playlist $playlist: $!";
while (my $entry = <FILE>) {
next if($entry =~ /^#/);
next if($entry =~ /^\s/);
$entry =~ s/\n$//;
- import_file($entry, $dropbox);
+ push @entries, $entry;
}
close(FILE);
+ my $num_entries = scalar(@entries);
+ print " ($num_entries Files in list)\n";
+
+ my $cnt = 0;
+ my $ret = 0;
+ for my $entry ( @entries ) {
+ if($progress_cb) {
+ $progress_cb->($cnt, $num_entries, $entry);
+ }
- return 0;
+ $ret = import_file($entry, $dropbox);
+ last if($ret != 0);
+
+ $cnt++;
+ }
+
+ if($progress_cb) {
+ $progress_cb->($num_entries, $num_entries, "Import abgeschlossen!");
+ }
+
+ return $ret;
}
sub import_single
{
- my ($file, $dropbox) = @_;
+ my ($file, $dropbox, $progress_cb) = @_;
print "Starting import from file $file to $dropbox\n";
- import_file($file, $dropbox);
+ if($progress_cb) {
+ $progress_cb->(0, 1, $file);
+ }
+ my $ret = import_file($file, $dropbox, $progress_cb);
+
+ if($progress_cb) {
+ $progress_cb->(1, 1, "Import abgeschlossen!");
+ }
+ return $ret;
}
sub import_file