[Slim-Checkins] r11120 - in /trunk/server: ./ HTML/EN/ SQL/mysql/ Slim/ Slim/Music/ Slim/Schema/ Slim/Utils/ Slim/Web/ Slim/Web/Pages/

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Fri Jan 5 16:20:19 PST 2007


Author: adrian
Date: Fri Jan  5 16:20:19 2007
New Revision: 11120

URL: http://svn.slimdevices.com?rev=11120&view=rev
Log:
Bug: N/A
Description: scanning progress information

- new Slim::Utils::Progress which stores progress in the db as well as
  offering a progress bar
- new database table (memory only) to store importer progress
- initial web display of scanning progress (to be updated)

Added:
    trunk/server/HTML/EN/progress.html   (with props)
    trunk/server/SQL/mysql/schema_5_down.sql   (with props)
    trunk/server/SQL/mysql/schema_5_up.sql   (with props)
    trunk/server/Slim/Schema/Progress.pm   (with props)
    trunk/server/Slim/Utils/Progress.pm   (with props)
    trunk/server/Slim/Web/Pages/Progress.pm   (with props)
Modified:
    trunk/server/HTML/EN/home.html
    trunk/server/Slim/Music/Artwork.pm
    trunk/server/Slim/Music/Import.pm
    trunk/server/Slim/Music/MusicFolderScan.pm
    trunk/server/Slim/Music/PlaylistFolderScan.pm
    trunk/server/Slim/Schema.pm
    trunk/server/Slim/Utils/Scanner.pm
    trunk/server/Slim/Web/Pages.pm
    trunk/server/scanner.pl
    trunk/server/strings.txt

Modified: trunk/server/HTML/EN/home.html
URL: http://svn.slimdevices.com/trunk/server/HTML/EN/home.html?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/HTML/EN/home.html (original)
+++ trunk/server/HTML/EN/home.html Fri Jan  5 16:20:19 2007
@@ -8,7 +8,13 @@
 [% pageHeaderMenu = BLOCK %]
 
 	<div class="statusarea">
-		[% IF warn %]<p><b>[% "NOTE" | string %]</b> [% "HOME_SCAN_WARNING" | string %] [% END %]
+		[% IF warn %]
+			<b>[% "NOTE" | string %]</b> [% "HOME_SCAN_WARNING" | string %]
+			[% IF progress.name %]
+				<p>[% progress.name _ "_PROGRESS" | string %] 
+				<a href="[% webroot %]progress.html?type=importer">[% progress.bar %]</a>
+			[% END %]
+		[% END %]
 
 		[% IF song_count %]
 			[% "LIBRARY_CONTAINS" | string %] [% album_count %] [% "WITH" | string %] 

Added: trunk/server/HTML/EN/progress.html
URL: http://svn.slimdevices.com/trunk/server/HTML/EN/progress.html?rev=11120&view=auto
==============================================================================
--- trunk/server/HTML/EN/progress.html (added)
+++ trunk/server/HTML/EN/progress.html Fri Jan  5 16:20:19 2007
@@ -1,0 +1,35 @@
+[% pagetitle = "STATISTICS" | string %]
+[% pageHeaderMenu = pagetitle %]
+
+[% PROCESS pageheader.html %]
+
+[% IF refresh %]<script language="JavaScript">
+
+function doLoad() {
+	setTimeout( "refresh()", [% refresh %] * 1000);
+}
+
+function refresh() {
+	window.location.replace("[% webroot	%]progress.html?type=[% type %]&player=[% player | uri %]");
+}
+
+</script>[% END %]
+
+<body [% IF refresh %]onload="doLoad()"[% END %]>
+
+    <h4>[% type _ "_PROGRESS" | string %]</h4>
+
+	<p>[% type _ "_PROGRESS_DESC" | string %]</p>
+
+	[% FOREACH item = progress_items %]
+		<p>
+		[% item.obj.name _ "_PROGRESS" | string %] ( [% item.obj.done %] [% "OF" | string %] [% item.obj.total %] ) 
+		[% IF item.obj.active %] [% "RUNNING" | string %][% ELSE %] [% "COMPLETE" | string %][% END %]
+		[% item.time %] [% "SECONDS" | string %] [% item.bar %]
+		[% IF item.obj.info %]<p>[% item.obj.info %]</p>[% END %]
+		</p>	
+	[% END %]
+
+	<p>[% IF message %][% message %][% END %]</p>
+
+[% PROCESS pagefooter.html %]

