#!./bin/python3

import os

from handler.filelist import FileListHandler

class M3UHandler(FileListHandler):

    def getPlaylistItems(self, item):
        path = item["path"]
        items = []

        with open(path) as f:
            for line in f:
                item_path = str(line).strip()
                if not item_path.startswith("#"):
                    items.append({
                        "name" : self.toDisplayName(os.path.basename(item_path)),
                        "path" : os.path.join(os.path.dirname(path), item_path)
                    })

        return items
