Created
September 13, 2025 02:00
-
-
Save WildRikku/564bb6761395c8e3793300cc774204a3 to your computer and use it in GitHub Desktop.
Simple and dumb script to import the most important meta data to Quod Libet from SQLite. It was sufficient for me but might not be for you, for example it lacks a check for multiple artists. However I thought it might be helpful since the documentation for the Quod Libet python API is not great
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import quodlibet.library | |
| from quodlibet.query import Query | |
| from quodlibet import app | |
| import sqlite3 | |
| # you need a Quod Libet dev environment | |
| # this script and your QL songs file need to be placed at the root of your Quod Libet git checkout | |
| # there is another one for copying QL data to SQLite https://gist.github.com/WildRikku/15b645d236b2d4edf32c01c9603a2c86 | |
| dbcon = sqlite3.connect("../songs.db") | |
| dbcur = dbcon.cursor() | |
| # realdata is the file you copied from your actual Quod Libet config dir | |
| library = quodlibet.library.init('../realdata') | |
| app.library = library | |
| for song in Query('').filter(app.library): | |
| songDict = {} | |
| whereStr = [] | |
| title = song.get('title', None), | |
| artist = song.get('artist', None), | |
| album = song.get('album', None), | |
| version = song.get('version', None) | |
| if title is not None and title[0] is not None: | |
| songDict['title'] = title[0] | |
| whereStr.append('title=:title') | |
| else: | |
| whereStr.append('title IS NULL') | |
| if artist is not None and artist[0] is not None: | |
| songDict['artist'] = artist[0] | |
| whereStr.append('artist=:artist') | |
| else: | |
| whereStr.append('artist IS NULL') | |
| if album is not None and album[0] is not None: | |
| songDict['album'] = album[0] | |
| whereStr.append('album=:album') | |
| else: | |
| whereStr.append('album IS NULL') | |
| if version is not None: | |
| songDict['version'] = version | |
| whereStr.append('version=:version') | |
| else: | |
| whereStr.append('version IS NULL') | |
| # ugh this is so inefficient, running a query for every song, but well, it works | |
| res = dbcur.execute( | |
| "SELECT playCount, skipCount, added, lastplayed, laststarted FROM songs_merged WHERE " + ' AND '.join( | |
| whereStr), | |
| songDict) | |
| data = res.fetchone() | |
| if data is not None: | |
| song['~#playcount'] = data[0] | |
| song['~#skipcount'] = data[1] | |
| song['~#added'] = data[2] | |
| song['~#lastplayed'] = data[3] | |
| song['~#laststarted'] = data[4] | |
| else: | |
| # for debugging only, set breakpoint to next line | |
| print( | |
| "SELECT playCount, skipCount, added, lastplayed, laststarted FROM songs_merged WHERE " + ' AND '.join( | |
| whereStr)) | |
| app.library.dirty = True | |
| app.library.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment