<?sphp $this->text('pagetitle') ?>
 
Home of the Squeezebox™ & Transporter® network music players.

TrackStat plugin

From SqueezeboxWiki

Revision as of 21:56, 8 May 2008 by Erland (Talk | contribs)
Jump to: navigation, search

Contents

Overview

This is a statistic plugin for Slimserver. Slimserver normally stores statistics about the last time a track was played, when a specific track was added to the library and how many times a track has been played. The problem is that all this statistics is cleared every time you perform a full rescan of slimserver. To me this makes the statistics useless since I need to perform rescans from time to time.

The TrackStat plugin solves this problem by making sure that the statistics survives a rescan. This is the core functionality of the TrackStat plugin and the reason I wrote it. Besides this TrackStat also extends the statistics a bit, one example is that it doesn't count a track as played just because you listen to the first 2 seconds of it, you will have to play a certain amount of the track until it is played. TrackStat also makes it possible to put a rating on all your tracks by holding a number between 1-5 down on the now playing screen.

The other main functionality the TrackStat plugins provides is various ways to browse your music based on the statistic information. The standard slimserver only makes it possible to show most played tracks. The TrackStat plugin makes it possible to show the statistics in a lot more ways. The purpose is simply to give you another way to select which music you like to play, for example like:

  • Find tracks you haven't played for a long time
  • Find tracks you have recently added to the library
  • Find top rated tracks
  • Find least played tracks
  • And a lot more...

Browsing the statistics is one thing but TrackStat also integrates with the DynamicPlaylist plugin and provides a number of different random playlists where the ordering prioritize different tracks based on the different statistic information. The advantage of dynamic playlists is that new tracks are added to the playlist continously based on the statistics at the time.

Installation

  1. Download from http://erland.homeip.net/download
  2. Remove any previous version of TrackStat from the Slimserver Plugins directory
  3. Unzip the new version in the Slimserver Plugins directory
  4. Optionally install other plugins that extends TrackStat with more functionality
  5. When you have installed everything you might also want to look at:

Bugs and new features

The current list of known bugs and wishes for new features can be found here:

If you want to encourage future development of this plugin you should also consider making a donation

http://erland.homeip.net/donate

iTunes integration

TrackStat provides an integration with iTunes. The standard Slimserver iTunes integration makes it possible get available tracks from iTunes and also retrieves the rating, play counts and played time information. The TrackStat iTunes integration provides the following main functionalities:

  • Import of ratings, play counts and played time for tracks that already exists in slimserver, basically the same as the standard Slimserver iTunes integration
  • Export of ratings, play counts and played time for all tracks in SlimServer. The export is done through a text file which will have to be feed into iTunes using a provided perl script.
  • The Import and Export functionality also provides a way to map file paths. This means that the TrackStat iTunes integration can be used in a situation where you have FLAC format on all music in Slimserver and MP3 in iTunes. It also works in a configuration where Slimserver runs on Linux and iTunes on Windows.
  • Possibility to log information about changed ratings, play counts, played time on tracks in SlimServer as they are played. This log file can be feed into iTunes using a provided perl script. The result is that you can easily have Slimserver as your statistic source and update the iTunes database with latest statistics at regular intervals.
  • If you have the Multi Library plugin installed you will also get some options to limit the export/import to selected libraries defined in the Multi Library plugin
  • The import/export functionality is found under the Custom Scan menu in the home page of SlimServer web interface.

MusicIP integration

