def getEvent(eventID):
    event = dbops.getEvent(eventID)
    log('Listing video files for event: %s' % event[1])
    for x in library.loadLibrary():
        if event[0] == x['ID']:
            thumbPath = os.path.join(__thumbDir__, '%s-poster.jpg' % x['ID'])
            if not xbmcvfs.exists(thumbPath):
                thumbPath = os.path.join(__promotionDir__, '%s-poster.jpg' % event[2].replace(' ', ''))
            fanartPath = os.path.join(__thumbDir__, '%s-fanart.jpg' % x['ID'])
            if not xbmcvfs.exists(fanartPath):
                fanartPath = os.path.join(__promotionDir__, '%s-fanart.jpg' % event[2].replace(' ', ''))
            outline = '%s: %s, %s' % (event[3], event[4], event[5])
            try:
                description = open(os.path.join(__thumbDir__, '%s-description.txt' % event[0])).read()
            except IOError:
                description = outline
            fighterList = dbops.getFightersByEvent(eventID)
            description = description + '\n\n' + '\n'.join(fighterList)
            fileList = getVideoList(x['path'])
            if len(fileList) == 1:
                li=xbmcgui.ListItem(label = event[1], iconImage = thumbPath, thumbnailImage = thumbPath)
                li.setInfo( type="Video", infoLabels={ "title": event[1], "plot": description, "cast": fighterList, "genre": event[2], "date": event[3], "premiered": event[3], "tvshowtitle": event[2]} )
                xbmc.Player().play(fileList[0]['path'], li)
                sys.exit(0)
            else:
                for vidFile in fileList:
                    addLink(linkName = vidFile['title'], plotoutline = outline, plot = description, url = vidFile['path'], thumbPath = thumbPath, fanartPath = fanartPath, genre = event[2])
def getEventsByOrganisation(organisation):
    log('Listing all events for: %s' % organisation)
    dbList = dbops.getEventsByPromotion(organisation)
    totalEvents = len(dbList)
    for event in dbList:
        for x in library.loadLibrary():
            if event[0] == x['ID']:
                fightList = dbops.getFightersByEvent(event[0])
                addEvent(event[0], event[1], event[2], event[3], event[4], event[5], fightList, totalEvents)
def getEventsByFighter(fighterID):
    log('Listing all events for: %s' % fighterID)
    dbList = dbops.getEventsByFighter(fighterID)
    totalEvents = len(dbList)
    for event in dbList:
        for x in library.loadLibrary():
            if event[0] == x['ID']:
                fightList = dbops.getFightersByEvent(event[0])
                addEvent(event[0], event[1], event[2], event[3], event[4], event[5], fightList, totalEvents)
def allEvents():
    log('Browsing: All events')
    dbList = dbops.getAllEvents()
    totalEvents = len(dbList)
    for event in dbList:
        for x in library.loadLibrary():
            if event[0] == x['ID']:
                fightList = dbops.getFightersByEvent(event[0])
                addEvent(event[0], event[1], event[2], event[3], event[4], event[5], fightList, totalEvents)
def searchAll():
    log('Searching MMA Library')
    searchStr = getUserInput(title = "Search MMA Library")
    if searchStr:
        dbList = dbops.searchEvents(searchStr)
        totalEvents = len(dbList)
        dbList2 = dbops.searchFighters(searchStr)
        totalFighters = len(dbList2)
        totalListItems = totalEvents + totalFighters
        for event in dbList:
            for x in library.loadLibrary():
                if event[0] == x['ID']:
                    fightList = dbops.getFightersByEvent(event[0])
                    addEvent(event[0], event[1], event[2], event[3], event[4], event[5], fightList, totalListItems)
        for fighter in dbList2:
            addFighter(fighter[0], fighter[1], fighter[2], fighter[3], fighter[4], fighter[5], fighter[6], fighter[7], fighter[8], fighter[10], totalListItems, fighter[9])