Propchange: trunk/server/HTML/EN/progress.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/HTML/EN/progress.html
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/HTML/EN/progress.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: trunk/server/SQL/mysql/schema_5_down.sql
URL: http://svn.slimdevices.com/trunk/server/SQL/mysql/schema_5_down.sql?rev=11120&view=auto
==============================================================================
--- trunk/server/SQL/mysql/schema_5_down.sql (added)
+++ trunk/server/SQL/mysql/schema_5_down.sql Fri Jan  5 16:20:19 2007
@@ -1,0 +1,1 @@
+DROP TABLE IF EXISTS progress;

Propchange: trunk/server/SQL/mysql/schema_5_down.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/SQL/mysql/schema_5_down.sql
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/SQL/mysql/schema_5_down.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/server/SQL/mysql/schema_5_up.sql
URL: http://svn.slimdevices.com/trunk/server/SQL/mysql/schema_5_up.sql?rev=11120&view=auto
==============================================================================
--- trunk/server/SQL/mysql/schema_5_up.sql (added)
+++ trunk/server/SQL/mysql/schema_5_up.sql Fri Jan  5 16:20:19 2007
@@ -1,0 +1,15 @@
+-- table to store progress information, e.g. scanning progress by importer
+
+DROP TABLE IF EXISTS progress;
+CREATE TABLE progress (
+  id int(10) unsigned NOT NULL auto_increment,
+  type varchar(255),
+  name varchar(255),
+  active bool,
+  total int(10) unsigned,
+  done int(10) unsigned,
+  start int(10) unsigned,
+  finish int(10) unsigned,
+  info varchar(255),
+  PRIMARY KEY (id)
+) ENGINE=MEMORY;

Propchange: trunk/server/SQL/mysql/schema_5_up.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/SQL/mysql/schema_5_up.sql
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/SQL/mysql/schema_5_up.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/server/Slim/Music/Artwork.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Music/Artwork.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Music/Artwork.pm (original)
+++ trunk/server/Slim/Music/Artwork.pm Fri Jan  5 16:20:19 2007
@@ -76,7 +76,9 @@
 	my $count    = $tracks->count;
 
 	if ($count) {
-		$progress = Slim::Utils::ProgressBar->new({ 'total' => $count });
+		$progress = Slim::Utils::Progress->new({ 
+			'type' => 'importer', 'name' => 'artwork', 'total' => $count, 'bar' => 1
+		});
 	}
 
 	while (my $track = $tracks->next) {
@@ -93,10 +95,10 @@
 			$album->update;
 		}
 
-		$progress->update if $progress;
-	}
-
-	$progress->final($count) if $progress;
+		$progress->update;
+	}
+
+	$progress->final($count) if $count;
 
 	Slim::Music::Import->endImporter('findArtwork');
 }

Modified: trunk/server/Slim/Music/Import.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Music/Import.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Music/Import.pm (original)
+++ trunk/server/Slim/Music/Import.pm Fri Jan  5 16:20:19 2007
@@ -255,6 +255,11 @@
 sub runScan {
 	my $class  = shift;
 
+	# Delete all exiting importer progress entries
+	for my $prog (Slim::Schema->rs('Progress')->search({ 'type' => 'importer' })->all) {
+		$prog->delete;
+	}
+
 	# If we are scanning a music folder, do that first - as we'll gather
 	# the most information from files that way and subsequent importers
 	# need to do less work.

Modified: trunk/server/Slim/Music/MusicFolderScan.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Music/MusicFolderScan.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Music/MusicFolderScan.pm (original)
+++ trunk/server/Slim/Music/MusicFolderScan.pm Fri Jan  5 16:20:19 2007
@@ -77,6 +77,7 @@
 		'url'       => $dir,
 		'recursive' => $recurse,
 		'types'     => 'audio',
+		'scanName'  => 'directory',
 	});
 
 	$log->info("Finished background scan of music folder.");

