def __init__(self, filename, config, list_streams=False, init_stream_list=None):
global TITLE_STRING<EOL>self.db_was_read = False<EOL>try:<EOL><INDENT>db_dir = os.path.dirname(filename)<EOL>if not os.path.exists(db_dir):<EOL><INDENT>os.makedirs(db_dir)<EOL><DEDENT>f = shelve.open(filename, '<STR_LIT:c>')<EOL><DEDENT>except Exception:<EOL><INDENT>raise ShelveError(<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>)<EOL><DEDENT>self.max_id = <NUM_LIT:0><EOL>if init_stream_list:<EOL><INDENT>f['<STR_LIT>'] = init_stream_list<EOL>for i, s in enumerate(f['<STR_LIT>']):<EOL><INDENT>s['<STR_LIT:id>'] = s.get('<STR_LIT:id>') or i<EOL>s['<STR_LIT>'] = s.get('<STR_LIT>') or <NUM_LIT:0><EOL>s['<STR_LIT>'] = s.get('<STR_LIT>') or <NUM_LIT:0><EOL><DEDENT>self.max_id = i<EOL>f.sync()<EOL><DEDENT>try:<EOL><INDENT>self.streams = sorted(f['<STR_LIT>'], key=lambda s:s['<STR_LIT>'], reverse=True)<EOL>for s in self.streams:<EOL><INDENT>self.max_id = max(self.max_id, s['<STR_LIT:id>'])<EOL>s['<STR_LIT>'] = <NUM_LIT:2><EOL><DEDENT>if list_streams:<EOL><INDENT>print(json.dumps(self.streams))<EOL>f.close()<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>self.streams = []<EOL><DEDENT>self.db_was_read = True<EOL>self.filtered_streams = list(self.streams)<EOL>self.filter = '<STR_LIT>'<EOL>self.all_streams_offline = None<EOL>self.show_offline_streams = False<EOL>self.config = config<EOL>TITLE_STRING = TITLE_STRING.format(self.config.VERSION)<EOL>self.cmd_list = list(map(shlex.split, self.config.LIVESTREAMER_COMMANDS))<EOL>self.cmd_index = <NUM_LIT:0><EOL>self.cmd = self.cmd_list[self.cmd_index]<EOL>self.last_autocheck = <NUM_LIT:0><EOL>self.default_res = self.config.DEFAULT_RESOLUTION<EOL>self.store = f<EOL>self.store.sync()<EOL>self.no_streams = self.streams == []<EOL>self.no_stream_shown = self.no_streams<EOL>self.q = ProcessList(StreamPlayer().play)<EOL>self.livestreamer = livestreamer.Livestreamer()<EOL>
Init and try to load a stream list, nothing about curses yet