mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
feat:弱引用单例
This commit is contained in:
@@ -7,19 +7,19 @@ from ruamel.yaml import CommentedMap
|
||||
|
||||
from app.core.config import settings
|
||||
from app.log import logger
|
||||
from app.utils.singleton import Singleton
|
||||
from app.utils.singleton import WeakSingleton
|
||||
|
||||
|
||||
class CategoryHelper(metaclass=Singleton):
|
||||
class CategoryHelper(metaclass=WeakSingleton):
|
||||
"""
|
||||
二级分类
|
||||
"""
|
||||
_categorys = {}
|
||||
_movie_categorys = {}
|
||||
_tv_categorys = {}
|
||||
|
||||
def __init__(self):
|
||||
self._category_path: Path = settings.CONFIG_PATH / "category.yaml"
|
||||
self._categorys = {}
|
||||
self._movie_categorys = {}
|
||||
self._tv_categorys = {}
|
||||
self.init()
|
||||
|
||||
def init(self):
|
||||
@@ -69,7 +69,7 @@ class CategoryHelper(metaclass=Singleton):
|
||||
"""
|
||||
if not self._movie_categorys:
|
||||
return []
|
||||
return self._movie_categorys.keys()
|
||||
return list(self._movie_categorys.keys())
|
||||
|
||||
@property
|
||||
def tv_categorys(self) -> list:
|
||||
@@ -78,7 +78,7 @@ class CategoryHelper(metaclass=Singleton):
|
||||
"""
|
||||
if not self._tv_categorys:
|
||||
return []
|
||||
return self._tv_categorys.keys()
|
||||
return list(self._tv_categorys.keys())
|
||||
|
||||
def get_movie_category(self, tmdb_info) -> str:
|
||||
"""
|
||||
@@ -127,7 +127,7 @@ class CategoryHelper(metaclass=Singleton):
|
||||
continue
|
||||
elif attr == "production_countries":
|
||||
# 制片国家
|
||||
info_values = [str(val.get("iso_3166_1")).upper() for val in info_value]
|
||||
info_values = [str(val.get("iso_3166_1")).upper() for val in info_value] # type: ignore
|
||||
else:
|
||||
if isinstance(info_value, list):
|
||||
info_values = [str(val).upper() for val in info_value]
|
||||
|
||||
@@ -9,7 +9,7 @@ from typing import Optional
|
||||
from app.core.config import settings
|
||||
from app.core.meta import MetaBase
|
||||
from app.log import logger
|
||||
from app.utils.singleton import Singleton
|
||||
from app.utils.singleton import WeakSingleton
|
||||
from app.schemas.types import MediaType
|
||||
|
||||
lock = RLock()
|
||||
@@ -18,7 +18,7 @@ CACHE_EXPIRE_TIMESTAMP_STR = "cache_expire_timestamp"
|
||||
EXPIRE_TIMESTAMP = settings.CONF.meta
|
||||
|
||||
|
||||
class TmdbCache(metaclass=Singleton):
|
||||
class TmdbCache(metaclass=WeakSingleton):
|
||||
"""
|
||||
TMDB缓存数据
|
||||
{
|
||||
@@ -28,9 +28,6 @@ class TmdbCache(metaclass=Singleton):
|
||||
"type": MediaType
|
||||
}
|
||||
"""
|
||||
_meta_data: dict = {}
|
||||
# 缓存文件路径
|
||||
_meta_path: Path = None
|
||||
# TMDB缓存过期
|
||||
_tmdb_cache_expire: bool = True
|
||||
|
||||
@@ -218,3 +215,6 @@ class TmdbCache(metaclass=Singleton):
|
||||
if not cache_media_info:
|
||||
return
|
||||
self._meta_data[key]['title'] = cn_title
|
||||
|
||||
def __del__(self):
|
||||
self.save()
|
||||
|
||||
Reference in New Issue
Block a user