add 下载历史记录
This commit is contained in:
32
app/db/downloadhistory_oper.py
Normal file
32
app/db/downloadhistory_oper.py
Normal file
@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from app.db import DbOper
|
||||
from app.db.models.downloadhistory import DownloadHistory
|
||||
|
||||
|
||||
class DownloadHistoryOper(DbOper):
|
||||
"""
|
||||
插件数据管理
|
||||
"""
|
||||
|
||||
def get_by_path(self, path: Path) -> Any:
|
||||
"""
|
||||
按路径查询下载记录
|
||||
:param path: 数据key
|
||||
"""
|
||||
return DownloadHistory.get_by_path(self._db, path)
|
||||
|
||||
def get_by_hash(self, download_hash: str) -> Any:
|
||||
"""
|
||||
按Hash查询下载记录
|
||||
:param download_hash: 数据key
|
||||
"""
|
||||
return DownloadHistory.get_by_hash(self._db, download_hash)
|
||||
|
||||
def add(self, **kwargs):
|
||||
"""
|
||||
新增下载历史
|
||||
"""
|
||||
downloadhistory = DownloadHistory(**kwargs)
|
||||
return downloadhistory.create(self._db)
|
31
app/db/models/downloadhistory.py
Normal file
31
app/db/models/downloadhistory.py
Normal file
@ -0,0 +1,31 @@
|
||||
from sqlalchemy import Column, Integer, String, Sequence
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.db.models import Base
|
||||
|
||||
|
||||
class DownloadHistory(Base):
|
||||
"""
|
||||
下载历史记录
|
||||
"""
|
||||
id = Column(Integer, Sequence('id'), primary_key=True, index=True)
|
||||
path = Column(String, nullable=False, index=True)
|
||||
type = Column(String, nullable=False)
|
||||
title = Column(String, nullable=False)
|
||||
year = Column(String)
|
||||
tmdbid = Column(Integer, index=True)
|
||||
imdbid = Column(String)
|
||||
tvdbid = Column(Integer)
|
||||
doubanid = Column(String)
|
||||
seasons = Column(Integer)
|
||||
episodes = Column(String)
|
||||
image = Column(String)
|
||||
download_hash = Column(String, index=True)
|
||||
torrent_name = Column(String)
|
||||
torrent_description = Column(String)
|
||||
torrent_site = Column(String)
|
||||
note = Column(String)
|
||||
|
||||
@staticmethod
|
||||
def get_by_hash(db: Session, download_hash: str):
|
||||
return db.query(DownloadHistory).filter(DownloadHistory.download_hash == download_hash).first()
|
Reference in New Issue
Block a user