GitXplorerGitXplorer
c

mdict-analysis

public
254 stars
57 forks
2 issues

Commits

List of commits on branch master.
Unverified
e99cfca7a969cc8020d6f92d76c254e075f4110a

Update and rename README.rst to README.md

ccsarron committed 8 years ago
Unverified
70ee45bdfbcf253b4ed7eb1626d9ffc6d1b4b3e0

python 3 compatible fix

committed 9 years ago
Unverified
2262968d810b1eb1882cbe9be351aaddae558f47

no encryption if Encrypted is not in header

committed 9 years ago
Unverified
01bdb1deb03869f09ef9701dda460c41c3915daf

python 3 compatible

committed 9 years ago
Unverified
c3b203bdb07832b7ea54820caea7044258e3b95b

make a smart check of newline ending

committed 9 years ago
Unverified
b72174a4ebab3991fc1c1beb1f473c837082e891

python 3 compatible

committed 9 years ago

README

The README file for this repository.

An Analysis of MDX/MDD File Format

MDict is a multi-platform open dictionary

which are both questionable. It is not available for every platform, e.g. OS X, Linux. Its dictionary file format is not open. But this has not hindered its popularity, and many dictionaries have been created for it.

This is an attempt to reveal MDX/MDD file format, so that my favorite dictionaries, created by MDict users, could be used elsewhere.

MDict Files

MDict stores the dictionary definitions, i.e. (key word, explanation) in MDX file and the dictionary reference data, e.g. images, pronunciations, stylesheets in MDD file. Although holding different contents, these two file formats share the same structure.

MDX File Format

MDD File Format

Example Programs

readmdict.py

readmdict.py is an example implementation in Python. This program can read/extract mdx/mdd files.

.. note:: python-lzo is required to read mdx files created with engine 1.2. Get Windows version from http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-lzo

It can be used as a command line tool. Suppose one has oald8.mdx and oald8.mdd::

$ python readmdict.py -x oald8.mdx

This will creates oald8.txt dictionary file and creates a folder data for images, pronunciation audio files.

On Windows, one can also double click it and select the file in the popup dialog.

Or as a module::

In [1]: from readmdict import MDX, MDD

Read MDX file and print the first entry::

In [2]: mdx = MDX('oald8.mdx')

In [3]: items = mdx.items()

In [4]: items.next()
Out[4]:
('A',
 '<span style=\'display:block;color:black;\'>.........')

mdx is an object having all info from a MDX file. items is an iterator producing 2-item tuples. Of each tuple, the first element is the entry text and the second is the explanation. Both are UTF-8 encoded strings.

Read MDD file and print the first entry::

In [5]: mdd = MDD('oald8.mdd')

In [6]: items = mdd.items()

In [7]: items = mdd.next()
Out[7]: 
(u'\\pic\\accordion_concertina.jpg',
'\xff\xd8\xff\xe0\x00\x10JFIF...........')

mdd is an object having all info from a MDD file. items is an iterator producing 2-item tuples. Of each tuple, the first element is the file name and the second element is the corresponding file content. The file name is encoded in UTF-8. The file content is a plain bytes array.

Acknowledge

The file format gets fully disclosed by https://github.com/zhansliu/writemdict. The encryption part is taken into this project.