change: 抽象analyze类

This commit is contained in:
Carol 2023-09-06 14:42:58 +08:00
parent 8637f2b373
commit e9d4317a07
2 changed files with 32 additions and 29 deletions

31
analyze.py Normal file
View File

@ -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

30
main.py
View File

@ -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))