diff --git a/analyze.py b/analyze.py new file mode 100644 index 0000000..a18a946 --- /dev/null +++ b/analyze.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import xml.etree.ElementTree as ET + + +class Analyze: + def __init__(self, file_path): + self.file_path = file_path + + def analyze(self): + tree = ET.parse(self.file_path) + root = tree.getroot() + if "tvshow" in root.tag: + data_json = {} + self.__list_nodes(root, data_json) + return data_json + if "movie" in root.tag: + data_json = {} + self.__list_nodes(root, data_json) + return data_json + + def __list_nodes(self, root, data): + actors = [] + for node in root: + if 0 == len(list(node)): + data[node.tag] = node.text + elif "actor" == node.tag: + actor_json = {} + self.__list_nodes(node, actor_json) + actors.append(actor_json) + data["actors"] = actors diff --git a/main.py b/main.py index c9cc393..d167b40 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- import os -import xml.etree.ElementTree as ET from utils.LoggerUtil import Logger from tmdb import Tmdb +from analyze import Analyze def __init_logger(log_file="tmdb.log", level="info", back_count=3): @@ -23,34 +23,6 @@ def __init_logger(log_file="tmdb.log", level="info", back_count=3): return Logger(log_file_abspath, level=level, backCount=back_count) -class Analyze: - def __init__(self, file_path): - self.file_path = file_path - - def analyze(self): - tree = ET.parse(self.file_path) - root = tree.getroot() - if "tvshow" in root.tag: - data_json = {} - self.__list_nodes(root, data_json) - return data_json - if "movie" in root.tag: - data_json = {} - self.__list_nodes(root, data_json) - return data_json - - def __list_nodes(self, root, data): - actors = [] - for node in root: - if 0 == len(list(node)): - data[node.tag] = node.text - elif "actor" == node.tag: - actor_json = {} - self.__list_nodes(node, actor_json) - actors.append(actor_json) - data["actors"] = actors - - def __execute(dir_path, output, tmdb_token): __file_paths = [] log.logger.info("当前执行元数据刮削识别的根文件夹:{0}".format(dir_path))