TrackStat provides an integration with MusicIP. The standard Slimserver MusicIP integration makes it possible to get available tracks from MusicIP and also retrieves the rating, play counts and played time information. The TrackStat MusicIP integration provides the following main functionalities:

  • Import of ratings, play counts and played time for tracks that already exists in slimserver, basically the same as the standard Slimserver MusicIP integration.
  • Export of ratings, play counts and played time for all tracks in SlimServer.
  • The Import and Export functionality also provides a way to map file paths. This mean that the TrackStat MusicIP integration can be used in a situation where you have FLAC format on all music in Slimserver and MP3 in MusicIP. It also works in a configuration where Slimserver runs on a Linux and MusicIP on Windows.
  • When you change a rating or play a track in Slimserver it will also dynamically be sent to MusicIP so the statistic information in MusicIP always are up to date.
  • If you have the Multi Library plugin installed you will also get some options to limit the export/import to selected libraries defined in the Multi Library plugin
  • The import/export functionality is found under the Custom Scan menu in the home page of SlimServer web interface.

Amarok integration

TrackStat provides an integration with Amarok. The TrackStat Amarok integration provides the following main functionalities:

  • Import of ratings, play counts and played time from Amarok for tracks that already exists in slimserver.
  • Export of ratings, play counts added time and played time to Amarok for all tracks in SlimServer.
  • The Import and Export functionality also provides a way to map file paths. This mean that the TrackStat Amarok integration can be used in a situation where you have FLAC format on all music in Slimserver and MP3 in Amarok. It also works in a configuration where Slimserver runs on a one computer and Amarok on another computer.
  • When you change a rating or play a track in Slimserver it will also dynamically be sent to Amarok so the statistic information in Amarok always are up to date.
  • The TrackStat Amarok integration only works together with Amarok using MySQL. It has not been tested together with Amarok using the default SQLite database.
  • If you have the Multi Library plugin installed you will also get some options to limit the export/import to selected libraries defined in the Multi Library plugin
  • The import/export functionality is found under the Custom Scan menu in the home page of SlimServer web interface.

Persistent storage and backup of statistics

Normally in Slimserver all statistics are clear when you perform a full rescan, there is also no way to take a backup of just the statistic data which can be restored after the rescan. TrackStat provides functionality in this area in a number of ways:

  • It is possible to manually backup and restore statistic data.
  • It is possible to automatically turn on nightly backup of statistic data every night, note that this requires that your computer is powered on. A new backup file will be created every night if this functionality is enabled. Note! There is currently no clean up functionality that removes old backup files, so you will have to do this manually once per month or year to make sure your disk isn't filled with backup files.
  • TrackStat stores the statistic information in a separate table in the database, the result is that statistic data will automatically survive a full rescan of Slimserver. If you have MusicBrainz tags in your music it will even survive a situation where you have moved or renamed your music files, without MusicBrainz tag only statistics for unmoved files with the same name as before will survive.

Display of ratings

The normal Slimserver display ratings in the Web interface in the "Song info" page. TrackStat extends this by making it possible to also display ratings in all track listings both in web interface and on the SqueezeBox/Transporter display. TrackStat does this by defining a number of new title formats which you can select to show in the track listings. The following title formats are supported:

  • TRACKSTATRATINGDYNAMIC - Shows the rating as a dynamic number of characters, a rating of 3 is displayed as (_ is shown here instead of spaces): "_*_*_*"
  • TRACKSTATRATINGSTATIC - Shows the rating as static number of characters, a rating of 3 is displayed as (_ is shown here instead of spaces): "_*_*_*____" (Note the spaces at the end)
  • TRACKSTATRATINGNUMBER - Shows the rating as a digit, a rating of 4 is displayed as "4"

To configure Slimserver to show the ratings you will need to configure the display formatting attributes, this is done as follows:

  1. Goto "Server Settings / Formatting" in the slimserver web interface
  2. Step down to the "TITLE FORMAT" setting. Here you select which title format that shall be used in the web interface and you also select which title formats that shall be available to select on the SqueezeBox/Transporter display. TrackStat has already added a number of different title formats that contains the above mentioned keywords. You can either compose your own title format using the existing keywords or select one of the existing ones. Note that even though you aren't going to use a title format in the web interface it needs to exist here if you like to use it on the SqueezeBox/Transporter display.
  3. Click the Change button to save your changes
  4. Goto "Player Settings" for the SqueezeBox/Transporter in the web interface.
  5. Step down to the "TITLE FORMAT" settings. Here you can select which title formats that shall be available to toggle between on the SqueezeBox/Transporter display and also select the one that shall be active by default.
  6. Click the Change button to save your changes