Modified: trunk/server/Slim/Music/PlaylistFolderScan.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Music/PlaylistFolderScan.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Music/PlaylistFolderScan.pm (original)
+++ trunk/server/Slim/Music/PlaylistFolderScan.pm Fri Jan  5 16:20:19 2007
@@ -83,6 +83,7 @@
 		'url'       => $dir,
 		'recursive' => $recurse,
 		'types'     => 'list',
+		'scanName'  => 'playlist',
 	});
 
 	$class->doneScanning;

Modified: trunk/server/Slim/Schema.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Schema.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Schema.pm (original)
+++ trunk/server/Slim/Schema.pm Fri Jan  5 16:20:19 2007
@@ -47,6 +47,7 @@
 use Slim::Utils::Strings qw(string);
 use Slim::Utils::Text;
 use Slim::Utils::Unicode;
+use Slim::Utils::Progress;
 
 my $log = logger('database.info');
 
@@ -168,8 +169,9 @@
 		Playlist
 		PlaylistTrack
 		Rescan
-		Track 
-		Year 
+		Track
+		Year
+		Progress
 	/);
 
 	# Build all our class accessors and populate them.
@@ -1005,7 +1007,10 @@
 
 	my $iterator = $self->search('Track', { 'audio' => 1 });
 	my $count    = $iterator->count;
-	my $progress = Slim::Utils::ProgressBar->new({ 'total' => $count });
+
+	my $progress = Slim::Utils::Progress->new({
+		'type' => 'importer', 'name' => 'cleanup', 'total' => $count, 'bar' => 1
+	});
 
 	# fetch one at a time to keep memory usage in check.
 	while (my $track = $iterator->next) {
@@ -1016,10 +1021,10 @@
 			$track = undef;
 		}
 
-		$progress->update if $progress;
-	}
-
-	$progress->final($count) if $progress;
+		$progress->update;
+	}
+
+	$progress->final($count);
 
 	logger('scan.import')->info("Finished with stale track cleanup.");
 
@@ -1163,7 +1168,9 @@
 	my $count    = $cursor->count;
 
 	if ($count) {
-		$progress = Slim::Utils::ProgressBar->new({ 'total' => $count });
+		$progress = Slim::Utils::Progress->new({
+			'type' => 'importer', 'name' => 'mergeva', 'total' => $count, 'bar' => 1
+		});
 	}
 
 	# fetch one at a time to keep memory usage in check.
@@ -1223,7 +1230,7 @@
 			$albumObj->update;
 		}
 
-		$progress->update if $progress;
+		$progress->update;
 	}
 
 	$progress->final($count) if $progress;

Added: trunk/server/Slim/Schema/Progress.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Schema/Progress.pm?rev=11120&view=auto
==============================================================================
--- trunk/server/Slim/Schema/Progress.pm (added)
+++ trunk/server/Slim/Schema/Progress.pm Fri Jan  5 16:20:19 2007
@@ -1,0 +1,19 @@
+package Slim::Schema::Progress;
+
+# $Id$
+
+use strict;
+use base 'Slim::Schema::DBI';
+
+{
+	my $class = __PACKAGE__;
+
+	$class->table('progress');
+
+	$class->add_columns(qw/id type name active total done start finish info/);
+	$class->set_primary_key('id');
+}
+
+1;
+
+__END__

