You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB

from entity.DownloadInfoEntity import DownloadInfo
from common.Utils import getSession
from sqlalchemy import update
class DownloadInfoService:
def getOneNoFinish():
session = getSession()
downloadInfo = session.query(DownloadInfo).filter(
DownloadInfo.isFinished == 0, DownloadInfo.tryTime <= 2).first()
session.close()
return downloadInfo
def getOneByVideoId(videoId):
session = getSession()
downloadInfo = session.query(DownloadInfo).filter(
DownloadInfo.videoId == videoId).one_or_none()
session.close()
return downloadInfo
def updateIsFinishByVideoId(videoId, tryTime, isFinish):
session = getSession()
updateSql = update(DownloadInfo).where(
DownloadInfo.videoId == videoId).values(tryTime=tryTime, isFinished=isFinish)
resutl = session.execute(updateSql)
session.commit()
session.close()
def insertOne(videoId):
session = getSession()
downloadInfo: DownloadInfo = DownloadInfo(videoId=videoId, downloadType=1,
tryTime=0, isFinished=0)
session.add(downloadInfo)
session.commit()
session.close()