from enum import Enum

class TrackType(Enum):

    VIDEO       = {'label': 'video', 'index': 1}
    AUDIO       = {'label': 'audio', 'index': 2}
    SUBTITLE    = {'label': 'subtitle', 'index': 3}
    ATTACHMENT  = {'label': 'attachment', 'index': 4}

    UNKNOWN    = {'label': 'unknown', 'index': 0}


    def label(self):
        """Returns the stream type as string"""
        return str(self.value['label'])

    def indicator(self):
        """Returns the stream type as single letter"""
        return self.label()[0]

    def index(self):
        """Returns the stream type index"""
        return int(self.value['index'])

    @staticmethod
    def fromLabel(label : str):
        tlist = [t for t in TrackType if t.value['label'] == str(label)]
        if tlist:
            return tlist[0]
        else:
            return TrackType.UNKNOWN

    @staticmethod
    def fromIndex(index : int):
        tlist = [t for t in TrackType if t.value['index'] == int(index)]
        if tlist:
            return tlist[0]
        else:
            return TrackType.UNKNOWN
