

class OriginChannels():

    def __init__(self, fhdhr, origin):
        self.fhdhr = fhdhr
        self.origin = origin

        self.base_api = 'https://localnow.com/api/dsp/live/epg'

    def get_channels(self):

        channel_list = []

        channels_json = self.fhdhr.web.session.get(self.base_api).json()["data"]["channels"]
        for channel_dict in channels_json:

            clean_station_item = {
                                 "name": channel_dict["name"],
                                 "callsign": channel_dict["slug"],
                                 "id": channel_dict["id"],
                                 "thumbnail": channel_dict["logo"],
                                 }
            channel_list.append(clean_station_item)

        return channel_list

    def get_channel_stream(self, chandict, stream_args):
        return None
        channels_json = self.fhdhr.web.session.get(self.base_api).json()
        origin_chandict = self.get_channel_dict(channels_json, "identifier", chandict["origin_id"])
        streamdict = self.get_channel_dict(origin_chandict["streams"], "StreamType", 'website')
        streamurl = streamdict['Url']

        stream_info = {"url": streamurl}

        return stream_info

    def get_channel_dict(self, chanlist, keyfind, valfind):
        return next(item for item in chanlist if item[keyfind] == valfind)
