def channel_playlist():
    channels, _code = _fetch_channels()
    if not channels:
        return _code, -1, -1
    channels_sorted = sorted(channels.values(), key=lambda _channel: _channel.weight)
    if cfg.channel_group == 1:
        group = c.default_group_name
    else:
        group = cfg.channel_group_name
    if cfg.my_script == 1:
        streamer = c.pipe + os.path.join(cfg.playlist_path, cfg.my_script_name)
    else:
        streamer = c.pipe + os.path.join(cfg.playlist_path, cfg.playlist_streamer)
    playlist_src = '#EXTM3U\n'
    playlist_dst = '#EXTM3U\n'
    _num = 0
    _err = 0
    for channel in channels_sorted:
        try:
            _log("Adding: " + c.to_string(channel.name))
            playlist_src += '#EXTINF:-1, %s\n%s\n' % (c.to_string(channel.name), c.to_string(channel.url()))
            playlist_dst += c.build_channel_lines(channel, cfg.channel_logo ,_logo_path_file(channel.name), streamer, group, cfg.playlist_type, cfg.channel_epg_name, cfg.channel_epg_id, cfg.channel_group)
            _num += 1
        except ChannelIsNotBroadcastingError:
            _err += 1
            _log("... Not broadcasting. Skipped.")
        except AuthenticationError:
            return c.authent_error, 0, 0
        except TooManyDevicesError:
            return c.toomany_error, 0, 0
    c.write_file(playlist_src, os.path.join(cfg.playlist_path, cfg.playlist_src), _log)
    c.write_file(playlist_dst, os.path.join(cfg.playlist_path, cfg.playlist_dst), _log)
    return 'OK', _num, _err
示例#2
0
def channel_playlist():
    global _channel_group_, _channel_groupname_, _myscript_, _myscript_name_, _channel_logo_, \
        _playlist_type_, _channel_epgname_, _channel_epgid_, _ffmpeg_, _no_error_
    channels, _code = _fetch_channels()
    if not channels:
        return _code, -1, -1

    channels_sorted = sorted(channels.values(),
                             key=lambda _channel: _channel.weight)
    if _channel_group_ == 1:
        group = c.default_group_name
    else:
        group = _channel_groupname_

    if _myscript_ == 1:
        streamer = c.pipe + os.path.join(_playlist_path_, _myscript_name_)
    else:
        streamer = c.pipe + os.path.join(_playlist_path_, _playlist_streamer_)

    playlist_src = '#EXTM3U\n'
    playlist_dst = '#EXTM3U\n'
    _num = 0
    _err = 0
    for channel in channels_sorted:
        try:
            log_not("Adding: " + channel.name)
            playlist_src += '#EXTINF:-1, %s\n%s\n' % (c.to_string(
                channel.name), c.to_string(channel.url()))
            playlist_dst += c.build_channel_lines(
                channel, _channel_logo_, _logo_path_file(channel.name),
                streamer, group, _playlist_type_, _channel_epgname_,
                _channel_epgid_, _channel_group_)
            _num += 1
        except ChannelIsNotBroadcastingError:
            log_not("... Not broadcasting. Skipped.")
            _err += 1
        except AuthenticationError:
            return _authent_error_, 0, 0
        except TooManyDevicesError:
            return _toomany_error_, 0, 0
        except NoPlaylistUrlsError:
            log_not("... No playlist URL provided. Skipped.")
            _err += 1
    c.write_file(playlist_src,
                 xbmc.translatePath(os.path.join(_profile_, _playlist_src_)),
                 _log_dbg)
    c.write_file(playlist_dst,
                 xbmc.translatePath(os.path.join(_profile_, _playlist_dst_)),
                 _log_dbg)
    if _playlist_type_ == 3:
        c.write_streamer(
            xbmc.translatePath(os.path.join(_profile_, _playlist_streamer_)),
            xbmc.translatePath(os.path.join(_profile_, _playlist_src_)),
            _ffmpeg_, _log_dbg)
    set_setting('last_time', time.strftime('%Y-%m-%d %H:%M'))
    set_setting('last_downloaded', c.to_string(_num))
    set_setting('last_skipped', c.to_string(_err))
    return _no_error_, _num, _err
def channel_playlist():
    global config
    channels, _code = _fetch_channels()
    if not channels:
        return _code, -1, -1, -1
    channels_sorted = sorted(list(channels.values()),
                             key=lambda _channel: _channel.weight)
    if config.getint('Playlist', 'channel_group') == 1:
        group = c.default_group_name
    else:
        group = config.get('Playlist', 'channel_group_name')
    if config.getboolean('Common', 'my_script'):
        streamer = c.pipe + os.path.join(
            config.get('Playlist', 'playlist_path'),
            config.get('Common', 'my_script_name'))
    else:
        streamer = c.pipe + os.path.join(
            config.get('Playlist', 'playlist_path'),
            config.get('Common', 'playlist_streamer'))
    playlist_src = '#EXTM3U\n'
    playlist_dst = '#EXTM3U\n'
    _num = 0
    _err = 0
    _cached = 0
    if len(channels_sorted) == 0:
        _log("Failed to download channels!")
        return c.nochannels_error, 0, 0, 0
    for channel in channels_sorted:
        try:
            _log("Adding: %s..." % channel.name)
            playlist_src += '#EXTINF:-1, %s\n%s\n' % (channel.name,
                                                      channel.url())
            playlist_dst += c.build_channel_lines(
                channel, config.getint('Playlist', 'channel_logo'),
                _logo_path_file(channel.name), streamer, group,
                config.getint('Playlist', 'playlist_type'),
                config.getint('Playlist', 'channel_epg_name'),
                config.getint('Playlist', 'channel_epg_id'),
                config.getint('Playlist', 'channel_group'))
            if config.getboolean('Playlist', 'cache_playlists'):
                if c.cache_playlist(channel.url(),
                                    config.get('Playlist', 'playlist_path'),
                                    _log):
                    _cached += 1
            _num += 1
        except ChannelIsNotBroadcastingError:
            _err += 1
            _log("... Not broadcasting. Skipped.")
        except AuthenticationError:
            return c.authent_error, 0, 0, 0
        except TooManyDevicesError:
            return c.toomany_error, 0, 0, 0
        except NoPlaylistUrlsError:
            _log("... No playlist URL provided. Skipped.")
            _err += 1
    c.write_file(
        playlist_src,
        os.path.join(config.get('Playlist', 'playlist_path'),
                     config.get('Playlist', 'playlist_src')), _log)
    c.write_file(
        playlist_dst,
        os.path.join(config.get('Playlist', 'playlist_path'),
                     config.get('Playlist', 'playlist_dst')), _log)
    return 'OK', _num, _err, _cached