Channel features: subscribers, new-videos badges, activity-driven sync
- Store subscriber count from YouTube statistics and show it on channel page - Sync 50 videos per channel with playlistItems pagination support - Show per-channel and per-category new-videos counters (2-day window) - Replace hourly videos sync with activity trigger (2h idle) and incremental backfill (hard cap 200 per channel) - Clicking the sidebar new-videos count filters the category feed to recent videos only (new_only) - Update agent-team docs: deploy after green checks
This commit is contained in:
parent
fde9a439df
commit
e10df8dcbd
27 changed files with 1420 additions and 107 deletions
|
|
@ -124,6 +124,133 @@ def test_feed_filters_uncategorized(client, db_session):
|
|||
assert ids == {"vid1", "vid3"}
|
||||
|
||||
|
||||
def _seed_new_only(db_session):
|
||||
"""Two categories: channel A in a category (recent + old video),
|
||||
channel B uncategorized (recent + old video). Published dates are
|
||||
relative to now so the new_videos_window filter is exercised."""
|
||||
now = datetime.now(timezone.utc)
|
||||
channel_a = Channel(youtube_channel_id="chanNewA", title="Channel New A", subscribed=True)
|
||||
channel_b = Channel(youtube_channel_id="chanNewB", title="Channel New B", subscribed=True)
|
||||
db_session.add_all([channel_a, channel_b])
|
||||
db_session.commit()
|
||||
|
||||
category = Category(name="Recent", slug="recent", sort_order=0)
|
||||
db_session.add(category)
|
||||
db_session.commit()
|
||||
|
||||
db_session.execute(channel_categories.insert().values(channel_id=channel_a.id, category_id=category.id))
|
||||
db_session.commit()
|
||||
|
||||
videos = [
|
||||
Video(
|
||||
youtube_video_id="vidRecentA",
|
||||
channel_id=channel_a.id,
|
||||
title="Recent A",
|
||||
published_at=now - timedelta(days=1),
|
||||
youtube_url="https://www.youtube.com/watch?v=vidRecentA",
|
||||
),
|
||||
Video(
|
||||
youtube_video_id="vidOldA",
|
||||
channel_id=channel_a.id,
|
||||
title="Old A",
|
||||
published_at=now - timedelta(days=30),
|
||||
youtube_url="https://www.youtube.com/watch?v=vidOldA",
|
||||
),
|
||||
Video(
|
||||
youtube_video_id="vidRecentB",
|
||||
channel_id=channel_b.id,
|
||||
title="Recent B",
|
||||
published_at=now - timedelta(hours=2),
|
||||
youtube_url="https://www.youtube.com/watch?v=vidRecentB",
|
||||
),
|
||||
Video(
|
||||
youtube_video_id="vidOldB",
|
||||
channel_id=channel_b.id,
|
||||
title="Old B",
|
||||
published_at=now - timedelta(days=30),
|
||||
youtube_url="https://www.youtube.com/watch?v=vidOldB",
|
||||
),
|
||||
]
|
||||
db_session.add_all(videos)
|
||||
db_session.commit()
|
||||
|
||||
return channel_a, channel_b, category, videos
|
||||
|
||||
|
||||
def test_feed_new_only_includes_recent_and_excludes_old(client, db_session):
|
||||
_seed_new_only(db_session)
|
||||
|
||||
resp = client.get("/api/feed?new_only=true").json()
|
||||
|
||||
ids = {i["youtube_video_id"] for i in resp["items"]}
|
||||
assert ids == {"vidRecentA", "vidRecentB"}
|
||||
|
||||
# Without new_only nothing changes: old videos appear as usual.
|
||||
all_ids = {i["youtube_video_id"] for i in client.get("/api/feed").json()["items"]}
|
||||
assert all_ids == {"vidRecentA", "vidOldA", "vidRecentB", "vidOldB"}
|
||||
|
||||
|
||||
def test_feed_new_only_combines_with_category(client, db_session):
|
||||
_, _, category, _ = _seed_new_only(db_session)
|
||||
|
||||
resp = client.get(f"/api/feed?category_id={category.id}&new_only=true").json()
|
||||
|
||||
ids = {i["youtube_video_id"] for i in resp["items"]}
|
||||
assert ids == {"vidRecentA"}
|
||||
|
||||
|
||||
def test_feed_new_only_excludes_unsubscribed_channels(client, db_session):
|
||||
now = datetime.now(timezone.utc)
|
||||
channel = Channel(youtube_channel_id="chanUnsub", title="Channel Unsub", subscribed=False)
|
||||
db_session.add(channel)
|
||||
db_session.commit()
|
||||
db_session.add(
|
||||
Video(
|
||||
youtube_video_id="vidFreshUnsub",
|
||||
channel_id=channel.id,
|
||||
title="Fresh Unsub",
|
||||
published_at=now - timedelta(hours=2),
|
||||
youtube_url="https://www.youtube.com/watch?v=vidFreshUnsub",
|
||||
)
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
resp = client.get("/api/feed?new_only=true").json()
|
||||
assert resp["items"] == []
|
||||
|
||||
# Regular feed is not filtered by subscription.
|
||||
all_ids = {i["youtube_video_id"] for i in client.get("/api/feed").json()["items"]}
|
||||
assert all_ids == {"vidFreshUnsub"}
|
||||
|
||||
|
||||
def test_feed_new_only_pagination_cursor_works_in_filtered_set(client, db_session):
|
||||
now = datetime.now(timezone.utc)
|
||||
channel = Channel(youtube_channel_id="chanPage", title="Channel Page", subscribed=True)
|
||||
db_session.add(channel)
|
||||
db_session.commit()
|
||||
db_session.add_all(
|
||||
[
|
||||
Video(
|
||||
youtube_video_id=f"vidNew{i}",
|
||||
channel_id=channel.id,
|
||||
title=f"Video New {i}",
|
||||
published_at=now - timedelta(hours=i),
|
||||
youtube_url=f"https://www.youtube.com/watch?v=vidNew{i}",
|
||||
)
|
||||
for i in range(3)
|
||||
]
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
page1 = client.get("/api/feed?new_only=true&limit=2").json()
|
||||
assert [i["youtube_video_id"] for i in page1["items"]] == ["vidNew0", "vidNew1"]
|
||||
assert page1["next_cursor"] is not None
|
||||
|
||||
page2 = client.get(f"/api/feed?new_only=true&limit=2&cursor={page1['next_cursor']}").json()
|
||||
assert [i["youtube_video_id"] for i in page2["items"]] == ["vidNew2"]
|
||||
assert page2["next_cursor"] is None
|
||||
|
||||
|
||||
def test_feed_filters_downloaded(client, db_session):
|
||||
_, _, _, videos = _seed(db_session)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue