Project

General

Profile

API call to get channel icon URL

Added by Paul M about 6 years ago

Hi,
I can't find a function in the REST API for getting a channel icon, if available.

It's quite possible I'm not reading it right.

thanks for any ideas,
Paul


Replies (5)

RE: API call to get channel icon URL - Added by Em Smith about 6 years ago

The api/epg/events/grid contains a channelIcon; and the api/channel/grid contains an icon. Those are probably the easiest ways based on your code.

RE: API call to get channel icon URL - Added by Paul M about 6 years ago

thanks for that.

if I click on a row in the TVH EPG, and get the pop-up window with the channe/program info, and then right mouse click on the icon and open in a new screen, then I see a URL like this:
http://myserver:9981/imagecache/4

when I make this API call http://myserver:9981/api/channel/grid?limit=400
the json contains a URL to the external image which is basically the URL from the TVH configuration file called "Channel icon path:"

I had been hoping/expecting the TVH server to maintain a cache of channel images.

thanks

RE: API call to get channel icon URL - Added by Em Smith about 6 years ago

I took a look, try "icon_public_url" instead in the api/channel/grid.

(I don't have imagecache enabled but seems to work).

RE: API call to get channel icon URL - Added by Paul M about 6 years ago

thanks, that does indeed work.

RE: API call to get channel icon URL - Added by r nagtegaal over 2 years ago

#!/usr/bin/env python3
import json
import re
import requests

class TVHeadend:
    def __init__(self, tvheadend_server):
        self.tvheadend_server = f'http://{tvheadend_server}:9981'
        self.regexes = [re.compile("^$"), re.compile("\W"), re.compile("astra \d/\d+\w/\W\w+:\d+\W")]

    def regex_match(self, string):
        if any(regex.match(string) for regex in self.regexes):
            return True
        return False

    def set_channel(self, channel_dict):
        key = channel_dict['uuid']
        name = channel_dict['name']
        icon = channel_dict['icon_public_url']
        icon_url = f'{self.tvheadend_server}/{icon}'
        channel = f'{self.tvheadend_server}/stream/channel/{key}'
        return {'channel': channel, 'name': name, 'icon': icon_url}

    def get_channels(self):
        url = '/api/channel/grid?limit=40000'
        query = '%s%s' % (
            self.tvheadend_server,
            url,
        )
        response = requests.get(query)
        if response.status_code != 200:
            print(f'Caught error retrieving channel list: {response.text}')
            return {}

        data = json.loads(response.text, strict=False)
        channels = [self.set_channel(x) for x in data['entries'] if not self.regex_match(x['name'])]
        return channels

if __name__ == '__main__':
    tvh = TVHeadend('172.16.100.9')
    tvh.get_channels()

You get a result like: [{'channel': <channel url>, 'name': <channel name>, 'icon': <icon url>}, ...]

eg.:

[{'channel': 'http://172.16.100.9:9981/stream/channel/19f23680b439c9e8fae68c78e2a3d714', 'name': '4MEDIATHEK', 'icon': 'http://172.16.100.9:9981/imagecache/1'},
{'channel': 'http://172.16.100.9:9981/stream/channel/9d873b004d669abec05ece42483bb12d', 'name': 'ITV HD', 'icon': 'http://172.16.100.9:9981/imagecache/786'},
{'channel': 'http://172.16.100.9:9981/stream/channel/ad7d4300cb404a0036a55c78fdb83ef7', 'name': 'W', 'icon': 'http://172.16.100.9:9981/imagecache/931'},
{'channel': 'http://172.16.100.9:9981/stream/channel/67b447009878f6c403478f786131a1c5', 'name': 'pearl.tv Shop', 'icon': 'http://172.16.100.9:9981/imagecache/2'}, ...]
    (1-5/5)