├── README.md ├── dict2mdx.py ├── dict2mdx.sh ├── v1.0.0 ├── dict2mdx.py └── dict2mdx.sh └── v2.0.0 ├── dict2mdx.py └── dict2mdx.sh /README.md: -------------------------------------------------------------------------------- 1 | # dict2mdx 2 | This is a python script to automatically convert Lingvo DSL, Babylon BGL, Stardict, ZIM, Slob, Tabfile txt, etc dictionaries to MDict MDX (see input formats supported by [Pyglossary](https://github.com/ilius/pyglossary)). 3 | 4 | N.B: this script can also pack the resources folder which is located beside the dictionary file to MDD automatically. 5 | 6 | This script has developed because Pyglossary developer decided not to support conversion to .mtxt or .mdx; if the developer decided to support conversion to .mdx, this tool would not be developed, and I hope he does that. 7 | 8 |
9 |
10 | 11 | ### REQUIRMENTS: 12 | 13 | 1- Python 3.9 and up. 14 | 15 | 2- [Pyglossary](https://github.com/ilius/pyglossary) which originally come without octopus_mdict_source.py plugin if you install it using `pip install pyglossary`, because of the developer decided to stop developing this plugin. 16 | SO: DOWNLOAD my modified ready version of pyglossary 5.0.0 with octopus_mdict_source.py plugin added to /pyglossary/plugins folder, and ui_cmd_interactive.py file modified a bit; from my fork [LINK](https://codeload.github.com/sobaee/pyglossaryfork/zip/refs/tags/5.0.0). Decompress the downloaded zip file, and run: `python setup.py install` from inside the decompressed folder to install this modified version of pyglossay and it will work perfectly. 17 | 18 | N.B: As a reference; you can download "octopus_mdict_source.py" plugin from this [link](https://gist.github.com/ilius/88d11fa37a4a40cd0d7f6535120b0693). 19 | 20 | 3- The most important dependencies: 21 | `pip3 install prompt_toolkit mdict-utils beautifulsoup4 python-lzo python-idzip` 22 | 23 | 4- Other important dependencies: 24 | `pip3 install lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim` 25 | 26 |
27 |
28 | 29 | 30 | ### USAGE: 31 | 32 | Navigate to the directory that contains this python script and copy the dictionary file to the same directory, and run this command: 33 | `python dict2mdx.py` 34 |
35 |
36 | 37 | ### Finally: 38 | If requirements are met and all dependencies are ready, your conversion will run smoothly and your .mdx dictionary will be ready, to be used by Multi-dictionaries viewers which support .mdx files (ex. DictTango, Bluedict, Mdict, GoldenDict PC, etc). 39 | 40 | Thanks to "4pda.to" guy "cсpizz" who made the primary version of this automatic script who inspired me to update the script, make a similar python script and make it more useful. [LINK to the original script](https://gist.github.com/glowinthedark/e393730e8477bb64f86fc99ec21d6303). 41 | 42 | Thanks to the owners of Pyglossary and mdict-utils. 43 | -------------------------------------------------------------------------------- /dict2mdx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | import os 13 | import sys 14 | import subprocess 15 | import re 16 | import readline 17 | 18 | history_file = ".script_history.txt" 19 | 20 | # Check if history_file exists 21 | if not os.path.isfile(history_file): 22 | print(f"{history_file} not found. Ignoring on first run.") 23 | 24 | # Load previous command history 25 | try: 26 | readline.read_history_file(history_file) 27 | except FileNotFoundError: 28 | pass 29 | 30 | def check_command(command): 31 | try: 32 | subprocess.check_output([command, '--version'], stderr=subprocess.STDOUT) 33 | except subprocess.CalledProcessError: 34 | return False 35 | else: 36 | return True 37 | 38 | if check_command('python3'): 39 | if check_command('pyglossary'): 40 | if check_command('mdict'): 41 | print("All dependings are ready!!\n") 42 | else: 43 | print("ERROR: mdict not found! Run 'pip3 install mdict-utils'!") 44 | exit(1) 45 | else: 46 | print("ERROR: pyglossary not installed! Download my modified version on github readme.md and run this command from inside the main folder 'python setup.py install'") 47 | exit(1) 48 | else: 49 | print("ERROR: python not installed! install it according to your system") 50 | exit(1) 51 | 52 | answer1 = input("to convert directly from .mtxt to MDX or to pack MDD resources only press (y)!! OR PRESS ANY OTHER KEY TO CONTINUE! ") 53 | 54 | if answer1.lower() == 'y': 55 | src = input("Enter your .mtxt dict full name without spaces: ") 56 | 57 | with open("description.html", "w") as file: 58 | file.write(src.split('.')[0]) 59 | 60 | with open("title.html", "w") as file: 61 | file.write(src.split('.')[0]) 62 | 63 | if os.path.exists(src.split('.')[0] + ".mtxt"): 64 | cmd = [ 65 | "mdict", 66 | "--title", "title.html", 67 | "--description", "description.html", 68 | "-a", src.split('.')[0] + ".mtxt", 69 | src.split('.')[0] + ".mdx" 70 | ] 71 | subprocess.run(cmd, check=True) 72 | 73 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 74 | cmd = [ 75 | "mdict", 76 | "-a", src.split('.')[0] + ".mtxt_res", 77 | src.split('.')[0] + ".mdd" 78 | ] 79 | subprocess.run(cmd, check=True) 80 | print("Sources is also converted to MDD\n") 81 | 82 | print("All done!") 83 | exit(1) 84 | else: 85 | print(f"ERROR: {src.split('.')[0]}.mtxt doesn't found\n") 86 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 87 | cmd = [ 88 | "mdict", 89 | "-a", src.split('.')[0] + ".mtxt_res", 90 | src.split('.')[0] + ".mdd" 91 | ] 92 | subprocess.run(cmd, check=True) 93 | print("Only MDD is packed!!!") 94 | exit(1) 95 | else: 96 | print("Your conversion will continue\n") 97 | 98 | subprocess.run('pyglossary --cmd', shell=True) 99 | 100 | print() 101 | print() 102 | answer = input("Convert .mtxt to MDX? (y) or press any other key to exit? ") 103 | 104 | if answer.lower() == "y": 105 | src = input("Enter your result .mtxt dict full name again, please: ") 106 | 107 | with open("description.html", "w") as file: 108 | file.write(src.split('.')[0]) 109 | 110 | with open("title.html", "w") as file: 111 | file.write(src.split('.')[0]) 112 | 113 | if os.path.exists(src.split('.')[0] + ".mtxt"): 114 | cmd = [ 115 | "mdict", 116 | "--title", "title.html", 117 | "--description", "description.html", 118 | "-a", src.split('.')[0] + ".mtxt", 119 | src.split('.')[0] + ".mdx" 120 | ] 121 | subprocess.run(cmd, check=True) 122 | 123 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 124 | cmd = [ 125 | "mdict", 126 | "-a", src.split('.')[0] + ".mtxt_res", 127 | src.split('.')[0] + ".mdd" 128 | ] 129 | subprocess.run(cmd, check=True) 130 | print("Sources is also converted to MDD\n") 131 | 132 | print("All done!") 133 | exit(1) 134 | else: 135 | print(f"{src.split('.')[0]}.mtxt doesn't found") 136 | exit(1) 137 | else: 138 | print("Conversion done, Did not convert to MDX") 139 | exit(1) 140 | 141 | # Save command history 142 | readline.write_history_file(history_file) -------------------------------------------------------------------------------- /dict2mdx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | if command -v python3 >/dev/null 2>&1; then 13 | if command -v pyglossary >/dev/null 2>&1; then 14 | if command -v mdict >/dev/null 2>&1; then 15 | echo -e "All dependings are ready!!\n" 16 | else 17 | echo "ERROR: mdict not found! Run 'pip3 install mdict-utils'!" 18 | exit 1 19 | fi 20 | else 21 | echo "ERROR: pyglossary not installed! Install my modified version as you read on github" 22 | exit 1 23 | fi 24 | else 25 | echo "ERROR: python not installed! Download and install from https://www.python.org/downloads" 26 | exit 1 27 | fi 28 | 29 | read -p "If your file is already .mtxt and/or sources folder and you want to convert directly to MDX and/or MDD press (y)!! OR press any other key if not! " answer1 30 | case $answer1 in 31 | y|Y) 32 | src="" 33 | read -p "Enter the .mtxt dict name: " src 34 | 35 | printf ${src%.*} > description.html 36 | printf ${src%.*} > title.html 37 | if [ -e "${src%.*}.mtxt" ]; then 38 | mdict --title title.html --description description.html -a "${src%.*}.mtxt" "${src%.*}.mdx" 39 | 40 | if [ -d "${src%.*}.mtxt_res" ]; then 41 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 42 | echo -e ' Sources is also converted to MDD \n ' 43 | fi 44 | 45 | 46 | echo 'All done!' 47 | exit 1 48 | else 49 | echo -e "ERROR: ${src%.*}.mtxt doesn't found\n" 50 | if [ -d "${src%.*}.mtxt_res" ]; then 51 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 52 | echo -e '\n Only MDD is packed!!!' 53 | fi 54 | exit 1 55 | fi 56 | 57 | ;; 58 | n|N) 59 | echo -e ' Your conversion will continue \n ' 60 | 61 | ;; 62 | *) # Invalid choice 63 | echo -e ' Your conversion will continue \n ' 64 | ;; 65 | esac 66 | 67 | 68 | pyglossary --cmd 69 | 70 | echo 71 | echo 72 | read -p "Convert .mtxt to MDX? (y) or press any other key to exit? " answer 73 | case $answer in 74 | y|Y) 75 | src="" 76 | read -p "Enter dict name again: " src 77 | 78 | printf ${src%.*} > description.html 79 | printf ${src%.*} > title.html 80 | if [ -e "${src%.*}.mtxt" ]; then 81 | mdict --title title.html --description description.html -a "${src%.*}.mtxt" "${src%.*}.mdx" 82 | 83 | if [ -d "${src%.*}.mtxt_res" ]; then 84 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 85 | echo -e ' Sources is also converted to MDD \n ' 86 | fi 87 | 88 | 89 | echo 'All done!' 90 | exit 1 91 | else 92 | echo "${src%.*}.mtxt doesn't found" 93 | exit 1 94 | fi 95 | 96 | ;; 97 | n|N) 98 | echo 'Conversion done, Did not converted to MDX' 99 | exit 1 100 | 101 | ;; 102 | *) # Invalid choice 103 | echo 'Conversion done, Did not converted to MDX' 104 | ;; 105 | esac -------------------------------------------------------------------------------- /v1.0.0/dict2mdx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | import os 13 | import sys 14 | import subprocess 15 | import re 16 | import readline 17 | 18 | history_file = ".script_history.txt" 19 | 20 | # Check if history_file exists 21 | if not os.path.isfile(history_file): 22 | print(f"{history_file} not found. Ignoring on first run.") 23 | 24 | # Load previous command history 25 | try: 26 | readline.read_history_file(history_file) 27 | except FileNotFoundError: 28 | pass 29 | 30 | def check_command(command): 31 | try: 32 | subprocess.check_output([command, '--version'], stderr=subprocess.STDOUT) 33 | except subprocess.CalledProcessError: 34 | return False 35 | else: 36 | return True 37 | 38 | if check_command('python3'): 39 | if check_command('pyglossary'): 40 | if check_command('mdict'): 41 | print("All dependencies are ready!\n") 42 | else: 43 | print("ERROR: mdict not found! Run 'pip3 install mdict-utils'!") 44 | exit(1) 45 | else: 46 | print("ERROR: pyglossary not installed! Run 'pip3 install pyglossary'") 47 | exit(1) 48 | else: 49 | print("ERROR: python not installed! Download and install from https://www.python.org/downloads") 50 | exit(1) 51 | 52 | 53 | src = input("Input file (ex. dictionary.dsl): ") 54 | 55 | with open('description.html', 'w') as f: 56 | f.write(os.path.splitext(src)[0]) 57 | 58 | with open('title.html', 'w') as f: 59 | f.write(os.path.splitext(src)[0]) 60 | 61 | if src.endswith('.dz'): 62 | print('Unpacking .dz file...') 63 | subprocess.run(['idzip', '-d', src]) 64 | src = os.path.splitext(src)[0] 65 | 66 | # Save command history 67 | readline.write_history_file(history_file) 68 | 69 | if os.path.isfile(f"{os.path.splitext(src)[0]}.mtxt"): 70 | answer = input(f"{os.path.splitext(src)[0]}.mtxt already exists! Do you want to convert it directly to MDX? (y/n) ") 71 | if answer.lower() == 'y': 72 | # Use Word Title option 73 | subprocess.run(['mdict', '--title', 'title.html', '--description', 'description.html', '-a', f"{os.path.splitext(src)[0]}.mtxt", f"{os.path.splitext(src)[0]}.mdx"]) 74 | if os.path.isdir(f"{os.path.splitext(src)[0]}.cache_res"): 75 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.cache_res", f"{os.path.splitext(src)[0]}.mdd"]) 76 | 77 | if os.path.isdir(f"{os.path.splitext(src)[0]}.mtxt_res"): 78 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.mtxt_res", f"{os.path.splitext(src)[0]}.mdd"]) 79 | 80 | if os.path.isdir(f"{os.path.splitext(src)[0]}.txt_res"): 81 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.txt_res", f"{os.path.splitext(src)[0]}.mdd"]) 82 | print('All done!') 83 | sys.exit(1) 84 | elif answer.lower() == 'n': 85 | # Do not use Word Title option 86 | pass 87 | else: 88 | # Invalid choice 89 | print("Invalid option. Please enter y or n.") 90 | sys.exit(1) 91 | 92 | db_file = f"{os.path.splitext(src)[0]}.cache" 93 | 94 | if os.path.exists(db_file): 95 | answer = input(f"{db_file} already exists! OVERWRITE? (y/n) ") 96 | if answer.lower() == 'y': 97 | os.remove(db_file) 98 | else: 99 | sys.exit(1) 100 | 101 | choice1 = input("Do you want to use Word Title option? (y/n): ") 102 | if choice1.lower() == 'y': 103 | # Use Word Title option 104 | subprocess.run(['pyglossary', src, db_file, '--write-format=OctopusMdictSource', '--json-write-options', '{"word_title": true}']) 105 | print('All done!') 106 | elif choice1.lower() == 'n': 107 | # Do not use Word Title option 108 | subprocess.run(['pyglossary', src, db_file, '--write-format=OctopusMdictSource']) 109 | print('All done!') 110 | else: 111 | # Invalid choice 112 | print("Invalid option. Please enter y or n.") 113 | sys.exit(1) 114 | 115 | subprocess.run(['mdict', '--title', 'title.html', '--description', 'description.html', '-a', db_file, f"{os.path.splitext(src)[0]}.mdx"]) 116 | 117 | if os.path.isdir(f"{os.path.splitext(src)[0]}.cache_res"): 118 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.cache_res", f"{os.path.splitext(src)[0]}.mdd"]) 119 | 120 | if os.path.isdir(f"{os.path.splitext(src)[0]}.mtxt_res"): 121 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.mtxt_res", f"{os.path.splitext(src)[0]}.mdd"]) 122 | 123 | if os.path.isdir(f"{os.path.splitext(src)[0]}.txt_res"): 124 | subprocess.run(['mdict', '-a', f"{os.path.splitext(src)[0]}.txt_res", f"{os.path.splitext(src)[0]}.mdd"]) 125 | 126 | print('All done!') 127 | -------------------------------------------------------------------------------- /v1.0.0/dict2mdx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | if command -v python3 >/dev/null 2>&1; then 13 | if command -v pyglossary >/dev/null 2>&1; then 14 | if command -v mdict >/dev/null 2>&1; then 15 | echo -e "All dependencies are ready!\n" 16 | else 17 | echo "ERROR: mdict not found! Run 'pip3 install mdict-utils'!" 18 | exit 1 19 | fi 20 | else 21 | echo "ERROR: pyglossary not installed! Run 'pip3 install pyglossary'" 22 | exit 1 23 | fi 24 | else 25 | echo "ERROR: python not installed! Download and install from https://www.python.org/downloads" 26 | exit 1 27 | fi 28 | 29 | 30 | 31 | 32 | src="" 33 | read -p "Input file (ex. dictionary.dsl): " src 34 | 35 | printf ${src%.*} > description.html 36 | printf ${src%.*} > title.html 37 | 38 | if [[ "$src" =~ .*\.dz ]]; then 39 | echo 'Unpacking .dz file...' 40 | idzip -d "$1" 41 | src="${1%.*}" 42 | fi 43 | 44 | if [ -f "${src%.*}.mtxt" ]; then 45 | read -p "${src%.*}.mtxt already exists! Do you want to convert it directly to MDX? (y/n) " answer 46 | case $answer in 47 | y|Y) # Use Word Title option 48 | mdict --title title.html --description description.html -a "${src%.*}.mtxt" "${src%.*}.mdx" 49 | if [ -d "${src%.*}.cache_res" ]; then 50 | mdict -a "${src%.*}.cache_res" "${src%.*}.mdd" 51 | fi 52 | 53 | if [ -d "${src%.*}.mtxt_res" ]; then 54 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 55 | fi 56 | 57 | if [ -d "${src%.*}.txt_res" ]; then 58 | mdict -a "${src%.*}.txt_res" "${src%.*}.mdd" 59 | fi 60 | echo 'All done!' 61 | exit 1 62 | ;; 63 | n|N) # Do not use Word Title option 64 | 65 | 66 | ;; 67 | *) # Invalid choice 68 | echo "Invalid option. Please enter y or n." 69 | ;; 70 | esac 71 | fi 72 | 73 | 74 | 75 | db_file="${src%.*}.cache" 76 | 77 | if [ -e "$db_file" ]; then 78 | read -p "$db_file already exists! OVERWRITE? (y/n) " answer 79 | if [[ $answer =~ ^[Yy]$ ]]; then 80 | rm -v "$db_file" 81 | else 82 | exit 1 83 | fi 84 | fi 85 | 86 | read -p "Do you want to use Word Title option? (y/n): " choice1 87 | case $choice1 in 88 | y|Y) # Use Word Title option 89 | pyglossary "$src" "$db_file" --write-format=OctopusMdictSource --json-write-options '{"word_title": true}' 90 | 91 | echo 'All done!' 92 | ;; 93 | n|N) # Do not use Word Title option 94 | 95 | pyglossary "$src" "$db_file" --write-format=OctopusMdictSource 96 | echo 'All done!' 97 | ;; 98 | *) # Invalid choice 99 | echo "Invalid option. Please enter y or n." 100 | ;; 101 | esac 102 | 103 | mdict --title title.html --description description.html -a "$db_file" "${src%.*}.mdx" 104 | 105 | if [ -d "${src%.*}.cache_res" ]; then 106 | mdict -a "${src%.*}.cache_res" "${src%.*}.mdd" 107 | fi 108 | 109 | if [ -d "${src%.*}.mtxt_res" ]; then 110 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 111 | fi 112 | 113 | if [ -d "${src%.*}.txt_res" ]; then 114 | mdict -a "${src%.*}.txt_res" "${src%.*}.mdd" 115 | fi 116 | 117 | echo 'All done!' 118 | -------------------------------------------------------------------------------- /v2.0.0/dict2mdx.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | import os 13 | import sys 14 | import subprocess 15 | import re 16 | import readline 17 | 18 | history_file = ".script_history.txt" 19 | 20 | # Check if history_file exists 21 | if not os.path.isfile(history_file): 22 | print(f"{history_file} not found. Ignoring on first run.") 23 | 24 | # Load previous command history 25 | try: 26 | readline.read_history_file(history_file) 27 | except FileNotFoundError: 28 | pass 29 | 30 | def check_command(command): 31 | try: 32 | subprocess.check_output([command, '--version'], stderr=subprocess.STDOUT) 33 | except subprocess.CalledProcessError: 34 | return False 35 | else: 36 | return True 37 | 38 | if check_command('python3'): 39 | if check_command('pyglossary'): 40 | if check_command('mdict'): 41 | print("All dependings are ready!!\n") 42 | else: 43 | print("ERROR: mdict not found! Run 'pip3 install mdict-utils'!") 44 | exit(1) 45 | else: 46 | print("ERROR: pyglossary not installed! Download my modified version on github readme.md and run this command from inside the main folder 'python setup.py install'") 47 | exit(1) 48 | else: 49 | print("ERROR: python not installed! install it according to your system") 50 | exit(1) 51 | 52 | answer1 = input("If your file is already .mtxt and/or sources folder and you want to convert directly to MDX and/or MDD press (y)!! OR press any other key if not! ") 53 | 54 | if answer1.lower() == 'y': 55 | src = input("Enter the .mtxt dict name: ") 56 | 57 | with open("description.html", "w") as file: 58 | file.write(src.split('.')[0]) 59 | 60 | with open("title.html", "w") as file: 61 | file.write(src.split('.')[0]) 62 | 63 | if os.path.exists(src.split('.')[0] + ".mtxt"): 64 | cmd = [ 65 | "mdict", 66 | "--title", "title.html", 67 | "--description", "description.html", 68 | "-a", src.split('.')[0] + ".mtxt", 69 | src.split('.')[0] + ".mdx" 70 | ] 71 | subprocess.run(cmd, check=True) 72 | 73 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 74 | cmd = [ 75 | "mdict", 76 | "-a", src.split('.')[0] + ".mtxt_res", 77 | src.split('.')[0] + ".mdd" 78 | ] 79 | subprocess.run(cmd, check=True) 80 | print("Sources is also converted to MDD\n") 81 | 82 | print("All done!") 83 | exit(1) 84 | else: 85 | print(f"ERROR: {src.split('.')[0]}.mtxt doesn't found\n") 86 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 87 | cmd = [ 88 | "mdict", 89 | "-a", src.split('.')[0] + ".mtxt_res", 90 | src.split('.')[0] + ".mdd" 91 | ] 92 | subprocess.run(cmd, check=True) 93 | print("Only MDD is packed!!!") 94 | exit(1) 95 | else: 96 | print("Your conversion will continue\n") 97 | 98 | subprocess.run('pyglossary --cmd', shell=True) 99 | 100 | print() 101 | print() 102 | answer = input("Convert .mtxt to MDX? (y) or press any other key to exit? ") 103 | 104 | if answer.lower() == "y": 105 | src = input("Enter dict name again: ") 106 | 107 | with open("description.html", "w") as file: 108 | file.write(src.split('.')[0]) 109 | 110 | with open("title.html", "w") as file: 111 | file.write(src.split('.')[0]) 112 | 113 | if os.path.exists(src.split('.')[0] + ".mtxt"): 114 | cmd = [ 115 | "mdict", 116 | "--title", "title.html", 117 | "--description", "description.html", 118 | "-a", src.split('.')[0] + ".mtxt", 119 | src.split('.')[0] + ".mdx" 120 | ] 121 | subprocess.run(cmd, check=True) 122 | 123 | if os.path.isdir(src.split('.')[0] + ".mtxt_res"): 124 | cmd = [ 125 | "mdict", 126 | "-a", src.split('.')[0] + ".mtxt_res", 127 | src.split('.')[0] + ".mdd" 128 | ] 129 | subprocess.run(cmd, check=True) 130 | print("Sources is also converted to MDD\n") 131 | 132 | print("All done!") 133 | exit(1) 134 | else: 135 | print(f"{src.split('.')[0]}.mtxt doesn't found") 136 | exit(1) 137 | else: 138 | print("Conversion done, Did not convert to MDX") 139 | exit(1) 140 | 141 | # Save command history 142 | readline.write_history_file(history_file) -------------------------------------------------------------------------------- /v2.0.0/dict2mdx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Convert Lingvo DSL, Babylon BGL, Stardict, ZIM, etc dictionaries to MDict MDX (see input formats supported by https://github.com/ilius/pyglossary) 4 | # 5 | # Dependencies: 6 | # python3, pyglossary, mdict-utils, which 7 | # 8 | # Install all dependencies with: 9 | # pip3 install mdict-utils lxml polib PyYAML beautifulsoup4 marisa-trie html5lib PyICU libzim>=1.0 python-lzo prompt_toolkit python-idzip 10 | # pyglossary better to be installed from a local folder with: python setup.py install (better to use my ready pyglossary zip file) 11 | 12 | if command -v python3 >/dev/null 2>&1; then 13 | if command -v pyglossary >/dev/null 2>&1; then 14 | if command -v mdict >/dev/null 2>&1; then 15 | echo -e "All dependings are ready!!\n" 16 | else 17 | echo "ERROR: mdict not found! Run 'pip3 install mdict-utils'!" 18 | exit 1 19 | fi 20 | else 21 | echo "ERROR: pyglossary not installed! Install my modified version as you read on github" 22 | exit 1 23 | fi 24 | else 25 | echo "ERROR: python not installed! Download and install from https://www.python.org/downloads" 26 | exit 1 27 | fi 28 | 29 | read -p "If your file is already .mtxt and/or sources folder and you want to convert directly to MDX and/or MDD press (y)!! OR press any other key if not! " answer1 30 | case $answer1 in 31 | y|Y) 32 | src="" 33 | read -p "Enter the .mtxt dict name: " src 34 | 35 | printf ${src%.*} > description.html 36 | printf ${src%.*} > title.html 37 | if [ -e "${src%.*}.mtxt" ]; then 38 | mdict --title title.html --description description.html -a "${src%.*}.mtxt" "${src%.*}.mdx" 39 | 40 | if [ -d "${src%.*}.mtxt_res" ]; then 41 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 42 | echo -e ' Sources is also converted to MDD \n ' 43 | fi 44 | 45 | 46 | echo 'All done!' 47 | exit 1 48 | else 49 | echo -e "ERROR: ${src%.*}.mtxt doesn't found\n" 50 | if [ -d "${src%.*}.mtxt_res" ]; then 51 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 52 | echo -e '\n Only MDD is packed!!!' 53 | fi 54 | exit 1 55 | fi 56 | 57 | ;; 58 | n|N) 59 | echo -e ' Your conversion will continue \n ' 60 | 61 | ;; 62 | *) # Invalid choice 63 | echo -e ' Your conversion will continue \n ' 64 | ;; 65 | esac 66 | 67 | 68 | pyglossary --cmd 69 | 70 | echo 71 | echo 72 | read -p "Convert .mtxt to MDX? (y) or press any other key to exit? " answer 73 | case $answer in 74 | y|Y) 75 | src="" 76 | read -p "Enter dict name again: " src 77 | 78 | printf ${src%.*} > description.html 79 | printf ${src%.*} > title.html 80 | if [ -e "${src%.*}.mtxt" ]; then 81 | mdict --title title.html --description description.html -a "${src%.*}.mtxt" "${src%.*}.mdx" 82 | 83 | if [ -d "${src%.*}.mtxt_res" ]; then 84 | mdict -a "${src%.*}.mtxt_res" "${src%.*}.mdd" 85 | echo -e ' Sources is also converted to MDD \n ' 86 | fi 87 | 88 | 89 | echo 'All done!' 90 | exit 1 91 | else 92 | echo "${src%.*}.mtxt doesn't found" 93 | exit 1 94 | fi 95 | 96 | ;; 97 | n|N) 98 | echo 'Conversion done, Did not converted to MDX' 99 | exit 1 100 | 101 | ;; 102 | *) # Invalid choice 103 | echo 'Conversion done, Did not converted to MDX' 104 | ;; 105 | esac --------------------------------------------------------------------------------