change: 抽象analyze类
This commit is contained in:
parent
8637f2b373
commit
e9d4317a07
31
analyze.py
Normal file
31
analyze.py
Normal 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
30
main.py
|
@ -1,9 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import xml.etree.ElementTree as ET
|
|
||||||
from utils.LoggerUtil import Logger
|
from utils.LoggerUtil import Logger
|
||||||
from tmdb import Tmdb
|
from tmdb import Tmdb
|
||||||
|
from analyze import Analyze
|
||||||
|
|
||||||
|
|
||||||
def __init_logger(log_file="tmdb.log", level="info", back_count=3):
|
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)
|
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):
|
def __execute(dir_path, output, tmdb_token):
|
||||||
__file_paths = []
|
__file_paths = []
|
||||||
log.logger.info("当前执行元数据刮削识别的根文件夹:{0}".format(dir_path))
|
log.logger.info("当前执行元数据刮削识别的根文件夹:{0}".format(dir_path))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user