Hello.

I have a virtual library with ~10,000 tracks based on keywords in the comment tag.
For each track of that virtual library I would like to 'convert' the keywords in the comment tag into rating values (favstars1 = rating value 1) and write them to the tracks_persistent database.

I thought converting the comment tag keywords into rating values (0-5) and writing them to the tracks_persistent database would probably look something like this:

Code:
	# first get the library_id of the virtual library:
	# library_id => Slim::Music::VirtualLibraries->getRealId('RATED');

	# ??? then for each track of this virtual library in some 'repeat loop' you could do this:	

	my $rating_keyword_prefix = "favstars";
	my $thiscomment = $track->comment;
	my $ratinglevel = 0;
	
	if (defined $thiscomment && $thiscomment ne '') {
		if ($thiscomment =~ /$rating_keyword_prefix(\d)){
			($ratinglevel) = $thiscomment =~ /$rating_keyword_prefix(\d);
		}
	}

	my $ratingStatisticValue = ($ratinglevel * 20);
	my $trackURL = $track->url;
	my $urlmd5 = md5_hex($trackURL);

	my $sql = "UPDATE tracks_persistent set rating=$ratingStatisticValue where urlmd5 = ?";
	my $dbh = getCurrentDBH();
	my $sth = $dbh->prepare( $sql );
	eval {
		$sth->bind_param(1, $urlmd5);
		$sth->execute();
		commit($dbh);
	};
	if( $@ ) {
		$log->warn("Database error: $DBI::errstr\n");
		eval {
			rollback($dbh);
		};
	}
	$sth->finish();
But what would the 'wrapper' look like, i.e. how do I get all the tracks of my virtual library and cycle through them in a 'repeat loop'?

It's basically an internal database operation. Supposing this works how fast/slow would you estimate this to be for 10,000 tracks?

Thank you.


BTW this example uses $track->url to connect a track from the main library.db (tracks) to the same track in tracks_persistent. Would $track->id work as well?