[Slim-Checkins] r10100 - in /branches/6.5/server: Changelog6.html Plugins/RandomPlay/Plugin.pm

dsully at svn.slimdevices.com dsully at svn.slimdevices.com
Fri Sep 29 10:14:11 PDT 2006


Author: dsully
Date: Fri Sep 29 10:14:10 2006
New Revision: 10100

URL: http://svn.slimdevices.com?rev=10100&view=rev
Log:
Bug: 4201
Description: Merge from trunk -r 10097:10099

Modified:
    branches/6.5/server/Changelog6.html
    branches/6.5/server/Plugins/RandomPlay/Plugin.pm

Modified: branches/6.5/server/Changelog6.html
URL: http://svn.slimdevices.com/branches/6.5/server/Changelog6.html?rev=10100&r1=10099&r2=10100&view=diff
==============================================================================
--- branches/6.5/server/Changelog6.html (original)
+++ branches/6.5/server/Changelog6.html Fri Sep 29 10:14:10 2006
@@ -23,8 +23,9 @@
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4190">#4190</a> - xmlbrower transition problem</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4191">#4191</a> - Live365 Search has missing strings</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4192">#4192</a> - IE doesn't refresh status</li>
+		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4201">#4201</a> - Deselecting all genres in Random Mix creates invalid SQL query, stops SS</li>
+		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4205">#4205</a> - sleep function with SlimServer 6.5.0 in Fishbone skin, songs longer than 90 minutes</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4213">#4213</a> - Slimserver can crash due to display being deleted from client object at forget time</li>
-		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4205">#4205</a> - sleep function with SlimServer 6.5.0 in Fishbone skin, songs longer than 90 minutes</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4221">#4221</a> - 6.5 crashes on artist breadcrumb</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4228">#4228</a> - Fishbone skin status doesn't update from an empty playlist</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4237">#4237</a> - in Help > Internet Radio there is a dead link to Settings</li>

Modified: branches/6.5/server/Plugins/RandomPlay/Plugin.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Plugins/RandomPlay/Plugin.pm?rev=10100&r1=10099&r2=10100&view=diff
==============================================================================
--- branches/6.5/server/Plugins/RandomPlay/Plugin.pm (original)
+++ branches/6.5/server/Plugins/RandomPlay/Plugin.pm Fri Sep 29 10:14:10 2006
@@ -42,32 +42,58 @@
 sub findAndAdd {
 	my ($client, $type, $find, $limit, $addOnly) = @_;
 
-	$::d_plugins && msg("RandomPlay: Starting random selection of $limit items for type: $type\n");
+	$::d_plugins && msgf("RandomPlay: Starting random selection of %s items for type: $type\n", defined($limit) ? $limit : 'unlimited');
 
 	my @joins  = ();
 
 	# Pull in the right tables to do our searches
 	if ($type eq 'track' || $type eq 'year') {
 
-		push @joins, 'genreTracks';
+		if ($find->{'genreTracks.genre'}) {
+
+			push @joins, 'genreTracks';
+		}
 
 	} elsif ($type eq 'album') {
 
-		push @joins, { 'tracks' => 'genreTracks' };
+		if ($find->{'genreTracks.genre'}) {
+
+			push @joins, { 'tracks' => 'genreTracks' };
+
+		} else {
+
+			push @joins, 'tracks';
+		}
 
 	} elsif ($type eq 'contributor') {
 
-		push @joins, { 'contributorTracks' => { 'track' => 'genreTracks' } };
+		if ($find->{'genreTracks.genre'}) {
+
+			push @joins, { 'contributorTracks' => { 'track' => 'genreTracks' } };
+
+		} else {
+
+			push @joins, { 'contributorTracks' => 'track' };
+		}
 	}
 
 	# Search the database for the number of track we need. Use MySQL's
 	# RAND() function to get back a random list. Restrict by the genre's we've selected.
-	my @results = Slim::Schema->rs($type)->search($find, {
+	my @results = ();
+	my $rs      = Slim::Schema->rs($type)->search($find, {
 
 		'order_by' => \'RAND()',
 		'join'     => \@joins,
-
-	})->slice(0, ($limit-1));
+	});
+
+	if ($limit) {
+
+		@results = $rs->slice(0, ($limit-1));
+
+	} else {
+
+		@results = $rs->all;
+	}
 
 	$::d_plugins && msgf("RandomPlay: Find returned %i items\n", scalar @results);
 
@@ -165,14 +191,20 @@
 }
 
 sub getRandomYear {
-	my $filteredGenresRef = shift;
-	
+	my $filteredGenres = shift;
+
 	$::d_plugins && msg("RandomPlay: Starting random year selection\n");
 
-	my $year = Slim::Schema->rs('Track')->single(
-		{ 'genreTracks.genre' => $filteredGenresRef },
-		{ 'order_by' => \'RAND()', 'join' => 'genreTracks' }
-	)->year;
+	my %cond = ();
+	my %attr = ( 'order_by' => \'RAND()' );
+
+	if (ref($filteredGenres) eq 'ARRAY' && scalar @$filteredGenres > 0) {
+
+		$cond{'genreTracks.genre'} = $filteredGenres;
+		$attr{'join'}              = 'genreTracks';
+	}
+
+	my $year = Slim::Schema->rs('Track')->search(\%cond, \%attr)->single->year;
 
 	$::d_plugins && msg("RandomPlay: Selected year $year\n");
 
@@ -245,13 +277,16 @@
 
 		Slim::Player::Playlist::shuffle($client, 0);
 
+		my $find = {};
+
 		# Initialize find to only include user's selected genres.  If they've deselected
 		# all genres, this clause will be ignored by find, so all genres will be used.
 		my $filteredGenres = getFilteredGenres($client);
 
-		my $find = {
-			'genreTracks.genre' => { 'in' => $filteredGenres }
-		};
+		if (ref($filteredGenres) eq 'ARRAY' && scalar @$filteredGenres > 0) {
+
+			$find->{'genreTracks.genre'} = { 'in' => $filteredGenres };
+		}
 
 		# Prevent items that have already been played from being played again
 		# This fails when multiple clients are playing random mixes. -- Max
@@ -287,9 +322,13 @@
 				# random year to a genre.
 				my $year;
 
-				if($type eq 'year') {
+				if ($type eq 'year') {
+
 					$year = getRandomYear($filteredGenres);
-					$find->{'year'} = $year;
+
+					if ($year) {
+						$find->{'year'} = $year;
+					}
 				}
 
 				if ($i == 1) {



More information about the checkins mailing list