How to remove duplicate tracks from Banshee?

It is a known bug that has been fixed in the newer versions of Banshee.

You can use the latest version of Banshee from the Banshee PPA:

sudo add-apt-repository ppa:banshee-team/ppa
sudo apt-get update && sudo apt-get upgrade

How do I subscribe to a bug?


Locate the sqlite3 database (~/.config/banshee-1/banshee.db) and run the following query:

delete from coretracks where TrackID in
(
  select trackid from 
     (
      select TrackID as trackid, count(TrackID) as c from coretracks 
      group by TitleLowered,ArtistID,AlbumID,Title
     )
  where c > 1
);

PS Use the command "sqlite3" to open the database, and not just "sqlite".

PPS I had to run the query several times, each run only deletes one additional duplicate. This happens because the inner select only gives you back the ID of one surplus track for each Title/Artist/Album combination.


This answer uses python to access the banshee database, then perform the sql action which donbicca lists with a twist. Instead of having to run the sql code many times, I have asked python to loop the sql code over the number of instances which exist in the sql code. You only need to run this code once. You need to replace your home path (replace "/home/JONDOE" with your home path).

#!/usr/bin/env python

import sqlite3

#open database to determine number of rows to loop over

db = sqlite3.connect('/home/me/.config/banshee-1/banshee.db')
cursor = db.cursor()

a = cursor.execute('SELECT TrackID from coretracks group by TitleLowered,ArtistID,AlbumID,Title')
a_trackid = a.fetchall()
db.close()

#Close database to ensure results do not impact future results. Then reopen database

db = sqlite3.connect('/home/me/.config/banshee-1/banshee.db')
cursor = db.cursor()
sql = ('DELETE from coretracks where TrackID in (SELECT TrackID from (SELECT TrackID as trackid, count(TrackID) as g from coretracks group by TitleLowered,ArtistID,AlbumID,Title) where g > 1)')

for i in a_trackid:
    cursor.execute(sql)

db.commit()
db.close()