add 转移历史记录
This commit is contained in:
parent
e9e7bcc206
commit
df0ba221f9
@ -3,11 +3,13 @@ from pathlib import Path
|
|||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from app.chain import ChainBase
|
from app.chain import ChainBase
|
||||||
|
from app.core.config import settings
|
||||||
from app.core.context import MediaInfo
|
from app.core.context import MediaInfo
|
||||||
from app.core.meta import MetaBase
|
from app.core.meta import MetaBase
|
||||||
from app.core.metainfo import MetaInfo
|
from app.core.metainfo import MetaInfo
|
||||||
from app.db.downloadhistory_oper import DownloadHistoryOper
|
from app.db.downloadhistory_oper import DownloadHistoryOper
|
||||||
from app.db.models.downloadhistory import DownloadHistory
|
from app.db.models.downloadhistory import DownloadHistory
|
||||||
|
from app.db.transferhistory_oper import TransferHistoryOper
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
from app.schemas import TransferInfo, TransferTorrent
|
from app.schemas import TransferInfo, TransferTorrent
|
||||||
from app.schemas.types import TorrentStatus, EventType, MediaType
|
from app.schemas.types import TorrentStatus, EventType, MediaType
|
||||||
@ -22,6 +24,7 @@ class TransferChain(ChainBase):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.downloadhis = DownloadHistoryOper()
|
self.downloadhis = DownloadHistoryOper()
|
||||||
|
self.transferhis = TransferHistoryOper()
|
||||||
|
|
||||||
def process(self, arg_str: str = None, userid: Union[str, int] = None) -> bool:
|
def process(self, arg_str: str = None, userid: Union[str, int] = None) -> bool:
|
||||||
"""
|
"""
|
||||||
@ -99,7 +102,7 @@ class TransferChain(ChainBase):
|
|||||||
# 更新媒体图片
|
# 更新媒体图片
|
||||||
self.obtain_image(mediainfo=mediainfo)
|
self.obtain_image(mediainfo=mediainfo)
|
||||||
# 转移
|
# 转移
|
||||||
transferinfo: TransferInfo = self.transfer(mediainfo=mediainfo, path=Path(torrent.path))
|
transferinfo: TransferInfo = self.transfer(mediainfo=mediainfo, path=torrent.path)
|
||||||
if not transferinfo or not transferinfo.target_path:
|
if not transferinfo or not transferinfo.target_path:
|
||||||
# 转移失败
|
# 转移失败
|
||||||
logger.warn(f"{torrent.title} 入库失败")
|
logger.warn(f"{torrent.title} 入库失败")
|
||||||
@ -110,6 +113,24 @@ class TransferChain(ChainBase):
|
|||||||
userid=userid
|
userid=userid
|
||||||
),
|
),
|
||||||
continue
|
continue
|
||||||
|
# 新增转移历史记录
|
||||||
|
self.transferhis.add(
|
||||||
|
src=str(torrent.path),
|
||||||
|
dest=str(transferinfo.target_path),
|
||||||
|
mode=settings.TRANSFER_TYPE,
|
||||||
|
type=mediainfo.type.value,
|
||||||
|
category=mediainfo.category,
|
||||||
|
title=mediainfo.title,
|
||||||
|
year=mediainfo.year,
|
||||||
|
tmdbid=mediainfo.tmdb_id,
|
||||||
|
imdbid=mediainfo.imdb_id,
|
||||||
|
tvdbid=mediainfo.tvdb_id,
|
||||||
|
doubanid=mediainfo.douban_id,
|
||||||
|
seasons=meta.season,
|
||||||
|
episodes=meta.episode,
|
||||||
|
image=mediainfo.get_poster_image(),
|
||||||
|
download_hash=torrent.hash
|
||||||
|
)
|
||||||
# 转移完成
|
# 转移完成
|
||||||
self.transfer_completed(hashs=torrent.hash, transinfo=transferinfo)
|
self.transfer_completed(hashs=torrent.hash, transinfo=transferinfo)
|
||||||
# 刮剥
|
# 刮剥
|
||||||
|
@ -7,7 +7,7 @@ from app.db.models.downloadhistory import DownloadHistory
|
|||||||
|
|
||||||
class DownloadHistoryOper(DbOper):
|
class DownloadHistoryOper(DbOper):
|
||||||
"""
|
"""
|
||||||
插件数据管理
|
下载历史管理
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_by_path(self, path: Path) -> Any:
|
def get_by_path(self, path: Path) -> Any:
|
||||||
|
33
app/db/models/transferhistory.py
Normal file
33
app/db/models/transferhistory.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
from sqlalchemy import Column, Integer, String, Sequence
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app.db.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class TransferHistory(Base):
|
||||||
|
"""
|
||||||
|
转移历史记录
|
||||||
|
"""
|
||||||
|
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||||
|
src = Column(String, index=True)
|
||||||
|
dest = Column(String)
|
||||||
|
mode = Column(String)
|
||||||
|
type = Column(String)
|
||||||
|
category = Column(String)
|
||||||
|
title = Column(String, index=True)
|
||||||
|
year = Column(String)
|
||||||
|
tmdbid = Column(Integer)
|
||||||
|
imdbid = Column(String)
|
||||||
|
tvdbid = Column(Integer)
|
||||||
|
doubanid = Column(String)
|
||||||
|
seasons = Column(Integer)
|
||||||
|
episodes = Column(String)
|
||||||
|
image = Column(String)
|
||||||
|
download_hash = Column(String)
|
||||||
|
date = Column(String, index=True, default=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def search_by_title(db: Session, title: str):
|
||||||
|
return db.query(TransferHistory).filter(TransferHistory.title == title).all()
|
24
app/db/transferhistory_oper.py
Normal file
24
app/db/transferhistory_oper.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from app.db import DbOper
|
||||||
|
from app.db.models.transferhistory import TransferHistory
|
||||||
|
|
||||||
|
|
||||||
|
class TransferHistoryOper(DbOper):
|
||||||
|
"""
|
||||||
|
转移历史管理
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_by_title(self, title: str) -> Any:
|
||||||
|
"""
|
||||||
|
按标题查询转移记录
|
||||||
|
:param title: 数据key
|
||||||
|
"""
|
||||||
|
return TransferHistory.search_by_title(self._db, title)
|
||||||
|
|
||||||
|
def add(self, **kwargs):
|
||||||
|
"""
|
||||||
|
新增转移历史
|
||||||
|
"""
|
||||||
|
transferhistory = TransferHistory(**kwargs)
|
||||||
|
return transferhistory.create(self._db)
|
Loading…
x
Reference in New Issue
Block a user