Coder Social home page Coder Social logo

writemdict's Introduction

Summary

writemdict is a Python library that generates dictionaries in the .mdx file format used by Mdict. In addition to the official client, there are various other applications for different platforms that can use the generated dictionary files.

It works in Python 2 (>=2.6) as well as in Python 3.

The .mdx file format is not openly documented. Therefore, this library only supports some of the (presumed) features of the format. Among the supported features are:

  • Versions 1.2 and 2.0 of the file format
  • gzip or LZO compression (the latter with the python-lzo library).
  • encrypted .mdx files (two different encryption schemes)
  • 4 different character encodings.

Files

  • writemdict.py: the main file of the project.
  • ripemd128.py: a simple implementation of RIPEMD128 in pure Python.
  • pureSalsa20.py: implements the Salsa20 stream cipher in pure Python. This version includes support for Python 3.
  • testwrite.py: tests the functionality of the library by writing dictionaries using different options to the subdirectory testoutput/. These should be opened with the official MDict client to verify that they are correctly written.
  • README.md: this file.
  • fileformat.md: A description of the mdx file format.

Optional dependency

To support LZO compression, the python-lzo library must be installed.

Usage example

The main file

A very simple example, demonstrating the use of this library:

from __future__ import unicode_literals
from writemdict import MDictWriter

dictionary = {"doe": "<b>doe</b> <i>n.</i> a deer, a female deer.",
              "ray": "<b>ray</b> <i>n.</i> a drop of golden sun.",
              "me": "<b>me</b> <i>pron.</i> a name I call myself.",
              "far": "<b>far</b> <i>adv.</i> a long, long way to run."}

writer = MDictWriter(dictionary, title="Example Dictionary", description="This is an example dictionary.")
outfile = open("dictionary.mdx", "wb")
writer.write(outfile)
outfile.close()

This creates a dictionary with four entries: "doe", "ray", "me", and "far", and their corresponding definitions.

File format

This project primarily represents an effort in reverse-engineering and documenting the file format used for .mdx files. A description of the format (version 2.0 only) can be found in fileformat.md

See also

This project is based on xwang's mdict analysis, the first attempt to publically document the Mdict file format. That project also includes a python library for reading mdx files.

To do

  • Describe version 1.2 of the file format as well.

writemdict's People

Contributors

zhansliu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

writemdict's Issues

'cgi' is deprecated and slated for removal in Python 3.13

Now the lib does not work for new Python. Here is the output:

D:\EhDatabase2Dictionary\lib\writemdict\writemdict.py:33: DeprecationWarning: 'cgi' is deprecated and slated for removal in Python 3.13
  from cgi import escape
Traceback (most recent call last):
  File "D:\EhDatabase2Dictionary\lib\writemdict\writemdict.py", line 33, in <module>
    from cgi import escape
ImportError: cannot import name 'escape' from 'cgi' (C:\Users\bians\AppData\Local\Programs\Python\Python311\Lib\cgi.py)

mdict supports duplicate keys

mdict supports duplicate keys, but the python standard dict doesn't. a list with tuple elements in the demo script.

Eudic doesn't load CSS and JS files from .mdd file

Eudic (Android app) doesn't load CSS and JS files from mdd file packaged by writemdict. Other resources in mdd file, like images and sounds, work well. Is this issue related to dictionary encryption and registration?

Hope you can give me some advice! Thanks!

encrypt by device id or email has different should produce different results

First of all. Thanks for the great work. Encryption is the hardest piece before full reveal of MDict file format.

Using MdxKeyGen,exe, it generates different RegCode for email and device id, even though the same string is provided. Eg.
C:>MdxKeyGen.exe xiaoqiangwang [email protected]
Author DictKey=xiaoqiangwang
Owner Email=[email protected]
Reg code for end user=3D46FE973BDCE216667011423A29AC80

C:>MdxKeyGen.exe /d xiaoqiangwang [email protected]
Author DictKey=xiaoqiangwang
Device ID=[email protected]
Reg code for end user=D49DF8B49DFD45212DDDCA2C11B59174

And encrypt_key actually produces the same as what MdxKeyGen.exe does for Device ID,
In [4]: import writemdict
In [5]: writemdict.encrypt_key('xiaoqiangwang', '[email protected]')
Out[5]: u'D49DF8B49DFD45212DDDCA2C11B59174'

欧陆IOS版本无法识别 writemdict生成的mdx

为解决大部分mdx收词量太少,经常需要打开网页查词的问题。我做了一个《简明英汉字典增强版》收词200万+,基本解决用户上网查词的问题:

http://www.pdawiki.com/forum/thread-20311-1-1.html

很多网友都十分喜欢这部词典,为他们解决了痛点。

但是随着词汇量不断扩充,MdxBuilder 3.0 Beta2无法应付250万词条以上的mdx了,内存不够,于是我改用 Python 64bits + writemdict 来制作,可惜做出来的mdx 放在goldendict里没问题,手机欧陆就不行了,一开始以为欧陆支持的词汇量有限,结果我把单词删除到100万左右,用writemdict生成的欧陆照样不认,这就是 writemdict的问题了,能否帮看一下:

《简明英汉字典增强版》源文件
http://pan.baidu.com/s/1i4DDpx7

Any library to read mdict *.MDX files in java?

I was looking for any library or sources which helps me to read MDX dictionary files in Java, I have found some resources already such as mdict-android-opensource but it does not have its implantations to how read mdx database files. Does any one knows a good source about these files and possible libraries which could be used for it? Thanks very much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.