forked from flowerinthenight/flowerinthenight.github.io
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcoderstrip.py
208 lines (184 loc) · 5.42 KB
/
coderstrip.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#encoding=utf8
import re, os, sys
sys.path.append("../")
from pythonx.funclib import *
if IS_WINDOWS:
from pythonx.pelib import getLuckFileMd5, refreshLuckFileTime
else:
def getLuckFileMd5(fpath, luckmd5=None):
return getFileSrcMd5z(fpath) # 避免 git 换行变化造成的影响。
def refreshLuckFileTime(fpath):
return modifyFileTimeCur(fpath)
# 在西歐、北歐及東歐國家常用的字母,帶變音符,和一般英文字母不同。
DIACRITIC = """
À Á Â Ã Ä Å Æ Ā Ă Ą
Ç Ć Ĉ Ċ
Ð Ď Đ
È É Ê Ë Ē Ė Ę Ě Ə
Ĝ Ġ Ģ
Ĥ Ħ
Ì Í Î Ï Ī Į IJ
Ĵ
Ķ
Ļ Ł
Ñ Ń Ņ Ň
Ò Ó Ô Õ Ö Ø Ő Œ
Ŕ Ř
ẞ Ś Ŝ Ş Š Ș Þ
Ţ Ť Ț
Ù Ú Û Ü Ū Ŭ Ů Ű Ų
Ŵ
Ý Ŷ
Ÿ Ź Ż Ž
à á â ã ä å æ ā ă ą
ç ć ĉ ċ
ð ď đ
è é ê ë ē ė ę ě ə
ĝ ġ ģ
ĥ ħ
ì í î ï ī į ij
ĵ
ķ
ļ ł
ñ ń ņ ň
ò ó ô õ ö ø ő œ
ŕ ř
ß ś ŝ ş š ș þ
ţ ť ț
ù ú û ü ū ŭ ů ű ų
ŵ
ý ŷ
ÿ ź ż ž
α β γ δ ε
ζ η θ ι κ λ
μ ν ξ ο π ρ
σ τ υ φ χ
ψ ω
·
Σ
"""
DIACRITIC = "[{}]".format("".join(DIACRITIC.split()))
THUMBNAIL = ".thumbnail.webp"
SELENIUM = ".selenium.png"
def isDiacritic(tchar):
return refindall(DIACRITIC, tchar)
def createCnFile():
page = b""
ordch = 0x4e00
count = 0
while ordch <= 0x9fa5:
ch = chr(ordch)
ordch += 1
page += ch.encode("utf8")
count += 1
if count % 50 == 0:
page += b"\r\n"
tempfile = os.path.join("tempdir", "tempfile.txt")
writefile(tempfile, page)
openTextFile(tempfile)
#createCnFile()
def getLeftSpaceCount(line):
line = line[:]
assert not line.startswith("\t"), line
count = 0
while line and line[0] == " ":
line = line[1:]
count += 1
return count
def calcType(ttype, url):
url = url.split("?")[0].split("#")[0]
url = url.split("/")[-1].strip()
if not url: return ttype
secli = url.split(".")
if len(secli) <= 1: return ttype
if not secli[-1]: return ttype
return "."+secli[-1].lower()
def calcHost(url):
url = url.split("?")[0].split("#")[0]
return url.split("//")[1].split("/")[0]
G_CHECKLOG_FPATH1_MD5 = ""
def checklog(fpath1, fpath2):
global G_CHECKLOG_FPATH1_MD5
G_CHECKLOG_FPATH1_MD5 = getLuckFileMd5(fpath1, G_CHECKLOG_FPATH1_MD5)
fpath2md5 = getMd5(fpath2, "utf8")
localfile = os.path.join("tempdir", G_CHECKLOG_FPATH1_MD5, fpath2md5)
if not os.path.exists(localfile):
return False
fmd5 = readfile(localfile, True)
retv = fmd5 == getLuckFileMd5(fpath2, fmd5)
if retv:
refreshLuckFileTime(localfile) # modifyFileTimeCur
return retv
def savelog(fpath1, fpath2):
global G_CHECKLOG_FPATH1_MD5
G_CHECKLOG_FPATH1_MD5 = getLuckFileMd5(fpath1, G_CHECKLOG_FPATH1_MD5)
fpath2md5 = getMd5(fpath2, "utf8")
localfile = os.path.join("tempdir", G_CHECKLOG_FPATH1_MD5, fpath2md5)
writefile(localfile, getLuckFileMd5(fpath2), force=True)
def removelog(fpath1, fpath2):
global G_CHECKLOG_FPATH1_MD5
G_CHECKLOG_FPATH1_MD5 = getLuckFileMd5(fpath1, G_CHECKLOG_FPATH1_MD5)
fpath2md5 = getMd5(fpath2, "utf8")
localfile = os.path.join("tempdir", G_CHECKLOG_FPATH1_MD5, fpath2md5)
if os.path.exists(localfile):
os.remove(localfile)
G_SNAPCACHE = {}
G_UNTOUCHED = {}
# 收集所有缓存快照。
def buildSnapCache(rootdir):
rootdir = os.path.normpath(rootdir)
def mainfile(fpath, fname, ftype):
fpath = os.path.normpath(fpath)
if not refindall("^[0-9a-f]{8}\\.", fname, re.IGNORECASE):
return
if fname.find(SELENIUM) != -1:
return
key = fname[:8]
if not key in G_SNAPCACHE.keys():
G_SNAPCACHE[key] = []
G_SNAPCACHE[key].append(fpath)
if not key in G_UNTOUCHED.keys():
G_UNTOUCHED[key] = []
G_UNTOUCHED[key].append(fpath)
searchdir(rootdir, mainfile)
# 出现过的移除标记。
def touchSnapCache(umd5, flocal):
if umd5 in G_UNTOUCHED.keys() and flocal in G_UNTOUCHED[umd5]:
G_UNTOUCHED[umd5] = [i for i in G_UNTOUCHED[umd5] if i != flocal]
# 查询可能的缓存路径。
def querySnapCache(umd5):
if umd5 in G_SNAPCACHE.keys() and G_SNAPCACHE[umd5]:
return readfile(G_SNAPCACHE[umd5][0])
return None
# 移除指定缓存快照。
def removeSnapCache(umd5):
if umd5 in G_SNAPCACHE.keys() and G_SNAPCACHE[umd5]:
return osremove(G_SNAPCACHE[umd5][0])
return None
# 清理那些剩余的缓存快照。
def clearSnapCache():
print("ClearSnapCache", len(G_UNTOUCHED))
for umd5 in G_UNTOUCHED.keys():
for x in G_UNTOUCHED[umd5]:
osremove(x)
def ffmpegConvert(fpath):
if fpath.endswith(".264.mp4"): return
tpath = fpath + ".264.mp4"
if os.path.exists(tpath): return
ffmpeg = r"C:\Program Files\ImageMagick-6.9.11-Q16-HDRI\ffmpeg.exe"
cmdx = r"""
"{}" -y -i "{}" -r 30000/1001
-b:a 2M -bt 4M -vcodec libx264 -pass 1
-coder 0 -bf 0 -flags -loop -wpredp 0
-an "{}"
""".format(ffmpeg, fpath, tpath)
cmdx = " ".join(cmdx.split()).strip()
ossystem(cmdx)
def isInvisibleDir(fpath):
fpath = os.path.abspath(fpath).lower()
invisible = os.path.abspath("invisible").lower()+os.sep
invdir = fpath.startswith(invisible)
# .\_site\invisible\
siteinvisible = os.path.abspath(r"_site"+os.sep+"invisible").lower()+os.sep
invdir = invdir or fpath.startswith(siteinvisible)
return invdir