<gh_stars>1-10
import justrok
from justrok import util

class PlaylistItem(object):
    PROPERTIES = [("track", "Track"), ("artist", "Artist"), ("album", "Album"), ("title", "Title"), ("length", "Length"), ("disc", "Disc"), ("date", "Date"), ("comment", "Comment")]

    def __init__(self, path):
        self.path = path
        self._tags = dict((identifier, None) for (identifier, title) in PlaylistItem.PROPERTIES)
        self.position = None
        self.queue_position = None
        self.already_played = False
        self.needs_tag_reader = True

    @staticmethod
    def get_property_title(property_identifier):
        for (identifier, title) in PlaylistItem.PROPERTIES:
            if identifier == property_identifier:
                return title

    @staticmethod
    def get_number_of_properties():
        return len(PlaylistItem.PROPERTIES)

    @staticmethod
    def get_property_identifier_from_index(index):
        return PlaylistItem.PROPERTIES[index][0]

    @staticmethod
    def get_property_title_from_index(index):
        return PlaylistItem.PROPERTIES[index][1]

    def tags(self):
        return self._tags.copy()

    def tag_text(self, tag):
        value = self._tags[tag]
        if tag == 'length' and value is not None:
            return util.fmt_seconds(value)
        else:
            return value

    def tag_by_index(self, index):
        return self.tag_text(self.PROPERTIES[index][0])

    def update_tags(self, tags):
        for tag, value in tags.items():
            if tag not in self._tags:
                justrok.logger.warn('unknown tag %s', tag)
                continue
            self._tags[tag] = value

import justrok
from justrok import util

class PlaylistItem(object):
    PROPERTIES = [("track", "Track"), ("artist", "Artist"), ("album", "Album"), ("title", "Title"), ("length", "Length"), ("disc", "Disc"), ("date", "Date"), ("comment", "Comment")]

    def __init__(self, path):
        self.path = path
        self._tags = dict((identifier, None) for (identifier, title) in PlaylistItem.PROPERTIES)
        self.position = None
        self.queue_position = None
        self.already_played = False
        self.needs_tag_reader = True

    @staticmethod
    def get_property_title(property_identifier):
        for (identifier, title) in PlaylistItem.PROPERTIES:
            if identifier == property_identifier:
                return title

    @staticmethod
    def get_number_of_properties():
        return len(PlaylistItem.PROPERTIES)

    @staticmethod
    def get_property_identifier_from_index(index):
        return PlaylistItem.PROPERTIES[index][0]

    @staticmethod
    def get_property_title_from_index(index):
        return PlaylistItem.PROPERTIES[index][1]

    def tags(self):
        return self._tags.copy()

    def tag_text(self, tag):
        value = self._tags[tag]
        if tag == 'length' and value is not None:
            return util.fmt_seconds(value)
        else:
            return value

    def tag_by_index(self, index):
        return self.tag_text(self.PROPERTIES[index][0])

    def update_tags(self, tags):
        for tag, value in tags.items():
            if tag not in self._tags:
                justrok.logger.warn('unknown tag %s', tag)
                continue
            self._tags[tag] = value