Propchange: trunk/server/Slim/Schema/Progress.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/Slim/Schema/Progress.pm
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/Slim/Schema/Progress.pm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/server/Slim/Utils/Progress.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Progress.pm?rev=11120&view=auto
==============================================================================
--- trunk/server/Slim/Utils/Progress.pm (added)
+++ trunk/server/Slim/Utils/Progress.pm Fri Jan  5 16:20:19 2007
@@ -1,0 +1,317 @@
+package Slim::Utils::Progress;
+
+use strict;
+
+use Slim::Schema;
+
+use constant UPDATE_DB_INTERVAL  => 1;
+use constant UPDATE_BAR_INTERVAL => 0.3;
+
+sub new {
+	my $class = shift;
+	my $args  = shift;
+
+	my $done;
+	my $obj;
+	my $now = Time::HiRes::time();
+
+	$obj = Slim::Schema->rs('Progress')->find_or_create({
+		'type' => $args->{'type'}  || 'NOTYPE',
+		'name' => $args->{'name'}  || 'NONAME',
+	});
+
+	if (defined $args->{'total'}) {
+
+		$obj->total($args->{'total'});
+		$obj->done(0);
+		$obj->start ( time() );
+		$obj->active(1);
+
+		$obj->update;
+
+		$done = 0;
+	}
+
+	my $ref = {
+		'total' => $args->{'total'},
+		'done'  => $done,
+		'obj'   => $obj,
+		'dbup'  => 0,
+		'dball' => $args->{'every'},
+	};
+
+	bless $ref, $class;
+
+	if ($args->{'bar'} && $::progress) {
+
+		$ref->{'bar'} = 1;
+		$ref->{'barup'} = 0;
+		$ref->{'start_time'} = $now,
+		$ref->{'fh'} = \*STDOUT,
+		$ref->{'term'} = $args->{'term'} || -t $ref->{'fh'};
+
+		$ref->_initBar,
+	}
+
+	return $ref;
+}
+
+sub update {
+	my $class = shift;
+	my $info  = shift;
+	my $latest= shift;
+
+	my $done;
+
+	if (defined $latest) {
+
+		$done = $class->{'done'} = $latest;
+
+	} else {
+
+		$done = ++$class->{'done'};
+
+	}
+
+	my $now = Time::HiRes::time();
+
+	if ($class->{'dball'} || $now > $class->{'dbup'} + UPDATE_DB_INTERVAL) {
+
+		$class->{'dbup'} = $now;
+
+		my $obj = $class->{'obj'} || return;
+
+		$obj->done($done);
+		$obj->info($info) if $info;
+
+		$obj->update();
+	}
+
+	if ($class->{'bar'} && $now > $class->{'barup'} + UPDATE_BAR_INTERVAL) {
+
+		$class->{'barup'} = $now;
+
+		$class->_updateBar( $done );
+
+	}
+}
+
+sub final {
+	my $class = shift;
+
+	my $obj = $class->{'obj'} || return;
+
+	$obj->done( $class->{'total'} );
+	$obj->finish( time() );
+	$obj->active(0);
+	$obj->info( undef );
+
+	$obj->update;
+
+	if ($class->{'bar'}) {
+
+		$class->_finalBar( $class->{'total'} );
+	}
+}
+
+# The following code is adapted from Mail::SpamAssassin::Util::Progress which ships
+# with the following license:
+#
+# Copyright 2004 Apache Software Foundation
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use constant HAS_TERM_READKEY => eval { require Term::ReadKey };
+
+sub _initBar {
+	my $self = shift;
+
+	my $fh = $self->{'fh'};
+
+	# 0 for now, maybe allow this to be passed in
+	$self->{'prev_num_done'} = 0;
+
+	# 0 for now, maybe allow this to be passed in
+	$self->{'num_done'} = 0;
+
+	$self->{'avg_msgs_per_sec'} = undef;
+
+	$self->{'prev_time'}  = $self->{'start_time'};
+
+	return unless $self->{'term'};
+
+	my $term_size = undef;
+
+	# If they have set the COLUMNS environment variable, respect it and move on
+	if ($ENV{'COLUMNS'}) {
+		$term_size = $ENV{'COLUMNS'};
+	}
+
+	# The ideal case would be if they happen to have Term::ReadKey installed
+	if (!defined($term_size) && HAS_TERM_READKEY) {
+
+		my $term_readkey_term_size = eval { (Term::ReadKey::GetTerminalSize($self->{fh}))[0] };
+
+		# an error will just keep the default
+		if (!$@) {
+			# GetTerminalSize might have returned an empty array, so check the
+			# value and set if it exists, if not we keep the default
+			$term_size = $term_readkey_term_size if $term_readkey_term_size;
+		}
+	}
+
+	# only viable on Unix based OS, so exclude windows, etc here
+	if (!defined $term_size && $^O !~ /^(mswin|dos|os2)/oi) {
+
+		my $data = `stty -a`;
+		if ($data =~ /columns (\d+)/) {
+			$term_size = $1;
+		}
+
+		if (!defined $term_size) {
+			my $data = `tput cols`;
+			if ($data =~ /^(\d+)/) {
+				$term_size = $1;
+			}
+		}
+	}
+
+	# fall back on the default
+	if (!defined $term_size) {
+		$term_size = 80;
+	}
+
+	# Adjust the bar size based on what all is going to print around it,
+	# do not forget the trailing space. Here is what we have to deal with
+	#123456789012345678901234567890123456789
+	# XXX% [] XXX.XX tracks/sec XXmXXs LEFT
+	# XXX% [] XXX.XX tracks/sec XXmXXs DONE
+	$self->{'bar_size'} = $term_size - 39;
+
+	my @chars = (' ') x $self->{'bar_size'};
+
+	print $fh sprintf("\r%3d%% [%s] %6.2f tracks/sec %sm%ss LEFT",
+		    0, join('', @chars), 0, '--', '--');
+}
+
+sub _updateBar {
+	my ($self, $num_done) = @_;
+
+	my $fh       = $self->{'fh'};
+	my $time_now = Time::HiRes::time();
+
+	# If nothing is passed in to update assume we are adding one to the prev_num_done value
+	if (!defined $num_done) {
+		$num_done = $self->{'prev_num_done'} + 1;
+	}
+
+	my $msgs_since = $num_done - $self->{'prev_num_done'};
+	my $time_since = $time_now - $self->{'prev_time'};
+
+	# Avoid a divide by 0 error.
+	if ($time_since == 0) {
+		$time_since = 1;
+	}
+
+	if ($self->{'term'}) {
+
+		my $percentage = $num_done != 0 ? int(($num_done / $self->{'total'}) * 100) : 0;
+
+		my @chars    = (' ') x $self->{'bar_size'};
+		my $used_bar = $num_done * ($self->{'bar_size'} / $self->{'total'});
+
+		for (0..$used_bar-1) {
+			$chars[$_] = '=';
+		}
+
+		my $rate         = $msgs_since/$time_since;
+		my $overall_rate = $num_done/($time_now-$self->{'start_time'});
+
+		# semi-complicated calculation here so that we get the avg msg per sec over time
+		if (defined $self->{'avg_msgs_per_sec'}) {
+
+			$self->{'avg_msgs_per_sec'} = 0.5 * $self->{'avg_msgs_per_sec'} + 0.5 * ($msgs_since / $time_since);
+
+		} else {
+
+			$self->{'avg_msgs_per_sec'} = $msgs_since / $time_since;
+		}
+
+		# using the overall_rate here seems to provide much smoother eta numbers
+		my $eta = ($self->{'total'} - $num_done)/$overall_rate;
+
+		# we make the assumption that we will never run > 1 hour, maybe this is bad
+		my $min = int($eta/60) % 60;
+		my $sec = int($eta % 60);
+
+		print $fh sprintf("\r%3d%% [%s] %6.2f tracks/sec %02dm%02ds LEFT",
+				$percentage, join('', @chars), $self->{'avg_msgs_per_sec'}, $min, $sec);
+
+	} else {
+
+		# we have no term, so fake it
+		print $fh '.' x $msgs_since;
+	}
+
+	$self->{'prev_time'}     = $time_now;
+	$self->{'prev_num_done'} = $num_done;
+	$self->{'num_done'}      = $num_done;
+}
+
+sub _finalBar {
+	my ($self, $num_done) = @_;
+
+	# passing in $num_done is optional, and will most likely rarely be used,
+	# we should generally favor the data that has been passed in to update()
+	if (!defined $num_done) {
+		$num_done = $self->{'num_done'};
+	}
+
+	my $fh = $self->{'fh'};
+
+	my $time_taken = Time::HiRes::time() - $self->{'start_time'};
+
+	# can't have 0 time, so just make it 1 second
+	   $time_taken ||= 1;
+
+	# in theory this should be 100% and the bar would be completely full, however
+	# there is a chance that we had an early exit so we aren't at 100%
+	my $percentage = $num_done != 0 ? int(($num_done / $self->{'total'}) * 100) : 0;
+
+	my $msgs_per_sec = $num_done / $time_taken;
+
+	my $min = int($time_taken/60) % 60;
+	my $sec = $time_taken % 60;
+
+	if ($self->{'term'}) {
+
+		my @chars    = (' ') x $self->{'bar_size'};
+		my $used_bar = $num_done * ($self->{'bar_size'} / $self->{'total'});
+
+		for (0..$used_bar-1) {
+			$chars[$_] = '=';
+		}
+
+		print $fh sprintf("\r%3d%% [%s] %6.2f tracks/sec %02dm%02ds DONE\n",
+		      $percentage, join('', @chars), $msgs_per_sec, $min, $sec);
+
+	} else {
+
+		print $fh sprintf("\n%3d%% Completed %6.2f tracks/sec in %02dm%02ds\n",
+		      $percentage, $msgs_per_sec, $min, $sec);
+	}
+}
+
+1;
+
+__END__

