mirror of
https://github.com/lifegpc/pythonscript.git
synced 2026-06-05 11:08:49 +08:00
Add new script link_directory
This commit is contained in:
23
copy_tag.py
Normal file
23
copy_tag.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from argparse import ArgumentParser
|
||||
import music_tag
|
||||
import taglib
|
||||
|
||||
p = ArgumentParser()
|
||||
p.add_argument('infile')
|
||||
p.add_argument('outfile')
|
||||
|
||||
|
||||
def main():
|
||||
arg = p.parse_args()
|
||||
with taglib.File(arg.infile) as f:
|
||||
with taglib.File(arg.outfile) as o:
|
||||
o.tags.update(f.tags)
|
||||
o.save()
|
||||
i = music_tag.load_file(arg.infile)
|
||||
o = music_tag.load_file(arg.outfile)
|
||||
o["artwork"] = i["artwork"]
|
||||
o.save()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
40
link_directory.py
Normal file
40
link_directory.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from argparse import ArgumentParser
|
||||
from os.path import exists, isdir, join
|
||||
from os import makedirs, listdir, link
|
||||
|
||||
|
||||
p = ArgumentParser(description='Link files in a directory to another directory.') # noqa: E501
|
||||
p.add_argument('-a', '--all', help='Include all files.', action='store_true') # noqa: E501
|
||||
p.add_argument('input', help='The path to the input directory.')
|
||||
p.add_argument('output', help='The path to the output directory.')
|
||||
|
||||
|
||||
def hardlink_files(input: str, output: str, all: bool):
|
||||
if exists(input) and not isdir(input):
|
||||
raise ValueError(f"{input} is not a directory.")
|
||||
if exists(output) and not isdir(output):
|
||||
raise ValueError(f"{output} is not a directory.")
|
||||
if not exists(output):
|
||||
makedirs(output)
|
||||
for f in listdir(input):
|
||||
if not all and f.startswith('.'):
|
||||
continue
|
||||
src = join(input, f)
|
||||
dst = join(output, f)
|
||||
if isdir(src):
|
||||
hardlink_files(src, dst, all)
|
||||
continue
|
||||
if exists(dst):
|
||||
print(f"{dst} already exists.")
|
||||
continue
|
||||
print(f"Linking {src} to {dst}.")
|
||||
link(src, dst)
|
||||
|
||||
|
||||
def main(args=None):
|
||||
arg = p.parse_intermixed_args(args)
|
||||
hardlink_files(arg.input, arg.output, arg.all)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -84,7 +84,7 @@ def get_m4a_files(dir: str, r: bool) -> List[str]:
|
||||
if isdir(file):
|
||||
if r:
|
||||
re += get_m4a_files(file, r)
|
||||
elif file.endswith('.m4a') or file.endswith(".flac"):
|
||||
elif file.endswith('.m4a') or file.endswith(".flac") or file.endswith(".mp3"):
|
||||
re.append(file)
|
||||
return re
|
||||
|
||||
|
||||
45
unpack_xxxx.py
Normal file
45
unpack_xxxx.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from argparse import ArgumentParser
|
||||
from json import load, dump
|
||||
import os
|
||||
from os.path import splitext, join
|
||||
import xxtea
|
||||
|
||||
|
||||
def try_decode(fn: str):
|
||||
with open(fn, 'rb') as f:
|
||||
data = f.read(6)
|
||||
if data != b'jiaile':
|
||||
return
|
||||
data = f.read()
|
||||
data = xxtea.decrypt(data, b"6uJL0SF5CQQuPZoW", padding=False)
|
||||
with open(fn, 'wb') as f:
|
||||
f.write(data)
|
||||
print(f"Decrypted {fn}")
|
||||
|
||||
def remove_unneed(fn: str):
|
||||
with open(fn, 'r', encoding='utf-8') as f:
|
||||
data = load(f)
|
||||
re = []
|
||||
for i in data['FileReferences']['Textures']:
|
||||
if i.endswith(".pvr.ccz"):
|
||||
re.append(i[0:-8] + '.png')
|
||||
else:
|
||||
re.append(i)
|
||||
data['FileReferences']['Textures'] = re
|
||||
with open(fn, 'w', encoding='utf-8') as f:
|
||||
dump(data, f)
|
||||
print('Removed unneeded files from', fn)
|
||||
|
||||
ap = ArgumentParser()
|
||||
ap.add_argument('DIR', help='Input Directory')
|
||||
args = ap.parse_args()
|
||||
for (root, dirname, filename) in os.walk(args.DIR[0]):
|
||||
for fn in filename:
|
||||
ext = splitext(fn)[1].lower()
|
||||
if ext in ['.jpg', '.jpeg', '.png']:
|
||||
try_decode(join(root, fn))
|
||||
elif fn.endswith('.model3.json'):
|
||||
remove_unneed(join(root, fn))
|
||||
elif fn.endswith('.pvr.ccz'):
|
||||
os.remove(join(root, fn))
|
||||
print('Removed', fn)
|
||||
Reference in New Issue
Block a user