LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-26-2015, 08:28 AM   #1
mstrimel
Member
 
Registered: Apr 2004
Location: USA
Distribution: Mint 19 Cinnamon
Posts: 75

Rep: Reputation: 0
SQLite and banshee: query from command line?


hi,
My music collection is fully curated in Banshee, and i LOVE the "Smart Playlists".

I need a CLI way to export my Banshee Smart Playlists. Reason being, I am using Music Player Daemon to drive my whole-house audio. (Exporting each Smart Playlist from the Banshee GUI is way too time consuming and can't be done via cron).

I am NOT a programmer, but i see strings like the following in Banshee's SQLite database (CoreSmartPlaylists table)

Code:
<request><query banshee-version="1"><and><equals><field name="genre" /><string>Acid Jazz</string></equals><greaterThanEquals><field name="rating" /><int>3</int></greaterThanEquals></and></query></request>
Clearly these parameters are being used by Banshee to create my Smart Playlists, but how? This is not any query format that i can recognize or parse [no surprise, given that i know nothing : ) ]

As a fun newbie project, i am willing to research the heck out of SQLite3 and bash, to turn this text string into some kind of CLI query that will output results to a file. BUT, can someone give me a hint to get going? What's the concept for turning that string into a query?

And is that even the right question?
thanks!
Mary
 
Old 07-26-2015, 11:13 AM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
EDIT: Disregard the info below, obviously I need to work on my reading comprehension. Rereading your post I see that you are way past that.

I'll take a look at that table and see if I can figure anything out.

_________________________________________________________________________________________________

You don't say what distro you are using, but you will need the sqlite command line interface. On Debain the package is named, oddly, sqlite3.

Then at the command line enter:
Code:
$ sqlite3 /path/to/banshee.db
Read the man page (man sqlite3) to see a list of available commands or you can enter ".help" at the prompt. For example to see all of the tables in a database you enter ".tables":
Code:
$ sqlite3 banshee.db 
SQLite version 3.8.10.2 2015-05-20 18:17:19
Enter ".help" for usage hints.
sqlite> .tables
CoreAlbums                CoreRemovedTracks         CoverArtDownloads       
CoreArtists               CoreShuffleModifications  HyenaModelVersions      
CoreCacheModels           CoreShufflers             IaItems                 
CoreConfiguration         CoreShuffles              LastfmStations          
CorePlaylistEntries       CoreSmartPlaylistEntries  PodcastEnclosures       
CorePlaylists             CoreSmartPlaylists        PodcastItems            
CorePrimarySources        CoreTracks                PodcastSyndications

I don't use banshee but I experimented a little and you can get data out like so:
Code:
$ sqlite3 banshee.db 'select Title from CoreTracks' > tracks.txt
HTH

Last edited by norobro; 07-26-2015 at 12:01 PM.
 
Old 07-26-2015, 08:06 PM   #3
mstrimel
Member
 
Registered: Apr 2004
Location: USA
Distribution: Mint 19 Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by norobro View Post

I don't use banshee but I experimented a little and you can get data out like so:
Code:
$ sqlite3 banshee.db 'select Title from CoreTracks' > tracks.txt
HTH
Thank you, that last bit does actually help tons; i did not know that sqlite3 could export to a file using the ">" symbol. I got it to export the track list for a particular playlist by looking up the playlist ID manually:

Code:
sqlite3 /home/mary/.config/banshee-1/bansheebackupmns.db 'select TrackID FROM CoreSmartPlaylistEntries WHERE SmartPlaylistID=18' > tracks.txt
So to really dumb it down for me: i need to write a shell script that will create a unique text file for each SmartPlaylist (using its name, not its ID) and then fill that text file with the actual track names. I have no idea HOW, but i think that is the "what".

Any suggetions welcome!
 
Old 07-27-2015, 08:24 AM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
The banshee.db is a relational database so it is possible to get the playlist names and the track names. Try playing around with like the following:
Code:
sqlite> select coresmartplaylists.name, corealbums.title, trackid, coretracks.title from coresmartplaylistentries join coresmartplaylists using(smartplaylistid) join coretracks using(trackid) join corealbums on coretracks.albumid=corealbums.albumid;
Executing that command from the command line should give you a file that contains all of your playlists which you will be able to parse, in bash using awk or sed, to separate the different smart play lists into separate files.
 
1 members found this post helpful.
Old 07-27-2015, 07:25 PM   #5
mstrimel
Member
 
Registered: Apr 2004
Location: USA
Distribution: Mint 19 Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 0
Oh yeah, I see that "join" is the key concept here ... Something like this is exactly what I need.
Can't wait to sit down and try this. Thank you!!
 
