用chrome 访问 https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-lzo
下载 python_lzo-1.12-cp37-cp37m-win_amd64.whl
pip instal /pypi/python_lzo-1.12-cp37-cp37m-win_amd64.whl
pip install readmdict ; 参见:使用Python调用mdx字典文件进行查词
从 MDD文件中提取指定的资源文件,pygame 播放mp3。
extract_mdd_cmd.py
# -*- coding: UTF-8 -*-
""" 从 MDD文件中提取指定的资源文件,并播放mp3 """
import os
import sys
import time
from readmdict import MDD # pip install readmdict
import pygame
# main()
if len(sys.argv) ==3:
CMD = sys.argv[1]
mddfile = sys.argv[2]
elif len(sys.argv) ==4:
CMD = sys.argv[1]
mddfile = sys.argv[2]
fnamels = sys.argv[3]
else:
print("usage: extract_mdd_cmd.py head mddfile ")
print("usage: extract_mdd_cmd.py list mddfile ")
print("usage: extract_mdd_cmd.py list mddfile fnamels")
print("usage: extract_mdd_cmd.py find mddfile fnamels")
sys.exit(1)
path1 ="你的MDict/doc目录"
os.chdir(path1)
if not os.path.exists(mddfile):
print(f"{mddfile} is not exists.")
sys.exit(2)
fn,ext = os.path.splitext(mddfile)
if ext.lower() != '.mdd':
print("Please specify a valid MDD file")
sys.exit(3)
#pygame.init()
pygame.mixer.init()
def mplay(filename):
"""播放"""
if pygame.mixer.music.get_busy():
print("mixer.music.get_busy")
return 1
if not os.path.exists(filename):
print(f"{filename} not found.")
return 2
fn,ext = os.path.splitext(filename)
if ext.lower() == '.mp3':
pygame.mixer.music.load(filename)
pygame.mixer.music.play()
else:
print(f"{filename} is not .mp3")
return 3
return 0
# 加载mdd文件
mdd = MDD(mddfile)
if CMD == 'head':
# 文件头 描述项列表
for key, value in mdd.header.items():
print(' %s : %s' % (key.decode(), value.decode()))
if CMD == 'list':
# 列出 资源文件名
if len(sys.argv) ==4:
for fkey,content in mdd.items():
fname = fkey.decode('utf-8')
if fname.find(fnamels) >=0:
print(fname)
else:
for fkey,content in mdd.items():
fname = fkey.decode('utf-8')
print(fname)
if CMD == 'find':
print(' Number of Entries : %d' % len(mdd))
# 找出包含字符串的资源文件名,并输出资源文件
datafolder = 'data'
if not os.path.exists(datafolder):
os.makedirs(datafolder)
for fkey,content in mdd.items():
fname = fkey.decode('utf-8')
if fname.find(fnamels) >=0:
dfname = datafolder + fname.replace('\\', '/')
print(dfname)
if not os.path.exists(os.path.dirname(dfname)):
os.makedirs(os.path.dirname(dfname))
if not os.path.exists(dfname):
df = open(dfname, 'wb')
df.write(content)
df.close()
else: # 播放 mp3
mplay(dfname)
filesize = os.path.getsize(dfname)
time.sleep(1 + filesize//4096)
运行 extract_mdd_cmd.py list "你的MDD文件.mdd" .css
运行 extract_mdd_cmd.py list "你的MDD文件.mdd" .js
运行 extract_mdd_cmd.py find "你的MDD文件.mdd" chain
运行 extract_mdd_cmd.py find "你的MDD文件.mdd" lingo