update
This commit is contained in:
@@ -12,6 +12,6 @@ class Video(Base):
|
||||
title = Column(String, nullable=False)
|
||||
youtuber = Column(String, nullable=False)
|
||||
thumbnail_url = Column(String, nullable=False)
|
||||
youtube_url = Column(String, nullable=False, unique=True)
|
||||
youtube_url = Column(String, nullable=False)
|
||||
file_path = Column(String, nullable=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
Binary file not shown.
@@ -13,10 +13,16 @@ from services.download_service import download_video, stream_video_live
|
||||
router = APIRouter(prefix="/videos", tags=["videos"])
|
||||
|
||||
|
||||
@router.post("", response_model=VideoResponse)
|
||||
def create_video(video_data: VideoCreate, db: Session = Depends(get_db)):
|
||||
video = video_service.create_video(db, video_data)
|
||||
return VideoResponse.from_model(video)
|
||||
@router.post("", response_model=list[VideoResponse])
|
||||
def create_videos(videos_data: list[VideoCreate], db: Session = Depends(get_db)):
|
||||
created_ids = []
|
||||
for video_data in reversed(videos_data):
|
||||
video_id_match = video_data.youtube_url.split("v=")[-1].split("&")[0]
|
||||
video_service.delete_by_youtube_id(db, video_id_match)
|
||||
video = video_service.create_video(db, video_data)
|
||||
created_ids.append(video.id)
|
||||
videos = [video_service.get_video(db, vid) for vid in created_ids]
|
||||
return [VideoResponse.from_model(v) for v in videos if v]
|
||||
|
||||
|
||||
@router.get("", response_model=list[VideoResponse])
|
||||
|
||||
Binary file not shown.
@@ -13,17 +13,22 @@ def create_video(db: Session, video_data: VideoCreate) -> Video:
|
||||
|
||||
|
||||
def get_all_videos(db: Session) -> list[Video]:
|
||||
return db.query(Video).order_by(Video.created_at.desc()).all()
|
||||
return db.query(Video).order_by(Video.id.desc()).all()
|
||||
|
||||
|
||||
def get_downloaded_videos(db: Session) -> list[Video]:
|
||||
return db.query(Video).filter(Video.file_path.isnot(None)).order_by(Video.created_at.desc()).all()
|
||||
return db.query(Video).filter(Video.file_path.isnot(None)).order_by(Video.id.desc()).all()
|
||||
|
||||
|
||||
def get_video(db: Session, video_id: int) -> Video | None:
|
||||
return db.query(Video).filter(Video.id == video_id).first()
|
||||
|
||||
|
||||
def delete_by_youtube_id(db: Session, youtube_id: str):
|
||||
db.query(Video).filter(Video.youtube_url.contains(youtube_id)).delete(synchronize_session=False)
|
||||
db.commit()
|
||||
|
||||
|
||||
def update_file_path(db: Session, video_id: int, path: str):
|
||||
video = get_video(db, video_id)
|
||||
if video:
|
||||
|
||||
Reference in New Issue
Block a user