def _make_mdd_index(self, db_name): if os.path.exists(db_name): os.remove(db_name) mdd = MDD(self._mdd_file) self._mdd_db = db_name index_list = mdd.get_index(check_block=self._check) conn = sqlite3.connect(db_name) c = conn.cursor() c.execute(''' CREATE TABLE MDX_INDEX (key_text text not null unique, file_pos integer, compressed_size integer, decompressed_size integer, record_block_type integer, record_start integer, record_end integer, offset integer )''') tuple_list = [ (item['key_text'], item['file_pos'], item['compressed_size'], item['decompressed_size'], item['record_block_type'], item['record_start'], item['record_end'], item['offset']) for item in index_list ] c.executemany('INSERT INTO MDX_INDEX VALUES (?,?,?,?,?,?,?,?)', tuple_list) if self._sql_index: c.execute(''' CREATE UNIQUE INDEX key_index ON MDX_INDEX (key_text) ''') conn.commit() conn.close()
def _make_mdd_index(self, db_name): mdd = MDD(self._mdd_file) self._mdd_db = db_name index_list = mdd.get_index() conn = sqlite3.connect(db_name) c = conn.cursor() c.execute(''' CREATE TABLE MDX_INDEX (key_text text, file_pos integer, compressed_size integer, record_block_type integer, record_start integer, record_end integer, offset integer )''') tuple_list = [] for item in index_list: tuple = (item['key_text'], item['file_pos'], item['compressed_size'], item['record_block_type'], item['record_start'], item['record_end'], item['offset']) tuple_list.append(tuple) c.executemany('INSERT INTO MDX_INDEX VALUES (?,?,?,?,?,?,?)', tuple_list) conn.commit() conn.close()
def file_error(): print( "\033[31mError: Target MDict file not found!\033[0m\nUsage:\n\033[35mpython \033[33mmdict_extractor.py \033[36m[mdd file]\033[0m\nor\n\033[35mpython \033[33mmdict_extractor.py \033[36m[mdx file]\033[0m" ) os.system('pause') exit(1) if __name__ == '__main__': if len(sys.argv) < 2: file_error() if not os.path.exists("pages"): os.mkdir("pages") if sys.argv[1].split('.')[-1] == "mdd": mdd_file = MDD(sys.argv[1]) print("正在提取媒体文件...") for mdd_item in mdd_file.items(): path = mdd_item[0].decode()[1:] data = mdd_item[1] if os.path.exists(os.path.join("pages", path)): print(f"[x] {path} 已存在!") continue else: print(f"[ ] {path}", end='\r') path_tuple = path.split('\\') path_str = str(os.path.join( "pages", *path_tuple[:-1])) if len(path_tuple) > 1 else '' if path_str != '' and not os.path.exists(path_str): os.mkdir(path_str) src_file = open(os.path.join("pages", path), 'wb')