Propchange: trunk/server/Slim/Utils/Progress.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/Slim/Utils/Progress.pm
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/Slim/Utils/Progress.pm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/server/Slim/Utils/Scanner.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Utils/Scanner.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Utils/Scanner.pm (original)
+++ trunk/server/Slim/Utils/Scanner.pm Fri Jan  5 16:20:19 2007
@@ -46,7 +46,7 @@
 use Slim::Utils::Cache;
 use Slim::Utils::Log;
 use Slim::Utils::Misc;
-use Slim::Utils::ProgressBar;
+use Slim::Utils::Progress;
 use Slim::Utils::Strings;
 
 my $log = logger('scan.scanner');
@@ -303,13 +303,20 @@
 		$log->info(sprintf("Found %d files in %s\n", scalar @{$files}, $topDir));
 	}
 
-	# Give the user a progress indicator if available.
-	my $progress = Slim::Utils::ProgressBar->new({ 'total' => scalar @{$files} });
+	# Send progress info to the db and progress bar
+	my $progress = Slim::Utils::Progress->new({
+		'type' => 'importer',
+		'name' => $args->{'scanName'} || 'directory',
+		'total'=> scalar @{$files}, 'bar' => 1,
+		'every'=> ($args->{'scanName'} && $args->{'scanName'} eq 'playlist'), # record all playists in the db
+	});
 
 	# If we're starting with a clean db - don't bother with searching for a track
 	my $method   = $::wipe ? 'newTrack' : 'updateOrCreate';
 
 	for my $file (@{$files}) {
+
+		$progress->update($file);
 
 		my $url = Slim::Utils::Misc::fileURLFromPath($file);
 
@@ -351,10 +358,9 @@
 			}
 		}
 