Note that to fully customize the display on the SqueezeBox/Transporter I recommend that you also install the MusicInfoSCR plugin. This will make it possible to customize exactly what should be shown on both display rows, as an example you can put the rating information on the upper row and still just have the track, artist album information on the button row as usual.

Automatically change ratings

By default ratings in TrackStat is only changed when the user choose to change the rating. You can optionally turn on the "Automatic rating" option in "Server Settings/Plugins/TrackStat". If you turn on automatic ratings the ratings of the songs will be automatically changed based on if you listen through a whole song or skip it directly. If you skip a song in the beginning the rating will be decreased, if you listen through almost the whole song the rating will be increased. If the "Dynamic automatic ratings" option also found in "Server Settings/Plugins/TrackStat" also is enabled, ratings will be increased/decreased faster when the rating is around 3 stars and slower when the rating is around 1 or 5 stars.

Available statistics

The TrackStat plugin stores the following different statistic information:

  • Rating
  • The last time a song was played
  • The number of time a song has been played
  • The time a song was added to Slimserver
  • A history log of exactly when each song has been played or rated

Note also that there is a difference compared to Slimserver when a song is detected as it has been played. Standard Slimserver detect a song as played as soon as you have played it even though you just played the first second and skipped to the next song directly. TrackStat improves this by only counting a song as played if the following criterias are true:

  • The song is longer than 5 second
  • At least 50% of the song has been played unless the song is longer than 30 minutes

The exact value of the above criterias are configurable in the TrackStat settings page. The value of having them is that you can safely skipping a song without increasing the play count, this is important for statistics like "Most played songs" to be really valuable.

Browsing the statistics

The statistics managed by the TrackStat plugin can be browsed either from the TrackStat web interface or from the "Plugins/TrackStat" menu on the SqueezeBox/Transporter. You can also move from the standard browse menus to TrackStat statisitics by hitting the TS buttons in the web interface or holding play down for a while if a M is displayed in the upper right corner in a browse menu on the SqueezeBox/Transporter. When you goto the statistics by clicking the TS button or holding play the statistics will be shown in the context of the item you selected.

The following different ways of browsing the statistics are currently available:

  • Albums rated
  • Artists rated
  • Songs rated
Shows songs, album, artists with a specific rating. For albums and artists an average rating is calculated based on the ratings of all songs on the album/artists, unrated songs is calculated as a rating of 3.
  • All albums
  • All artists
  • All genres
  • All playlists
  • All songs
  • All years
Shows the statistics information about albums, artists, genres, playlists, songs and years with a standard sorting. For example songs is sorted according to track number
  • Albums played long ago
  • Artists played long ago
  • Songs played long ago
Shows the albums, artists or songs that hasn't been played for a long time. The sorting is done on the last played time statistic
  • Last added albums
  • Last added artists
  • Last added songs
Shows the albums, artists or songs that was last added to slimserver. Note that if TrackStat wasn't installed when you added the music to slimserver the last added time will be based on the last time the music file was modified.
  • Last played albums
  • Last played artists
  • Last played songs
Shows the albums, artists or songs that was last played. This is basically a history log but it only show each album, artist, song once in the list.
  • Least played albums
  • Least played artists
  • Least played songs
Shows the albums, artists or songs that has been played the least number of times.
  • Least played albums not recently added
  • Least played artists not recently added
  • Least played songs not recently added
Shows the albums, artists or songs that has been played the least number of times, but it ignores those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Least played albums recently added
  • Least played artists recently added
  • Least played songs recently added
Shows the albums, artists or songs that has been played the least number of times, but it only include those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Most played albums
  • Most played artists
  • Most played genres
  • Most played playlists
  • Most played songs
  • Most played years
