コード例 #1
0
def get_channels(channel_list):
    html = webrequest.get_url(twitch.stream_objects() %
                              (','.join(channel_list)))
    json_file = json.loads(html)
    streams = []
    for stream in json_file['streams']:
        streamer = [
            stream['channel']['url'],
            stream['channel']['name'] + " - " + stream['channel']['game'],
            stream['channel']['status'], stream['channel']['logo'],
            stream['viewers']
        ]
        streams.append(streamer)
    sorted(streams, key=lambda x: x[4])
    items = []
    if len(streams) == 0:
        items.append(workflow.create_item())
    else:
        for streamer in streams:
            items.append(
                workflow.create_item(arg=streamer[0],
                                     title=streamer[1],
                                     subtitle=streamer[2],
                                     icon=settings.get_image(
                                         streamer[3], streamer[1])))
    workflow.output_items(items)
コード例 #2
0
def search_streams(term):
    html = webrequest.get_url(twitch.search_channels() % term)
    json_file = json.loads(html)
    items = []
    for channel in json_file['channels']:
        items.append(workflow.create_item(
            arg = channel['url'], 
            title = channel['name'], 
            subtitle = channel['game'],
            icon = settings.get_image(channel['logo'], "video_preview_%s" % channel['name'])))
    workflow.output_items(items)
コード例 #3
0
def load_image(image_url, filename, time):
    import os
    filename = filename.replace("/", "").replace("\\", "").replace(":", "").replace("'", "").replace('"', "")
    image_data = webrequest.get_url(image_url)
    image_filename = os.path.join('Images', filename)
    f = open(image_filename, 'wb+')
    f.write(image_data)
    f.close()
    update_image(image_url, filename, time)
    conn.commit()
    return image_filename
コード例 #4
0
def get_top_games():
    html = webrequest.get_url(twitch.top_games())
    json_file = json.loads(html)
    items = []
    for game in json_file['top']:
        game_name = game['game']['name']
        items.append(workflow.create_item(
            arg = game_name, 
            title = game_name, 
            subtitle = "%s Viewers" % game['game']['popularity'],
            icon = settings.get_image(game['game']['box']['small'], game_name)))
    workflow.output_items(items)
コード例 #5
0
def load_followed_channels(user, time):
    html = webrequest.get_url(twitch.followed_channels() % user)
    json_file = json.loads(html)
    channels = []
    for element in json_file['follows']:
        channels.append(element['channel']['name'])
        add_channel(element['channel']['name'])
    # update cache
    update_setting('followed_channels', '@#@#@'.join(channels))
    update_setting('followed_cache_time', time)
    conn.commit()
    return channels
コード例 #6
0
def load_followed_channels(user, time):
    html = webrequest.get_url(twitch.followed_channels() % user)
    json_file = json.loads(html)
    channels = []
    for element in json_file['follows']:
        channels.append(element['channel']['name'])
        add_channel(element['channel']['name'])
    # update cache
    update_setting('followed_channels', '@#@#@'.join(channels))
    update_setting('followed_cache_time', time)
    conn.commit()
    return channels
コード例 #7
0
def search_games(search):
    html = webrequest.get_url(twitch.search_games() % search)
    json_file = json.loads(html)
    items = []
    for game in json_file['games']:
        game_name = game['name']
        items.append(
            workflow.create_item(arg=game_name,
                                 title=game_name,
                                 subtitle="%s Viewers" % game['popularity'],
                                 icon=settings.get_image(
                                     game['box']['small'], game_name)))
    workflow.output_items(items)
コード例 #8
0
def search_streams(term):
    html = webrequest.get_url(twitch.search_channels() % term)
    json_file = json.loads(html)
    items = []
    for channel in json_file['channels']:
        items.append(
            workflow.create_item(arg=channel['url'],
                                 title=channel['name'],
                                 subtitle=channel['game'],
                                 icon=settings.get_image(
                                     channel['logo'],
                                     "video_preview_%s" % channel['name'])))
    workflow.output_items(items)
