--- unity_audacious_daemon.py 2016-05-15 23:27:13.460604000 +0200 +++ unity_audacious_daemon.py 2016-05-17 22:09:03.720889305 +0200 @@ -18,10 +18,10 @@ from gi.repository import Unity import gettext import urllib.parse -import dbus import hashlib import unicodedata import os +import subprocess APP_NAME = 'unity-scope-audacious' LOCAL_PATH = '/usr/share/locale/' @@ -96,41 +96,45 @@ global tracks tracks = [] for collection in os.listdir(AUDACIOUS_DBFILE): - dbfile = '%s/%s' % (AUDACIOUS_DBFILE, collection) - database = open(dbfile, "r") - database = database.read() - if not database.startswith("title:Library"): - records = database[14:] - records = records.split("uri=") - else: - records = "" - - for record in records: - track = [] - lines = record.split("\n") - uri = "" - year = 0 - for line in lines: - line = urllib.parse.unquote(line) - if line.startswith("file://"): - uri = line[7:] - if line.startswith("title="): - title = line[6:] - if line.startswith("artist="): - artist = line[7:] - if line.startswith("album="): - album = line[6:] - if line.startswith("year="): - year = line[5:] - if line.startswith("genre="): - genre = line[6:] - if line.startswith("track-number="): - tracknumber = line[13:] - if line.startswith("length="): - length = line[7:] - track = [title, uri, artist, album, "taglib/mp3", int(year), genre, int(tracknumber), int(length) / 1000] - tracks.append(track) - tracks.sort(key=lambda track: track[7]) + if collection.endswith(".audpl"): + dbfile = str(AUDACIOUS_DBFILE + collection) + database = open(dbfile, "r") + data = database.read() + database.close() + records = [] + if data: + if data.startswith("title"): + records = data.split("uri=") + if records: + del records[0] # ignore title=Library + if records: + for record in records: + track = [] + lines = record.split("\n") + uri = "" + year = 0 + for line in lines: + line = urllib.parse.unquote(line) + if line.startswith("file://"): + uri = line[7:] + if line.startswith("title="): + title = line[6:] + if line.startswith("artist="): + artist = line[7:] + if line.startswith("album="): + album = line[6:] + if line.startswith("year="): + year = line[5:] + if line.startswith("genre="): + genre = line[6:] + if line.startswith("track-number="): + tracknumber = line[13:] + if line.startswith("length="): + length = line[7:] + track = [title, uri, artist, album, "taglib/mp3", int(year), genre, int(tracknumber), int(length) / 1000] + tracks.append(track) + if tracks: + tracks.sort(key=lambda track: track[7]) return tracks @@ -355,6 +359,7 @@ album = result.metadata['album'].get_string() artist = result.metadata['artist'].get_string() global tracks + cmd = [] if id == 'show': if result.uri.startswith("album://"): for track in tracks: @@ -363,19 +368,20 @@ continue else: filename = result.uri - dirname = os.path.dirname(filename) - os.system("xdg-open '%s'" % str(dirname)) + if filename: + dirname = os.path.dirname(filename) + cmd = ["xdg-open", str(dirname)] else: - albumtracks = '' + cmd = ["audacious", "-E"] if result.uri.startswith('album://'): for track in tracks: if album in track[3] and artist in track[2]: - albumtracks = albumtracks + ' \'%s\'' % (track[1]) + cmd.append(track[1]) else: - albumtracks = '\'%s\'' % result.uri - print(albumtracks) - os.system('audacious -E %s' % albumtracks) - + cmd.append(result.uri) + if cmd: + p = subprocess.Popen(cmd) + p.communicate() return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri=None)