Shows the albums, artists, genres, playlists, songs or years that has been played the most number of times.
  • Most played albums not recently added
  • Most played artists not recently added
  • Most played songs not recently added
Shows the albums, artists or songs that has been played the most number of times, but it ignores those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Most played albums recently added
  • Most played artists recently added
  • Most played songs recently added
Shows the albums, artists or songs that has been played the most number of times, but it only includes those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Most played albums not recently played
  • Most played artists not recently played
  • Most played songs not recently played
Shows the albums, artists or songs that has been played the most number of times, but it ignores those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Most played albums recently played
  • Most played artists recently played
  • Most played songs recently played
Shows the albums, artists or songs that has been played the most number of times, but it only includes those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Never played albums
  • Never played artists
  • Never played songs
Shows the albums, artists or songs that has never been played
  • Not completely rated albums
  • Not completely rated artists
Shows the albums or artists that has at least one song that hasn't been rated yet
  • Not completely rated albums not recently added
  • Not completely rated artists not recently added
Shows the albums or artists that has at least one song that hasn't been rated yet, but it ignores those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Not completely rated albums recently added
  • Not completely rated artists recently added
Shows the albums or artists that has at least one song that hasn't been rated yet, but only include those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Not completely rated albums not recently played
  • Not completely rated artists not recently added
Shows the albums or artists that has at least one song that hasn't been rated yet, but it ignores those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Not completely rated albums recently played
  • Not completely rated artists recently added
Shows the albums or artists that has at least one song that hasn't been rated yet, but only include those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings.
  • Not rated albums not recently added
  • Not rated artists not recently added
  • Not rated songs not recently added
Shows the albums, artists or songs that hasn't been rated, but it ignores those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings. When showing albums or artists only those that has no rated songs is shown.
  • Not rated albums recently added
  • Not rated artists recently added
  • Not rated songs recently added
Shows the albums, artists or songs that hasn't been rated, but it only include those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings. When showing albums or artists only those that has no rated songs is shown.
  • Not rated albums not recently played
  • Not rated artists not recently played
  • Not rated songs not recently played
Shows the albums, artists or songs that hasn't been rated, but it ignores those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings. When showing albums or artists only those that has no rated songs is shown.
  • Not rated albums recently played
  • Not rated artists recently played
  • Not rated songs recently played
Shows the albums, artists or songs that hasn't been rated, but it only include those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings. When showing albums or artists only those that has no rated songs is shown.
  • Partly/Never played albums
  • Partly/Never played artists
Shows the albums or artists that has at least one song which have never been played
  • Top rated albums
  • Top rated artists
  • Top rated genres
  • Top rated playlists
  • Top rated songs
  • Top rated years
Show the albums, artists, genres, playlists, songs or years that has the highest ratings. For albums, artists, genres, playlists and years an average rating is calculated where unrated tracks is calculated as a rating of 3.
  • Top rated albums not recently added
  • Top rated artists not recently added
  • Top rated songs not recently added
Show the albums, artists or songs that has the highest ratings, but it ignores those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings. For albums and artists an average rating is calculated where unrated tracks is calculated as a rating of 3.
  • Top rated albums recently added
  • Top rated artists recently added
  • Top rated songs recently added
Show the albums, artists or songs that has the highest ratings, but it only includes those that has been added to slimserver within the last 30 days. The exact number of days is configurable in the TrackStat settings. For albums and artists an average rating is calculated where unrated tracks is calculated as a rating of 3.
  • Top rated albums not recently played
  • Top rated artists not recently played
  • Top rated songs not recently played
Show the albums, artists or songs that has the highest ratings, but it ignores those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings. For albums and artists an average rating is calculated where unrated tracks is calculated as a rating of 3.
  • Top rated albums recently played
  • Top rated artists recently played
  • Top rated songs recently played
