erland wrote:
hakan Wrote:
Would you accept patches that add this capability to your TrackStat
plugin? I think I'll never get around to publish (and support) my own
Plugin, but yours is already "out there" ;-)
Yes, patches are very welcome.
Just post them here in the forum or send them to me by email: erland_i
at hotmail.com
Hi,
Here is a patch against 1.10.1; on my installation, it works with files
both with and without musicbrainz_ids.
Please note that you have to extend your track_statistics table by a
column "musicbrainz_id varchar(40)".
Regards,
Hakan
--
The Key To Immortality Is First Living A Life Worth Remembering.
diff -wbur TrackStat-1.10.1-dist/Backup/File.pm TrackStat-1.10.1/Backup/File.pm
--- TrackStat-1.10.1-dist/Backup/File.pm 2006-02-26 10:51:08.000000000
+0100
+++ TrackStat-1.10.1/Backup/File.pm 2006-03-05 23:44:49.000000000 +0100
@@ -49,7 +49,7 @@
{
my $filename = shift;
- my $sql = ("SELECT url, playCount, lastPlayed, rating FROM
track_statistics");
+ my $sql = "SELECT url, musicbrainz_id, playCount, lastPlayed, rating
FROM track_statistics";
my $dbh = Slim::Music::Info::getCurrentDataStore()->dbh();
my $sth = $dbh->prepare( $sql );
@@ -63,15 +63,18 @@
print $output '<?xml version="1.0" encoding="UTF-8"?>'."\n";
print $output "<TrackStat>\n";
- my( $url, $playCount, $lastPlayed, $rating );
+ my( $url, $mbId, $playCount, $lastPlayed, $rating );
eval {
- $sth->bind_columns( undef, \$url, \$playCount, \$lastPlayed,
\$rating );
+ $sth->bind_columns( undef, \$url, \$mbId, \$playCount,
\$lastPlayed, \$rating );
my $result;
while( $sth->fetch() ) {
if($url) {
$url = escape($url);
debugMsg("Backing up: $url\n");
print $output " <track>\n
<url>$url</url>\n";
+ if($mbId) {
+ print $output "
<musicbrainzId>$mbId</musicbrainzId>\n";
+ }
if($playCount) {
print $output "
<playCount>$playCount</playCount>\n";
}
@@ -272,6 +275,7 @@
my $curTrack = shift;
my $url = $curTrack->{'url'};
+ my $mbId = $curTrack->{'musicbrainzId'};
my $playCount = $curTrack->{'playCount'};
my $lastPlayed = $curTrack->{'lastPlayed'};
my $rating = $curTrack->{'rating'};
@@ -281,28 +285,35 @@
return unless $track;
- my $trackHandle =
Plugins::TrackStat::Plugin::searchTrackInStorage($url);
+ my $trackHandle =
Plugins::TrackStat::Plugin::searchTrackInStorage($url, $mbId);
my $sql;
if ($playCount) {
debugMsg("Marking as played in storage: $playCount\n");
+
+ my $key = $url;
+
+ $lastPlayed = '0' if (!(defined($lastPlayed)));
+
if($trackHandle) {
- if($lastPlayed) {
- $sql = ("UPDATE track_statistics set
playCount=$playCount, lastPlayed=$lastPlayed where url=?");
- }else {
- $sql = ("UPDATE track_statistics set
playCount=$playCount where url=?");
+ my $queryParameter = "url";
+ if (defined($mbId)) {
+ $queryParameter = "musicbrainz_id";
+ $key = $mbId;
}
+
+ $sql = "UPDATE track_statistics set
playCount=$playCount, lastPlayed=$lastPlayed where $queryParameter = ?";
}else {
- if($lastPlayed) {
- $sql = ("INSERT INTO track_statistics
(url,playCount,lastPlayed) values (?,$playCount,$lastPlayed)");
+ if (defined($mbId)) {
+ $sql = "INSERT INTO track_statistics (url,
musicbrainz_id, playCount, lastPlayed) values (?, '$mbId', $playCount,
$lastPlayed)";
}else {
- $sql = ("INSERT INTO track_statistics
(url,playCount) values (?,$playCount)");
+ $sql = "INSERT INTO track_statistics (url,
musicbrainz_id, playCount, lastPlayed) values (?, NULL, $playCount,
$lastPlayed)";
}
}
my $dbh = Slim::Music::Info::getCurrentDataStore()->dbh();
my $sth = $dbh->prepare( $sql );
eval {
- $sth->bind_param(1, $url , SQL_VARCHAR);
+ $sth->bind_param(1, $key , SQL_VARCHAR);
$sth->execute();
$dbh->commit();
};
diff -wbur TrackStat-1.10.1-dist/Plugin.pm TrackStat-1.10.1/Plugin.pm
--- TrackStat-1.10.1-dist/Plugin.pm 2006-02-26 10:51:08.000000000 +0100
+++ TrackStat-1.10.1/Plugin.pm 2006-03-05 23:12:23.000000000 +0100
@@ -995,6 +995,7 @@
struct TrackInfo => {
url => '$',
+ mbId => '$',
playCount => '$',
lastPlayed => '$',
rating => '$'
@@ -1635,6 +1636,7 @@
debugMsg("Marking as played in storage\n");
my $playCount;
+
if($trackHandle && $trackHandle->playCount) {
$playCount = $trackHandle->playCount + 1;
}elsif($track->playCount){
@@ -1642,20 +1644,39 @@
}else {
$playCount = 1;
}
+
my $lastPlayed = $track->lastPlayed;
if(!$lastPlayed) {
$lastPlayed = time();
}
+ my $mbId;
+ if ($trackHandle) {
+ $mbId = $trackHandle->mbId;
+ }
+
+ my $key = $url;
+ $key = $mbId if (defined($mbId));
+
if ($trackHandle) {
- $sql = ("UPDATE track_statistics set playCount=$playCount,
lastPlayed=$lastPlayed where url=?");
+ if (defined($mbId)) {
+ $sql = "UPDATE track_statistics set
playCount=$playCount, lastPlayed=$lastPlayed where musicbrainz_id = ?";
+ } else {
+ $sql = "UPDATE track_statistics set
playCount=$playCount, lastPlayed=$lastPlayed where url = ?";
+ }
}else {
- $sql = ("INSERT INTO track_statistics
(url,playCount,lastPlayed) values (?,$playCount,$lastPlayed)");
+ $mbId = $track->{musicbrainz_id};
+ if (defined($mbId)) {
+ $sql = "INSERT INTO track_statistics (url,
musicbrainz_id, playCount, lastPlayed) values (?, '$mbId', $playCount,
$lastPlayed)";
+ } else {
+ $sql = "INSERT INTO track_statistics (url,
musicbrainz_id, playCount, lastPlayed) values (?, NULL, $playCount,
$lastPlayed)";
+ }
}
+
my $dbh = Slim::Music::Info::getCurrentDataStore()->dbh();
my $sth = $dbh->prepare( $sql );
eval {
- $sth->bind_param(1, $url , SQL_VARCHAR);
+ $sth->bind_param(1, $key , SQL_VARCHAR);
$sth->execute();
$dbh->commit();
};
@@ -1746,20 +1767,31 @@
sub searchTrackInStorage {
my $track_url = shift;
+ my $mbId = shift;
my $ds = Slim::Music::Info::getCurrentDataStore();
my $track = $ds->objectForUrl($track_url);
+ my $searchString = "";
+ my $queryAttribute = "";
return 0 unless $track;
- debugMsg("URL: ".$track->url."\n");
+
+ $mbId = $track->{musicbrainz_id} if (!(defined($mbId)));
+
+ debugMsg("searchTrackInStorage(): URL: ".$track->url."\n");
+ debugMsg("searchTrackInStorage(): mbId: ". $mbId ."\n") if
(defined($mbId));
# create searchString and remove duplicate/trailing whitespace as well.
- my $searchString = "";
- $searchString .= $track->url;
+ if (defined($mbId)) {
+ $searchString = $mbId;
+ $queryAttribute = "musicbrainz_id";
+ } else {
+ $searchString = $track->url;
+ $queryAttribute = "url";
+ }
return 0 unless length($searchString) >= 1;
- my $sql = ("SELECT url, playCount, lastPlayed, rating FROM
track_statistics where url=?");
-
+ my $sql = "SELECT url, musicbrainz_id, playCount, lastPlayed, rating
FROM track_statistics where $queryAttribute = ?";
my $dbh = Slim::Music::Info::getCurrentDataStore()->dbh();
my $sth = $dbh->prepare( $sql );
my $result = undef;
@@ -1767,10 +1799,10 @@
$sth->bind_param(1, $searchString , SQL_VARCHAR);
$sth->execute();
- my( $url, $playCount, $lastPlayed, $rating );
- $sth->bind_columns( undef, \$url, \$playCount, \$lastPlayed,
\$rating );
+ my( $url, $mbId, $playCount, $lastPlayed, $rating );
+ $sth->bind_columns( undef, \$url, \$mbId, \$playCount,
\$lastPlayed, \$rating );
while( $sth->fetch() ) {
- $result = TrackInfo->new( url => $url, playCount =>
$playCount, lastPlayed => $lastPlayed, rating => $rating );
+ $result = TrackInfo->new( url => $url, mbId => $mbId,
playCount => $playCount, lastPlayed => $lastPlayed, rating => $rating );
}
};
if( $@ ) {
diff -wbur TrackStat-1.10.1-dist/SQL/SQLite/dbcreate.sql
TrackStat-1.10.1/SQL/SQLite/dbcreate.sql
--- TrackStat-1.10.1-dist/SQL/SQLite/dbcreate.sql 2006-02-26
10:51:08.000000000 +0100
+++ TrackStat-1.10.1/SQL/SQLite/dbcreate.sql 2006-02-22 18:45:47.000000000
+0100
@@ -1,5 +1,6 @@
CREATE TABLE track_statistics (
url varchar UNIQUE NOT NULL,
+ musicbrainz_id varchar, -- musicbrainz uuid (36 bytes of text)
playCount integer,
lastPlayed integer,
rating integer
diff -wbur TrackStat-1.10.1-dist/SQL/mysql/dbcreate.sql
TrackStat-1.10.1/SQL/mysql/dbcreate.sql
--- TrackStat-1.10.1-dist/SQL/mysql/dbcreate.sql 2006-02-26
10:51:08.000000000 +0100
+++ TrackStat-1.10.1/SQL/mysql/dbcreate.sql 2006-02-22 18:45:20.000000000
+0100
@@ -1,5 +1,6 @@
CREATE TABLE track_statistics (
url text NOT NULL,
+ musicbrainz_id varchar(40), -- musicbrainz uuid (36 bytes of text)
playCount int(10) unsigned,
lastPlayed int(10) unsigned,
rating int(10) unsigned
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/plugins