import chromadb from config import SanatanConfig from db import SanatanDatabase config = SanatanConfig() YT_METADATA_COLLECTION_NAME = config.get_collection_name(scripture_name="yt_metadata") db = SanatanDatabase() def get_youtube_metadata_collection(): client = db.chroma_client return client.get_or_create_collection(YT_METADATA_COLLECTION_NAME) def get_indexed_channels(): collection=get_youtube_metadata_collection() results = collection.get(include=["metadatas"]) channels = {} for meta in results["metadatas"]: cid = meta.get("channel_id") # ✅ safe cname = meta.get("channel_title", "Unknown Channel") if cid: # only include if we have a channel_id channels[cid] = cname # print("channels= ",channels) return channels # ------------------------------- # Delete a channel # ------------------------------- def delete_channel_from_collection(channel_id: str): """Remove a channel from the index and refresh the radio choices.""" # Delete all videos for this channel # print("Deleting channel", channel_id) # print("data = ", data) get_youtube_metadata_collection().delete(where={"channel_id": channel_id}) def fetch_channel_data(channel_id: str): data = get_youtube_metadata_collection().get( where={"channel_id": channel_id}, include=["embeddings", "metadatas", "documents"] ) return data