+my $add_start;
+
+sub load_tracks($$) {
+ my ($seq, $dst) = @_;
+ my ($newlen, $count);
+
+ my $start = $add_start // $seq;
+ my $add_position = $pl_current_length;
+ my $end = $seq+1;
+
+ $dst //= $start;
+
+ MPD::exec("load", $ARGV[0], "$start:$end");
+ MPD::exec("status");
+ MPD::exec("command_list_end");
+
+ while (<$sock>) {
+ last if (/^OK/);
+ die($_) if (/^ACK/);
+
+ if (/^(\w+): (.*)$/) {
+ if ($1 eq "playlistlength") {
+ $newlen = int($2);
+ }
+ }
+ }
+
+ $count = $newlen - $pl_current_length;
+
+ MPD::exec("command_list_begin");
+ if ($newlen > $pl_current_length) {
+ MPD::exec("move", "$add_position:$newlen", $dst)
+ if ($add_position != $dst);
+ }
+
+ $pl_current_length = $newlen;
+ undef $add_start;
+
+ return $count;
+}
+