def getOpenFileName(defaultPath: str = None, defaultExt: str = None, extFilterList: ExtFilterList = None, allowMultiSelect: bool = False): try: w = OPENFILENAMEW() w.lStructSize = sizeof(OPENFILENAMEW) w.nMaxFile = MAXPATH w.nMaxFileTitle = MAXPATH w.Flags = OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR if allowMultiSelect: w.Flags = w.Flags | OFN_ALLOWMULTISELECT | OFN_EXPLORER fn = create_unicode_buffer("", MAXPATH) if extFilterList is not None: efs = extFilterListToStr(extFilterList) eft = create_unicode_buffer(efs, MAXPATH) w.lpstrFilter = cast(eft, LPCTSTR) w.lpstrFile = cast(fn, LPTSTR) if defaultExt is not None: w.lpstrDefExt = defaultExt if defaultPath is not None: tifn = create_unicode_buffer(defaultPath.replace('/', '\\'), MAXPATH) w.lpstrInitialDir = cast(tifn, LPCTSTR) if not windll.comdlg32.GetOpenFileNameW(byref(w)): return None if w.lpstrFile == '': if allowMultiSelect: return [] else: return '' elif not allowMultiSelect: return {"a": w.lpstrFile, "f": splitfn(w.lpstrFile)[1]} else: r = [] nunum = 0 tfn = '' for i in fn: if nunum == 2: break if i == '\0': nunum += 1 if tfn != '': r.append(tfn) tfn = '' else: nunum = 0 tfn += i if len(r) == 1: return [{"a": r[0], "i": splitfn(r[0])[1]}] else: r2 = [] for i in r[1:]: r2.append({"a": f"{r[0]}\\{i}", "f": i}) return r2 except: return None
def getSaveFileName(defaultPath: str = None, defaultName: str = None, defaultExt: str = None, extFilterList: ExtFilterList = None): try: w = OPENFILENAMEW() w.lStructSize = sizeof(OPENFILENAMEW) w.nMaxFile = MAXPATH w.nMaxFileTitle = MAXPATH w.Flags = OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT ofn = '' if defaultName is None else defaultName.replace('/', '\\') fn = create_unicode_buffer(ofn, MAXPATH) if extFilterList is not None: efs = extFilterListToStr(extFilterList) eft = create_unicode_buffer(efs, MAXPATH) w.lpstrFilter = cast(eft, LPCTSTR) w.lpstrFile = cast(fn, LPTSTR) if defaultExt is not None: w.lpstrDefExt = defaultExt if defaultPath is not None: tifn = create_unicode_buffer(defaultPath.replace('/', '\\'), MAXPATH) w.lpstrInitialDir = cast(tifn, LPCTSTR) if not windll.comdlg32.GetSaveFileNameW(byref(w)): return None if w.lpstrFile != '': return {"a": w.lpstrFile, "f": splitfn(w.lpstrFile)[1]} except: return None
def genUrl(self, startIndex: int, endIndex: int, url: str) -> List[str]: if endIndex < startIndex: return [] base = urlsplit(url) bn = splitfn(base.path)[0] r = [] for i in range(startIndex + 1, endIndex + 1): new = SplitResult(base.scheme, base.netloc, f"{bn}/{i}.ts", base.query, base.fragment) r.append(urlunsplit(new)) return r
def changeFileNameForLink(link: str, name: str) -> str: r = urlsplit(link) t = splitfn(r.path) r2 = SplitResult(r.scheme, r.netloc, f"{t[0]}/{name}", r.query, r.fragment) return urlunsplit(r2)
inp = input(lan['INPUT1']) # 请输入要过滤的文件数量: if len(inp) > 0: if inp.isnumeric(): g = int(inp) bs = False fl = file.getfilen(l=o, g=g) for i in fl: if exists(i['a']): try: read = biliDanmuXmlParser.loadXML(i['a']) except: print(lan['INPUT2']) # 此文件不是弹幕文件。 continue r = read try: fn = win32.getSaveFileName(defaultPath=splitfn(i['a'])[0], defaultExt="xml", extFilterList=[XMLFILE, ALLFILE]) if fn == '' or fn is None: continue except: input(lan['INPUT3']) # 按Enter开始选择输出文件。 read = file.getfilen(l=o, save=True) if read == -1: read = file.getfilen('.', save=True) fn = read[0] if exists(fn['a']): remove(fn['a']) try: f = open(fn['a'], mode='w', encoding='utf8') f.write('<?xml version="1.0" encoding="UTF-8"?>')
def urlsplitfn(uri: str) -> str: uri = str(uri) r = splitfn(urlsplit(uri).path)[1] return r