mirror of
https://github.com/bnair123/MusicAnalyser.git
synced 2026-02-25 19:56:06 +00:00
- Created FastAPI backend structure. - Implemented Spotify Recently Played ingestion logic. - Set up SQLite database with SQLAlchemy models. - Added AI Service using Google Gemini. - Created helper scripts for auth and background worker. - Added Dockerfile and GitHub Actions workflow.
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
from sqlalchemy import Column, Integer, String, DateTime, JSON, ForeignKey, Boolean
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from .database import Base
|
|
|
|
class Track(Base):
|
|
__tablename__ = "tracks"
|
|
|
|
id = Column(String, primary_key=True, index=True) # Spotify ID
|
|
name = Column(String)
|
|
artist = Column(String)
|
|
album = Column(String)
|
|
duration_ms = Column(Integer)
|
|
popularity = Column(Integer, nullable=True)
|
|
|
|
# Store raw full JSON response for future-proofing analysis
|
|
raw_data = Column(JSON, nullable=True)
|
|
|
|
# AI Analysis fields
|
|
lyrics_summary = Column(String, nullable=True)
|
|
genre_tags = Column(String, nullable=True) # JSON list stored as string or just raw JSON
|
|
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
plays = relationship("PlayHistory", back_populates="track")
|
|
|
|
|
|
class PlayHistory(Base):
|
|
__tablename__ = "play_history"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
track_id = Column(String, ForeignKey("tracks.id"))
|
|
played_at = Column(DateTime, index=True) # The timestamp from Spotify
|
|
|
|
# Context (album, playlist, etc.)
|
|
context_uri = Column(String, nullable=True)
|
|
|
|
track = relationship("Track", back_populates="plays")
|