update system to use find Highlights *not tested

This commit is contained in:
SumGuyV5 committed 2026-09-25 16:08:07 +00:00
1 parent 38e0cc6764
commit 7c96a5131b
8 files changed
+211 -86

No files matched your search

+41 -6
View File
@@ -1,4 +1,4 @@
from sqlalchemy import create_engine, Column, String, Integer, Boolean, ForeignKey, select
from sqlalchemy import create_engine, Column, String, Integer, Boolean, Float, ForeignKey, select
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
from typing import Any
@@ -35,6 +35,9 @@ class TwitchVideo(Base):
tiktok_info = relationship("TiktokInfo", back_populates="twitch_video", uselist=True)
chapters = relationship("Chapter", back_populates="twitch_video", cascade="all, delete-orphan")
# THIS WAS MISSING - this is what Highlight is looking for
highlights = relationship("Highlight", back_populates="twitch_video", cascade="all, delete-orphan")
# 3. Define the data table
class Data(Base):
__tablename__ = "data"
@@ -45,6 +48,7 @@ class Data(Base):
date_shorts = Column(String, nullable=False)
date_videos = Column(String, nullable=False)
date_videos_chats = Column(String, nullable=False)
date_tiktok = Column(String, nullable=False)
class YoutubeInfo(Base):
__tablename__ = "youtube_info"
@@ -74,6 +78,21 @@ class TiktokInfo(Base):
# Relationship linking back to the twitch video record
twitch_video = relationship("TwitchVideo", back_populates="tiktok_info")
class Highlight(Base):
__tablename__ = "highlights"
id = Column(Integer, primary_key=True, autoincrement=True)
twitch_video_id = Column(String, ForeignKey("twitch_videos.id"), nullable=False)
start_milliseconds = Column(Float, nullable=False)
length_milliseconds = Column(Float, nullable=False)
start_timestamp = Column(String, nullable=False)
end_timestamp = Column(String, nullable=False)
description = Column(String, nullable=False)
score = Column(Float, nullable=False)
# Relationship linking back to the twitch video record
twitch_video = relationship("TwitchVideo", back_populates="highlights")
class Chapter(Base):
__tablename__ = "chapters"
@@ -134,6 +153,10 @@ class Repository:
"""Flags a specific row record to downloaded (1)."""
self.__mark_as(record_id, "downloaded")
def mark_as_uploaded_tiktok(self, record_id: str):
"""Flags a specific row record to uploaded_tiktok (1)."""
self.__mark_as(record_id, "uploaded_tiktok")
def unmark_as_download(self, record_id: str):
"""Flags a specific row record to downloaded (0)."""
self.__mark_as(record_id, "downloaded", False)
@@ -186,6 +209,10 @@ class Repository:
stmt = select(TwitchVideo).where(TwitchVideo.downloaded == False)
return self.session.scalars(stmt).all()
def get_unuploaded_tiktok(self) -> list[TwitchVideo]:
"""Retrieve all rows that were download but not uploaded_tiktok"""
return self.__get_unuploaded("uploaded_tiktok", (TwitchVideo.clip_is == True))
def get_downloaded(self) -> list[TwitchVideo]:
stmt = select(TwitchVideo).where(TwitchVideo.downloaded == True)
return self.session.scalars(stmt).all()
@@ -215,19 +242,19 @@ class Repository:
def update_date_chats(self, date: str):
self.__update_date("date_videos_chat", date)
def get_data(self) -> list[Data]:
def get_data(self) -> Data:
stmt = select(Data)
return self.session.scalars(stmt).all()
return self.session.scalars(stmt).first()
def get_youtube_info_for_video(self, video_id: str) -> list[YoutubeInfo]:
def get_youtube_info_for_video(self, video_id: str) -> YoutubeInfo | None:
"""Retrieve all YouTubeInfo records associated with a specific TwitchVideo ID."""
stmt = select(YoutubeInfo).where(YoutubeInfo.twitch_video_id == video_id)
return self.session.scalars(stmt).all()
return self.session.scalars(stmt).first()
def get_youtube_info_all(self) -> list[YoutubeInfo]:
return self.session.scalars(select(YoutubeInfo)).all()
def insert(self, data: TwitchVideo | Data | YoutubeInfo | Chapter | list[YoutubeInfo] | list[Chapter]):
def insert(self, data: TwitchVideo | Data | YoutubeInfo | Chapter | list[YoutubeInfo] | list[Chapter] | TiktokInfo | Highlight):
"""
Handles insertion/updating for any of the defined models,
using session merge/add for SQLAlchemy 2.0 best practices.
@@ -270,6 +297,14 @@ class Repository:
print(f"➕ Successfully processed {len(data)} records of type {record_type.__name__}.")
else:
raise TypeError(f"Unsupported list content type: {record_type.__name__}")
elif isinstance(data, TiktokInfo):
# Handle single TiktokInfo object
self.session.merge(data)
print(f"➕ TiktokInfo record merged/inserted successfully!")
elif isinstance(data, Highlight):
# Handle single Highlight object
self.session.merge(data)
print(f"➕ Highlight record merged/inserted successfully!")
else:
raise TypeError(f"Unsupported data type for insertion: {type(data).__name__}")