Show the albums, artists or songs that has the highest ratings, but it only includes those that has been played within the last 30 days. The exact number of days is configurable in the TrackStat settings. For albums and artists an average rating is calculated where unrated tracks is calculated as a rating of 3.

Playing music based on statistics

TrackStat provides a number of ways to start playing music based on the statistics

  • You can browse the statistic in the web interface and hit the play icons, this will play all the songs for the item related to the play icon you clicked on. Note that if you clicked on a play icon beside an album when showing Not completely rated albums statistics this means that all tracks on the album will be played not just the unrated ones.
  • You can browse the statistic with the remote on the SqueezeBox/Transporter and hit play, this will play all songs related to the item you clicked on.
  • If you have installed the Dynamic Playlist plugin you can in the web interface click on the "Play as dynamic playlist" link. This will start playing a dynamic playlist based on the statistics you are currently showing. The dynamic playlist will continoue to play until all songs matching the selected statistic type has been played.
  • If you have installed the Dynamic Playlist plugin you can on the SqueezeBox/Transporter browse with the remote to the "Plugins/Dynamic Playlists" menu and select the statistics playlist of your choice and hit play. This will start playing a dynamic playlist based on the statistics you are currently showing. The dynamic playlist will continoue to play until all songs matching the selected statistic type has been played.
  • If you have installed the Dynamic Playlist plugin you can goto the Dynamic Playlist plugin web interface select the statistics playlist of your choice and hit play. This will start playing a dynamic playlist based on the statistics you are currently showing. The dynamic playlist will continoue to play until all songs matching the selected statistic type has been played.

Favorite statistics

By clicking on the "Select favorites" link in the TrackStat web interface you can select a number of statistics that you use often. The statistic types you selects will appear in the "Favorites" statistic group in the TrackStat web interface. The real use for this comes when you use TrackStat together with the Custom Browse plugin because then you can create a browse menu that makes it possible to browse statistics but it only shows the statistics you have selected as favorites.

SQL Playlist integration

TrackStat makes the following playlist types available in the SQL Playlist plugin. The advantage of using these playlists available through the SQL Playlist plugin is that you can have different settings for different playlist. With the dynamic playlists available through TrackStat the global TrackStat settings is used for all playlists.

  • TrackStat most played albums
Random playlist with only most played albums
  • TrackStat most played artists
Random playlist with only most played artists
  • TrackStat most played songs
Random playlist with only most played songs
  • TrackStat not rated songs
Random playlist with only not rated songs
  • TrackStat recently added albums
Random playlist with recently/not recently added albums
  • TrackStat recently added songs
Random playlist with recently/not recently added songs
  • TrackStat Top rated albums
Random playlist with only top rated albums
  • TrackStat Top rated artists
Random playlist with only top rated artists
  • TrackStat Top rated genres
Random playlist with only top rated genres
  • TrackStat Top rated playlists
Random playlist with only top rated playlists
  • TrackStat Top rated songs
Random playlist with only top rated songs
  • TrackStat Top rated years
Random playlist with only top rated years

CLI interface

The prefered way to recieve event or getting information from TrackStat is to use the provided CLI interface. TrackStat provides the following CLI commands and events.

  • Retreive rating for a track
trackstat getrating 94
trackstat getrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3
trackstat getrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3
00:04:20:06:22:b3 trackstat getrating 94
00:04:20:06:22:b3 trackstat getrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3
00:04:20:06:22:b3 trackstat getrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3
If the command succeeds it returns a "rating" parameter with the rating for the selected track between 0-5 and it also returns a "ratingpercentage" pamameter with the rating for the selected track between 0-100.
  • Set rating for a track to 4 (or 85%)
