python:从 MDD文件中提取指定的资源文件,并播放mp3

阅读: 评论:0

python:从 MDD文件中提取指定的资源文件,并播放mp3

python:从 MDD文件中提取指定的资源文件,并播放mp3

用chrome 访问
下载 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")it(1)path1 ="你的MDict/doc目录"
os.chdir(path1)
if not ists(mddfile):print(f"{mddfile} is not exists.")it(2)fn,ext = os.path.splitext(mddfile)
if ext.lower() != '.mdd':print("Please specify a valid MDD file")it(3)#pygame.init()
pygame.mixer.init()def mplay(filename):"""播放"""if pygame._busy():print("_busy")return 1if not ists(filename):print(f"{filename} not found.")return 2fn,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 3return 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 ists(datafolder):os.makedirs(datafolder)for fkey,content in mdd.items():fname = fkey.decode('utf-8')if fname.find(fnamels) >=0:dfname = datafolder + place('\', '/')print(dfname)if not ists(os.path.dirname(dfname)):os.makedirs(os.path.dirname(dfname))if not ists(dfname):df = open(dfname, 'wb')df.write(content)df.close()else: # 播放 mp3mplay(dfname)filesize = size(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

本文发布于:2024-01-28 08:41:13,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/17064024776183.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:文件   资源   python   MDD
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23