This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTML5KaraokeMaker.py
129 lines (103 loc) · 3.25 KB
/
HTML5KaraokeMaker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python
# -*- coding: utf-8 -*-
# HTML5KaraokeMaker
#
# Copyright 2015 Guénaël Muller <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# sys
import sys
import os
# translate
import locale
import gettext
# settings
from setting import *
from maker import Maker
# other
import shutil
import logging
logging.basicConfig()
# init translation
def initTranslation():
''' init Translation with gettext'''
lang = gettext.NullTranslations()
try:
lang = gettext.translation(APP, localedir=LOCALE_DIR)
except IOError:
pass
lang.install()
def translateArgparse(Text):
''' to Translate argparse module'''
Text = Text.replace("usage", _("usage"))
Text = Text.replace("show this help message and exit",
_("show this help message and exit"))
Text = Text.replace("error:", _("error:"))
Text = Text.replace("the following arguments are required:",
_("the following arguments are required:"))
Text = Text.replace("too few arguments",
_("too few arguments"))
Text = Text.replace("optional arguments",
_("optional arguments"))
return Text
initTranslation()
gettext.gettext = translateArgparse
import argparse
class HTML5kKaraokeMaker(object):
"CLI interface of HTML5kKaraokeMaker"
def readCli(self):
'''CLI:Argument parser'''
parser = argparse.ArgumentParser()
parser.add_argument(
'-p',
'--webpath',
help=_("use a local web path file"),
default=D_WEB_DIR
)
parser.add_argument(
'-d',
'--datapath',
help=_("use a local data path file"),
default=D_DATA_DIR
)
parser.add_argument(
'-o',
'--output',
help=_("choose a specific output directory"),
default=D_WEB_DIR
)
self.args = parser.parse_args()
return True
def __init__(self, logLevel=LOGLEVEL):
''' Launch CLI'''
self.logger = logging.getLogger("HTML5kKaraokeMaker")
self.logger.setLevel(logLevel)
if self.readCli():
self.maker = Maker(self.args.webpath,self.args.datapath)
self.maker.make()
self.saveFile()
else:
print(_("Interface error"))
def __str__(self):
'''Print text'''
if self.maker:
return str(self.maker)
else:
return _("No file")
def saveFile(self):
#copy needed data
audioPath=self.args.output+'/audio'
dependPath=self.args.output+'/depend'
if os.path.exists(audioPath):
shutil.rmtree(audioPath)
if os.path.exists(dependPath):
shutil.rmtree(dependPath)
shutil.copytree('data/audio','web/audio')
shutil.copytree('data/depend','web/depend')
with open(self.args.output+"/index.html", "w+") as doc:
doc.write(self.__str__())
if __name__ == '__main__':
k = HTML5kKaraokeMaker()