trackstat setrating 94 4
trackstat setrating 94 85%
trackstat setrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 4
trackstat setrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 85%
trackstat setrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 4
trackstat setrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 85%
00:04:20:06:22:b3 trackstat setrating 94 4
00:04:20:06:22:b3 trackstat setrating 94 85%
00:04:20:06:22:b3 trackstat setrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 4
00:04:20:06:22:b3 trackstat setrating file:///mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 85%
00:04:20:06:22:b3 trackstat setrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 4
00:04:20:06:22:b3 trackstat setrating /mnt/mp3music_small/The%20Bodyguard/12%20Trust%20In%20Me.mp3 85%
If the command succeeds it returns a "rating" parameter with the newly set rating between 0-5 and it also returns a "ratingpercentage" parameter with the rating for the selected track between 0-100.
  • Event about changed rating for a track with trackid 94 and rating 4 (or rating percentage 85%)
trackstat changedrating file%3A%2F%2F%2Fmp3music_small%2FThe%20Bodyguard%2F12%20Trust%20In%20Me.mp3 94 4 85%
  • Event about changed statistics regarding playcount=18 and lastplayed=1144572357
trackstat changedstatistic file%3A%2F%2F%2Fmp3music_small%2FThe%20Bodyguard%2F12%20Trust%20In%20Me.mp3 94 18 1144572357

Callback functions

The prefered way to receive events from TrackStat is using the CLI events, but there is also a number of callbacks which can be used. If a plugin implement any of these functions in its main plugin class they will be called by TrackStat when ratings or statistics are changed. The implementations below are just some small samples.


# This method will be called each time a rating value in TrackStat is changed by the user
# url = The url of the track on which the rating is changed
# rating = The new rating, a value between 0 - 100
sub setTrackStatRating {
	my ($client, $url, $rating) = @_;

	#
	# Call your own methods and do some interesting stuff here
	#
}


# This method will be called at the end of each played song
# url = The url of the track
# 
sub setTrackStatStatistic {
	my ($client,$url,$statistic)=@_;
	
	my $playCount = $statistic->{'playCount'};
	my $lastPlayed = $statistic->{'lastPlayed'};	
	my $musicbrainz_id = $statistic->{'mbId'};
	my $rating = $statistic->{'rating'};

	#
	# Call your own methods and do some interesting stuff here
	#
}

Database structure

The TrackStat statistic data is stored in the SlimServer database in the following tables.

track_statistics

The track_statistics table contains a single row for each song in your SlimServer library, the table consists of the following columns:

  • url - The url of the track, the same value as in tracks.url
  • musicbrainz_id - The musicbrainz id of the track if it has been tagged in the music file, the same value as in tracks.musicbrainz_id. This column is used to synchronize the url column after a rescan if files have been renamed or moved.
  • playcount - The play count of the track
  • added - The modification time of music file the first time it was part of a SlimServer rescan. This value will not be updated if you have changed the file after the first rescan it was part of. Similar as the tracks.timestamp value, with the difference that tracks.timestamp is updated as soon as the modification time of the file is changed.
  • lastplayed - The time when the track was played the last time. This is similar to the value in tracks.lastplayed with the difference that tracks.lastplayed is updated as soon as you play a millisecond of the track while the track_statistics.lastplayed is updated when you have played a part of the track. It is configurable how large amount of the track you need to play in the TrackStat section of "Server Settings/Plugins".
  • rating - The rating of a track as a value between 1 and 100. Unrated tracks is represented as a null value.

When joining the information in track_statistics with the tracks table you should do this with:

tracks.url=track_statistics.url

track_history

The track_history table contains a single row for each time a song in your SlimServer library has been played, so the table can contains the same track serveral times. The table consists of the following columns:

  • url - The url of the track, the same value as in tracks.url
  • musicbrainz_id - The musicbrainz id of the track if it has been tagged in the music file, the same value as in tracks.musicbrainz_id. This column is used to synchronize the url column after a rescan if files have been renamed or moved.
  • played - The time when the track was played.
  • rating - The rating of the track at the time it was played.

When joining the information in track_history with the tracks table you should do this with:

tracks.url=track_history.url

When joining the information in track_history with the track_statistics table you should do this with:

track_statistics.url=track_history.url