Old 07-29-2015, 12:06 PM   #6
mstrimel
Member
 
Registered: Apr 2004
Location: USA
Distribution: Mint 19 Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 0
Hello,
So, one problem I am having right off the bat, is that sqlite3 does not seem to recognize when I do a statement involving the [table].[column] construct.

To return song names and artist names, and associate them with smart playlist names, I believe I need to join AT LEAST three tables, maybe four, in my query [CoreSmartPlaylistEntries (to identify the tracks by trackId and playlist ID), CoreSmartPlaylists (to associate playlistID with a playlist name), CoreTracks (to associate trackId with song name) and CoreArtists (to associate artist name).

To test this on a particular playlist (#5), I am using a SELECT ... FROM, then a series of JOIN ... ON, followed by a "WHERE CoreSmartPlaylists.PlaylistID=5;"

The error I'm getting back is that "CoreSmartPlaylists.PlaylistID is ambiguous" or that "there is no such field as CoreSmartPlaylists.PlaylistID". If I truncate it to just PlaylistID it also complains.

Sorry I am not in front of my computer to give the exact commands. But why in principle would SQLite3 ever reject "CoreSmartPlaylists.PlaylistID" as ambigouos? [I've also tried flipping the order to PlaylistID.CoresmartPlaylists but I think it still gives the error.]

Thanks for any suggestions!
Mary
 
Old 07-29-2015, 03:26 PM   #7
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
When you get a chance please post your query.

I imported a CD and created a smart play list with one song from the CD.
Query:
Code:
sqlite> .headers on
sqlite> select name, corealbums.artistname, corealbums.title, trackid, coretracks.title 
FROM CoreSmartPlaylistEntries
join coresmartplaylists using(smartplaylistid)
join coretracks using(trackid)
join corealbums on coretracks.albumid=corealbums.albumid
where coresmartplaylists.smartplaylistid=1;
Although it's probably not exactly what you are looking for, here's the output:
Code:
Name|ArtistName|Title|TrackID|Title
Test Smart Play List|Sybil|Cold Drink|1|All I Like
 
Old 07-29-2015, 07:14 PM   #8
mstrimel
Member
 
Registered: Apr 2004
Location: USA
Distribution: Mint 19 Cinnamon
Posts: 75

Original Poster
Rep: Reputation: 0
Smile

Your query works perfectly, thanks.

My error: I had failed to list in my SELECT statement all of the columns that i was after [i thought i was supposed to list them in the JOIN statements for each of their tables, not the SELECT, but i was just super wrong!].

Now, to automate this proces, I propose to:

1. embed these SQLITE3 statements into a bash shell script that will output their results to a file named [smartplaylist].txt
2. have my bash shell script run these statements sequentially for SmartPlaylistID's [1,2,3...n]
3. add awk commands to the shell script that will format the resulting txt files into playlists recognized by mpd

Is that a reasonable game plan? This will be my first script, but i'm very motivated :-)

Thank You!!!
 
Old 07-29-2015, 08:31 PM   #9
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You're welcome!

The only problem that I see with your method is that you will have to hard code your queries. You can put the query in a loop and iterate your play list numbers, but then how will your loop know when to stop?

Another way to approach it is to perform one query to get all of your play lists from the db and then parse the output file.

Give the following a try from the command line:
Code:
$ sqlite3 banshee.db 'select smartplaylistid, name, corealbums.artistname, corealbums.title, trackid, coretracks.title 
FROM CoreSmartPlaylistEntries
join coresmartplaylists using(smartplaylistid)
join coretracks using(trackid)
join corealbums on coretracks.albumid=corealbums.albumid ' > lists.txt
Code:
$ awk -F "|" '{print >> $1".txt"}' lists.txt
The awk command should separate your play lists into files named 1.txt, 2.txt etc.

I'll leave the parsing of the files to you.

Norm
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sqlite Database Query Software jogl_z_8 Debian 2 10-31-2012 08:05 PM
sqlite query change question marks to NULL (?) ted_chou12 Linux - Software 4 04-25-2011 05:36 AM
grep query to list 1 line [which is fixed] and the next line after it [variable text] Glenn D. Linux - Software 3 01-20-2011 06:21 AM
LXer: Sqlite-Commander - A ncurses based tool to display the records and tables of a sqlite database LXer Syndicated Linux News 0 01-02-2011 08:11 AM
help with sqlite query to retriev browser history tiggertie Linux - General 1 05-24-2010 07:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration