Fix issues in MPD Python script
This commit is contained in:
parent
948e5ebe45
commit
f60252537a
@ -8,6 +8,7 @@ _Note_: `blissify` should be available in your `$PATH`.
|
|||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import subprocess
|
import subprocess
|
||||||
@ -27,6 +28,7 @@ def init_connection():
|
|||||||
# Get MPD connection settings
|
# Get MPD connection settings
|
||||||
try:
|
try:
|
||||||
mpd_host = os.environ["MPD_HOST"]
|
mpd_host = os.environ["MPD_HOST"]
|
||||||
|
if "@" in mpd_host:
|
||||||
mpd_password, mpd_host = mpd_host.split("@")
|
mpd_password, mpd_host = mpd_host.split("@")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
mpd_host = "localhost"
|
mpd_host = "localhost"
|
||||||
@ -36,7 +38,7 @@ def init_connection():
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
mpd_port = 6600
|
mpd_port = 6600
|
||||||
|
|
||||||
# Connect to MPD²
|
# Connect to MPD
|
||||||
client = MPDClient()
|
client = MPDClient()
|
||||||
client.connect(mpd_host, mpd_port)
|
client.connect(mpd_host, mpd_port)
|
||||||
if mpd_password is not None:
|
if mpd_password is not None:
|
||||||
@ -59,12 +61,16 @@ def full_rescan(mpd_root):
|
|||||||
# Connect to db
|
# Connect to db
|
||||||
db_path = os.path.join(_BLISSIFY_DATA_HOME, "db.sqlite3")
|
db_path = os.path.join(_BLISSIFY_DATA_HOME, "db.sqlite3")
|
||||||
logging.debug("Using DB path: %s." % (db_path,))
|
logging.debug("Using DB path: %s." % (db_path,))
|
||||||
|
try:
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
conn.execute('pragma foreign_keys=ON')
|
conn.execute('pragma foreign_keys=ON')
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
# Purge db
|
# Purge db
|
||||||
cur.executescript("BEGIN TRANSACTION; DELETE FROM distances; DELETE FROM songs; DELETE FROM errors; COMMIT;")
|
cur.executescript("BEGIN TRANSACTION; DELETE FROM distances; DELETE FROM songs; DELETE FROM errors; COMMIT;")
|
||||||
|
conn.close()
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
pass
|
||||||
|
|
||||||
client = init_connection()
|
client = init_connection()
|
||||||
# Get all songs from MPD and Blissify them
|
# Get all songs from MPD and Blissify them
|
||||||
|
Loading…
Reference in New Issue
Block a user