Music Player Daemon Community Wiki

522pages on
this wiki
Add New Page
Talk0 Share
  • Description: This Python script outputs your MPD collection in CSV (comma-separated values) format (the default separator is a tab character, not a comma). You can output this to a file, which you can then further process with e.g. Calc. MPD should be running in order for this script to function. Run it without arguments to display the default tags for each file, or specify the tags you want on the command line (like this: python artist album). To write to a file, run as follows:
    python > collection.csv
  • Maintainer(s): Frank Mulder < frankmulder2003 AT yahoo DOT com >
import mpd 
import sys 
client = mpd.MPDClient()           # create client object 
client.connect("localhost", 6600)  # connect to localhost:6600 
def take_first_if_list(element): 
    # Takes the first element if the argument is a list; otherwise, it returns the argument itself. This is needed for tags which contain multiple fields. 
    if isinstance(element, list): 
        return element[0] 
        return element 
# The default tags to be displayed for each file 
tags_to_display = ['artist', 'album', 'title', 'genre', 'file'] 
# If arguments have been given, use them as the tags to be displayed 
args = sys.argv[1:] 
if len(args) > 0: 
    tags_to_display = args 
for song in client.listallinfo(): 
    if 'file' in song: 
        for tag in tags_to_display: 
            # Print the given tag, or a default string if the tag does not exist 
            print take_first_if_list(song.setdefault(tag, 'empty')), 
            print separator, 
        # Print a newline after each song 
client.close()                     # send the close command 
client.disconnect()                # disconnect from the server

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.