def listChannels():
    modelChannels = ShahidUtils.getChannelList()
    for channel in sorted(modelChannels, key=lambda c: c.name):
        params = "channelID={0}".format(channel.id)
        addLink(channel.name, MODE_LIST_PROGRAMS, params, channel.image_thumb, channel.image_fanart)

    xbmcplugin.endOfDirectory(plugin)
def listVideos(programID, videoType):
    paramsPattern = "programID={0}&videoType={1}&clipID={2}"
    list = ShahidUtils.getVideoList(programID, videoType)

    for item in filter(lambda x: x.coming_soon == 0 , list):
        addLink(item.name, MODE_LIST_STREAMS, paramsPattern.format(programID, videoType, item.id, item.name), item.image_thumb, isFolder=False)

    xbmcplugin.endOfDirectory(plugin)
def listChannels():
    modelChannels = ShahidUtils.getChannelList()
    for channel in sorted(modelChannels, key=lambda c: c.name):
        params = "channelID={0}".format(channel.id)
        addLink(channel.name, MODE_LIST_PROGRAMS, params, channel.image_thumb,
                channel.image_fanart)

    xbmcplugin.endOfDirectory(plugin)
def listVideos(programID, videoType):
    paramsPattern = "programID={0}&videoType={1}&clipID={2}"
    list = ShahidUtils.getVideoList(programID, videoType)

    for item in filter(lambda x: x.coming_soon == 0, list):
        addLink(item.name,
                MODE_LIST_STREAMS,
                paramsPattern.format(programID, videoType, item.id, item.name),
                item.image_thumb,
                isFolder=False)

    xbmcplugin.endOfDirectory(plugin)
def listStreams(programID, clipID):
    paramsPattern = "playUrl={0}"
    streamList = ShahidUtils.getPlayStreamOptions(programID, clipID)

    # If only one stream is returned, just simply play it by default for user
    if len(streamList) == 1:
        url = urllib.quote_plus(streamList[0].url)
        return playVideo(url)

    # Many options are returned, list them to our dear user
    else:
        for item in streamList:
            url = urllib.quote_plus(item.url)
            addLink(item.title, MODE_PLAY_VIDEO, paramsPattern.format(url), None, isFolder=False)

        xbmcplugin.endOfDirectory(plugin)
def listPrograms(channelID):
    modelPrograms = ShahidUtils.getProgramList(channelID)

    for program in sorted(modelPrograms, key=lambda p: p.name):
        params = "programID={0}&episodesCount={1}&clipsCount={2}".format(program.id, str(program.episode_count), str(program.clip_count))

        # Append videoType if possible
        if program.episode_count > 0 and program.clip_count == 0:
            params += "&videoType=%s" % "episodes"

        if program.episode_count == 0 and program.clip_count > 0:
            params += "&videoType=%s" % "clips"

        addLink(program.name, MODE_LIST_VIDEOS, params, program.image_thumb, program.image_fanart)

    xbmcplugin.endOfDirectory(plugin)
def listPrograms(channelID):
    modelPrograms = ShahidUtils.getProgramList(channelID)

    for program in sorted(modelPrograms, key=lambda p: p.name):
        params = "programID={0}&episodesCount={1}&clipsCount={2}".format(
            program.id, str(program.episode_count), str(program.clip_count))

        # Append videoType if possible
        if program.episode_count > 0 and program.clip_count == 0:
            params += "&videoType=%s" % "episodes"

        if program.episode_count == 0 and program.clip_count > 0:
            params += "&videoType=%s" % "clips"

        addLink(program.name, MODE_LIST_VIDEOS, params, program.image_thumb,
                program.image_fanart)

    xbmcplugin.endOfDirectory(plugin)
def listStreams(programID, clipID):
    paramsPattern = "playUrl={0}"
    streamList = ShahidUtils.getPlayStreamOptions(programID, clipID)

    # If only one stream is returned, just simply play it by default for user
    if len(streamList) == 1:
        url = urllib.quote_plus(streamList[0].url)
        return playVideo(url)

    # Many options are returned, list them to our dear user
    else:
        for item in streamList:
            url = urllib.quote_plus(item.url)
            addLink(item.title,
                    MODE_PLAY_VIDEO,
                    paramsPattern.format(url),
                    None,
                    isFolder=False)

        xbmcplugin.endOfDirectory(plugin)
import sys
import urllib
import xbmcplugin
import xbmcgui
import xbmcaddon

import ShahidUtils

plugin = int(sys.argv[1])
settings = xbmcaddon.Addon(id='plugin.video.shahid.net')
language = settings.getLocalizedString
pluginPath = settings.getAddonInfo('path')

ShahidUtils = ShahidUtils.ShahidUtils()

# Setting constants
MODE_LIST_CHANNELS = 1
MODE_LIST_PROGRAMS = 2
MODE_LIST_VIDEOS = 3
MODE_PLAY_VIDEO = 4
MODE_LIST_STREAMS = 5


def getRootCategories():
    addLink("Channels", MODE_LIST_CHANNELS)
    #addLink("Programs", MODE_LIST_CATEGORY_CHANNELS)
    #addLink("Episodes", MODE_LIST_CATEGORY_CHANNELS)
    #addLink("Clips",    MODE_LIST_CATEGORY_CHANNELS)
    xbmcplugin.endOfDirectory(plugin)