Playlists generation for AudioGalaxy

I use audio galaxy and thought it would be nice to create M3U playlists for all my music folders. The result is this simple Python script:

import os
import string

AUDIOGALAXY_PLAYLIST_DIR = r"C:UsersyanMusicAudiogalaxy Playlists"
MUSIC_ROOT_FOLDER = "D:\Music\"
MUSIC_EXTENSIONS = [".mp3",]
PLAYLIST_EXT = ".m3u"

class Playlist:
    def __init__(self, dir):
        self.__name = string.replace(string.split(dir, MUSIC_ROOT_FOLDER, -1)[1], os.path.sep, "_")
        if not self.__name:
            self.__name = "Songs in root"
        self.__songs = []
        for file in [file for file in os.listdir(dir) if not file in [".", ".."]
                     and os.path.splitext(file)[1] in MUSIC_EXTENSIONS]:
            fullname = os.path.join(dir, file)
            if not os.path.isdir(fullname):
                self.__songs.append(fullname)

    def printme(self):
        print "%s - %d songs" % (self.__name, self.countSongs())
        #for song in self.__songs:
        #    print "t%s" % (song,)

    def countSongs(self):
        return len(self.__songs)    

    def save(self, dir):
        if 0 == self.countSongs():
            return
        file = open(os.path.join(dir, self.__name + PLAYLIST_EXT), "w")
        file.write('#EXTM3Un')
        for song in self.__songs:
            file.write(song + "n")
        file.close()

def handle_dir(target_dir, dirname, fnames):
    p = Playlist(dirname)
    p.printme()
    p.save(target_dir)

def main():
    os.path.walk(MUSIC_ROOT_FOLDER, handle_dir, AUDIOGALAXY_PLAYLIST_DIR)

if __name__ == '__main__':
    main()

Just set MUSIC_ROOT_FOLDER to your music files location and AUDIOGALAXY_PLAYLIST_DIR accordingly and run the script.

3 thoughts on “Playlists generation for AudioGalaxy

  1. Runs fine. I think audiogalaxy is broken when it comes to importing playlists though. No matter what I do the new playlist doesn’t show up. The only true way to create a playlist is manually drag and drop using the audiogalaxy web ui.

  2. It seems that sometimes it takes time for the playlist to be updated with the songs in the directory. And it also seems to depend on the mp3 format. Some MP3s I have weren’t recognized by Audio Galaxy and were not added to the playlist.

Leave a Reply

Your email address will not be published. Required fields are marked *