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
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 log_traceback(exc, exc_traceback): tb_lines = [ line.rstrip('\n') for line in traceback.format_exception( exc.__class__, exc, exc_traceback) ] for tb_line in tb_lines: log_err('Traceback: %s' % (c.to_string(tb_line)))
def request_token(self, callback=None): sig_req_url = self.__get_sig_url("request_token_base_url", has_oauth_token=False) try: result = httpget(sig_req_url) msg = '' if result.status_code == 200: msg = result.json() for k in (u'oauth_token', u'oauth_token_secret', u'oauth_callback_confirmed'): if msg.has_key(k): v = msg.get(k) setattr(self, common.to_string(k), common.safe_value(v)) elif result.status_code == 500: raise RequestException("kuaipan internal server error!") return result except RequestException as reqex: errmsg = "get init token failed!, err message is:%s" % str(reqex) print(errmsg) sys.exit(1)
next_time, next_time_sec = next_time_() if next_time != _next_time_: set_setting('next_time', next_time) _next_time_ = next_time log_not( 'Change of settings next time - next start: %s' % _next_time_) change_report = True if login_error or start_error or param_error: if not error_report: error_report = True info_dialog(_lang_(30048)) _log_wrn( 'Unfinished settings - login : %s, start : %s, param : %s' % (c.to_string(login_error), c.to_string(start_error), c.to_string(param_error))) _log_dbg( 'Service running: short cycle (Unfinished settings) - time: %s' % (time.strftime('%Y-%m-%d %H:%M:%S'))) continue if error_report: log_not('Finished settings') if start: start = False if not _next_time_ or _start_enable_: next_time_sec = 0 log_not(
def time_string(self): if self.exclusive: return to_string(self.end_time) return to_time_string(self.end_time)