User:Fstirlitz/script for ncmpc to pull lyrics from gmpc database

From ArchWiki

you will need python-apsw, python-xdg. put this file in /usr/share/ncmpc/lyrics, preferably under the name 11-gmpc.py:

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import os
import apsw
import xdg.BaseDirectory

artist = sys.argv[1]
title = sys.argv[2]

db = apsw.Connection(
	'{}/gmpc/metadata/covers.sql'.format(xdg.BaseDirectory.xdg_cache_home),
	flags=apsw.SQLITE_OPEN_READONLY
)

cursor = db.cursor()
cursor.execute("""
	SELECT content, contenttype
	FROM metadata
	WHERE
		key_a = ? AND
		key_b = ? AND
		type = 16
	""", (artist, title))

for row in cursor:
	if row[1] == 1:
		print(open(row[0], 'r').read())
	elif row[1] == 2:
		print(row[0])
	else:
		raise Exception('contenttype %u not recognized' % (row[1]))
	sys.exit(0)
	
sys.exit(69)