import sys, os import xml.etree.ElementTree as ET def main(): # list file in directory CheckDir(path) dryrun = False def CheckDir(path): # if dir has nfo file path2 = os.path.join(path, "") for root, dirs, files in os.walk(path): for name in dirs: # print(name) orgpath = os.path.join(root, name) fullpath = orgpath if "Unknown" in name: # name = name.replace("Ai Iijima", baseinfo["actress"]) if not dryrun: newpath = os.path.join(root, name) os.rename(orgpath, newpath) fullpath = newpath # print("orgpath= {0}, newpath={1}".format(orgpath, newpath)) # print("name= {0}, path={1}".format(name, subdir)) procesSubdir(fullpath) rootdir = "/Volumes/Docker/Syncthing/config/Sync" path = os.path.join(rootdir, "manualsort") baseinfo = {} baseinfo["actress"] = "@Unknown" baseinfo["altname"] = "Ai Iijima" def procesSubdir(path): hasnfo = False for root, dirs, files in os.walk(path): for name in files: fullpath = os.path.join(root, name) if ".nfo" in name: hasnfo = True setnfofile(root, fullpath) # create nfo file withe same filename as mediafile\ # setnfofile def setnfofile(root, nfofile): # # # add baseinfo into nfo file root, basename = os.path.split(root) # print(basename) # print("root= {0} basename={1}".format(root, basename)) tree = ET.parse(nfofile) xmlroot = tree.getroot() for title in xmlroot.findall("title"): title.text = basename # Create a new element new_element = ET.Element("tag") new_element.text = "uncensored" # tag = xmlroot.findall("tag") xmlroot.append(new_element) new_element = ET.Element("tag") new_element.text = "subtitled" # tag = xmlroot.findall("tag") xmlroot.append(new_element) if not dryrun: print("writing") tree.write(nfofile) # for actor in xmlroot.findall("actor"): # name = actor.find("name") # if name.text == "ai iijima": # name.text = baseinfo["actress"] # altname = actor.find("altname") # altname.text = baseinfo["altname"] # print(ET.tostring(actor)) # for actor in xmlroot.findall("actor"): # name = actor.find("name") # if name.text == "Unknown": # name.text = baseinfo["actress"] # altname = actor.find("altname") # altname.text = baseinfo["altname"] # # print(ET.tostring(actor)) # if not dryrun: # tree.write(nfofile) # print(xmlroot) # for root, dirs, files in os.walk(root): # for name in dirs: # print(name) # print(root) # def tryscrape(): # def getcover(): if __name__ == "__main__": main()