update
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from pathlib import Path
|
||||
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy.orm import Session, relationship
|
||||
|
||||
@@ -17,6 +19,14 @@ class Video(Base):
|
||||
filePath = Column("file_path", String, nullable=True)
|
||||
profiles = relationship("Profile", secondary=videoProfiles, backref="videos")
|
||||
|
||||
@property
|
||||
def isDownloaded(self) -> bool:
|
||||
return self.filePath is not None
|
||||
|
||||
@property
|
||||
def profileIds(self) -> list[int]:
|
||||
return [p.id for p in self.profiles]
|
||||
|
||||
@classmethod
|
||||
def deleteIfExists(cls, db: Session, youtubeUrl: str, profileId: int | None):
|
||||
if not profileId:
|
||||
@@ -80,6 +90,29 @@ class Video(Base):
|
||||
video.filePath = path
|
||||
db.commit()
|
||||
|
||||
@classmethod
|
||||
def getValidPath(cls, db: Session, videoId: int):
|
||||
video = cls.getById(db, videoId)
|
||||
if not video or not video.filePath:
|
||||
return None, None
|
||||
path = Path(video.filePath)
|
||||
if not path.exists():
|
||||
cls.updateFilePath(db, videoId, None)
|
||||
return None, None
|
||||
return path, video
|
||||
|
||||
@classmethod
|
||||
def deleteServerFile(cls, db: Session, videoId: int) -> bool:
|
||||
video = cls.getById(db, videoId)
|
||||
if not video:
|
||||
return False
|
||||
if video.filePath:
|
||||
path = Path(video.filePath)
|
||||
if path.exists():
|
||||
path.unlink()
|
||||
cls.updateFilePath(db, videoId, None)
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def deleteNotDownloaded(cls, db: Session, profileId: int, excludeIds: list[int] | None = None) -> int:
|
||||
query = db.query(cls).filter(
|
||||
|
||||
Reference in New Issue
Block a user