コード例 #9
0
def load_image(image_url, filename, time):
    import os
    filename = filename.replace("/", "").replace("\\",
                                                 "").replace(":", "").replace(
                                                     "'", "").replace('"', "")
    image_data = webrequest.get_url(image_url)
    image_filename = os.path.join('Images', filename)
    f = open(image_filename, 'wb+')
    f.write(image_data)
    f.close()
    update_image(image_url, filename, time)
    conn.commit()
    return image_filename
コード例 #10
0
def get_streams_by_game(gamename):
    html = webrequest.get_url(twitch.streams_per_game() % gamename)
    json_file = json.loads(html)
    items = []
    for stream in json_file['streams']:
        icon = None
        if user_settings['enable_previews'] == 'false': icon = settings.get_image(stream['channel']['logo'], stream['channel']['name'])
        else: icon = settings.get_image(stream['preview']['small'], "video_preview_%s" % stream['channel']['name'])
        items.append(workflow.create_item(
            arg = stream['channel']['url'], 
            title = "%s (%s viewers)" % (stream['channel']['name'], stream['viewers']), 
            subtitle = stream['channel']['status'],
            icon = icon))
    workflow.output_items(items)
コード例 #11
0
def get_videos(channelname):
    html = webrequest.get_url(twitch.videos() % channelname)
    json_file = json.loads(html)
    items = []
    index = 0
    for video in json_file['videos']:
        filename = 'video_preview_%s_%d' % (video['channel']['name'], index)
        icon = None
        if user_settings['enable_previews'] == 'false': icon = 'Images/%s' % channelname
        else: icon = settings.get_image(video['preview'], filename)
        items.append(workflow.create_item(
            arg = video['url'], 
            title = video['title'], 
            subtitle = "%s (%s views)" % (video['created_at'].split('T')[0], video['views']),
            icon = icon))
        index += 1
    workflow.output_items(items)
コード例 #12
0
def get_channels(channel_list):
    html = webrequest.get_url(twitch.stream_objects() % (','.join(channel_list)))
    json_file = json.loads(html)
    streams = []
    for stream in json_file['streams']:
        streamer = [stream['channel']['url'], stream['channel']['name'] + " - " + stream['channel']['game'], stream['channel']['status'], stream['channel']['logo'], stream['viewers']]
        streams.append(streamer)
    sorted(streams, key=lambda x: x[4])
    items = []
    if len(streams) == 0:
        items.append(workflow.create_item())
    else:
        for streamer in streams:
            items.append(workflow.create_item(
                arg = streamer[0], 
                title = streamer[1], 
                subtitle = streamer[2],
                icon = settings.get_image(streamer[3], streamer[1])))
    workflow.output_items(items)
コード例 #13
0
def get_videos(channelname):
    html = webrequest.get_url(twitch.videos() % channelname)
    json_file = json.loads(html)
    items = []
    index = 0
    for video in json_file['videos']:
        filename = 'video_preview_%s_%d' % (video['channel']['name'], index)
        icon = None
        if user_settings['enable_previews'] == 'false':
            icon = 'Images/%s' % channelname
        else:
            icon = settings.get_image(video['preview'], filename)
        items.append(
            workflow.create_item(
                arg=video['url'],
                title=video['title'],
                subtitle="%s (%s views)" %
                (video['created_at'].split('T')[0], video['views']),
                icon=icon))
        index += 1
    workflow.output_items(items)
コード例 #14
0
def get_streams_by_game(gamename):
    html = webrequest.get_url(twitch.streams_per_game() % gamename)
    json_file = json.loads(html)
    items = []
    for stream in json_file['streams']:
        icon = None
        if user_settings['enable_previews'] == 'false':
            icon = settings.get_image(stream['channel']['logo'],
                                      stream['channel']['name'])
        else:
            icon = settings.get_image(
                stream['preview']['small'],
                "video_preview_%s" % stream['channel']['name'])
        items.append(
            workflow.create_item(
                arg=stream['channel']['url'],
                title="%s (%s viewers)" %
                (stream['channel']['name'], stream['viewers']),
                subtitle=stream['channel']['status'],
                icon=icon))
    workflow.output_items(items)