-		$progress->update if $progress;
-	}
-
-	$progress->final if $progress;
+	}
+
+	$progress->final;
 
 	return $foundItems;
 }

Modified: trunk/server/Slim/Web/Pages.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Web/Pages.pm?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/Slim/Web/Pages.pm (original)
+++ trunk/server/Slim/Web/Pages.pm Fri Jan  5 16:20:19 2007
@@ -26,6 +26,8 @@
 use Slim::Web::Pages::Playlist;
 use Slim::Web::Pages::History;
 use Slim::Web::Pages::EditPlaylist;
+use Slim::Web::Pages::Progress;
+use Slim::Utils::Progress;
 
 our %additionalLinks = ();
 
@@ -66,6 +68,7 @@
 	Slim::Web::Pages::EditPlaylist::init(); # must precede Playlist::init();
 	Slim::Web::Pages::Playlist::init();
 	Slim::Web::Pages::History::init();
+	Slim::Web::Pages::Progress::init();
 }
 
 sub _lcPlural {
@@ -117,7 +120,25 @@
 	my ($class, $params, $rs, $previousLevel) = @_;
 
 	if (Slim::Music::Import->stillScanning) {
+
 		$params->{'warn'} = 1;
+
+		if (my $p = Slim::Schema->rs('Progress')->search({ 'type' => 'importer', 'active' => 1 })->first) {
+
+			my $bar = '';
+
+			for (my $i = 0; $i < $p->total; $i += $p->total / 40) {
+
+				$params->{'cell_full'} = $i < $p->done;
+				$bar .= ${Slim::Web::HTTP::filltemplatefile("hitlist_bar.html", $params)};
+			}
+
+			$params->{'progress'} = {
+				'name' => $p->name,
+				'bar'  => $bar,
+			}
+		}
+
 		return;
 	}
 

Added: trunk/server/Slim/Web/Pages/Progress.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Web/Pages/Progress.pm?rev=11120&view=auto
==============================================================================
--- trunk/server/Slim/Web/Pages/Progress.pm (added)
+++ trunk/server/Slim/Web/Pages/Progress.pm Fri Jan  5 16:20:19 2007
@@ -1,0 +1,53 @@
+package Slim::Web::Pages::Progress;
+
+use strict;
+
+use Slim::Schema;
+
+sub init {
+	Slim::Web::HTTP::addPageFunction(qr/^progress\.(?:htm|xml)/,\&progress);
+}
+
+sub progress {
+	my ($client, $params) = @_;
+
+	my $args = {};
+
+	$args->{'type'} = $params->{'type'} if $params->{'type'};
+	$args->{'name'} = $params->{'name'} if $params->{'name'};
+	$args->{'active'} = $params->{'active'} if $params->{'active'};
+
+	my @progress = Slim::Schema->rs('Progress')->search( $args )->all;
+
+	for my $p (@progress) {
+
+		my $bar = '';
+
+		for (my $i = 0; $i < $p->total; $i += $p->total / 25) {
+
+			$params->{'cell_full'} = $i < $p->done;
+			$bar .= ${Slim::Web::HTTP::filltemplatefile("hitlist_bar.html", $params)};
+		}
+
+		my $item = {
+			'obj'  => $p,
+			'bar'  => $bar,
+			'time' => ($p->finish || time()) - $p->start,
+		};
+
+		push @{$params->{'progress_items'}}, $item;
+	}
+
+	$params->{'refresh'} = 5;
+
+	# special message for importers once finished
+	if ($params->{'type'} && $params->{'type'} eq 'importer' && !Slim::Music::Import->stillScanning) {
+
+		$params->{'message'} = Slim::Utils::Strings::string('PROGRESS_IMPORTER_COMPLETE_DESC');
+
+	}
+
+	return Slim::Web::HTTP::filltemplatefile("progress.html", $params);
+}
+
+1;

Propchange: trunk/server/Slim/Web/Pages/Progress.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/server/Slim/Web/Pages/Progress.pm
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: trunk/server/Slim/Web/Pages/Progress.pm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/server/scanner.pl
URL: http://svn.slimdevices.com/trunk/server/scanner.pl?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/scanner.pl (original)
+++ trunk/server/scanner.pl Fri Jan  5 16:20:19 2007
@@ -85,6 +85,8 @@
 	# Redirect STDERR to the log file.
 	tie *STDERR, 'Slim::Utils::Log::Trapper';
 
+	STDOUT->autoflush(1);
+
 	my $log = logger('server');
 
 	# Bring up strings, database, etc.

Modified: trunk/server/strings.txt
URL: http://svn.slimdevices.com/trunk/server/strings.txt?rev=11120&r1=11119&r2=11120&view=diff
==============================================================================
--- trunk/server/strings.txt (original)
+++ trunk/server/strings.txt Fri Jan  5 16:20:19 2007
@@ -12313,3 +12313,33 @@
 	DE	Grösser
 	EN	Enlarge
 	SV	Förstora
+
+DIRECTORY_PROGRESS
+	EN	Directory Scan
+
+PLAYLIST_PROGRESS
+	EN	Playlist Scan
+
+MERGEVA_PROGRESS
+	EN	Merge Various Artists
+
+ARTWORK_PROGRESS
+	EN	Artwork Scan
+
+CLEANUP_PROGRESS
+	EN	Database Cleanup
+
+IMPORTER_PROGRESS
+	EN	Scanning Progress
+
+IMPORTER_PROGRESS_DESC
+	EN	This page shows the progress of each phase of the scanning process.
+
+RUNNING
+	EN	Running
+
+COMPLETE
+	EN	Complete
+
+PROGRESS_IMPORTER_COMPLETE_DESC
+	EN	Slimserver has finished scanning your music collection.



More information about the checkins mailing list