SalexAI commited on
Commit
7aef717
·
verified ·
1 Parent(s): 9243edd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -2
app.py CHANGED
@@ -31,7 +31,7 @@ INDEX_FILE = os.path.join(DATA_ROOT, "index.json")
31
  os.makedirs(VIDEO_DIR, exist_ok=True)
32
 
33
  # --------------------------------------------------
34
- # Album → Publisher mapping
35
  # --------------------------------------------------
36
  ALBUM_PUBLISHERS = {
37
  "B2c5n8hH4uWRoAW": "Alex Rose",
@@ -42,6 +42,18 @@ ALBUM_PUBLISHERS = {
42
  "B2c5ON9t3uz8kT7": "Cole Vandepoll",
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  # --------------------------------------------------
46
  # HTTP client
47
  # --------------------------------------------------
@@ -129,6 +141,39 @@ def save_index(data: dict):
129
  with open(INDEX_FILE, "w", encoding="utf-8") as f:
130
  json.dump(data, f, indent=2)
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  # --------------------------------------------------
133
  # Downloader
134
  # --------------------------------------------------
@@ -155,7 +200,7 @@ async def poll_album(token: str):
155
  known = {v["id"] for v in index["videos"]}
156
 
157
  publisher = ALBUM_PUBLISHERS.get(token, "Unknown")
158
- category = publisher
159
 
160
  album_dir = os.path.join(VIDEO_DIR, token)
161
  os.makedirs(album_dir, exist_ok=True)
@@ -212,6 +257,9 @@ async def poll_album(token: str):
212
  # --------------------------------------------------
213
  @app.on_event("startup")
214
  async def start_polling():
 
 
 
215
  async def loop():
216
  while True:
217
  for token in ALBUM_PUBLISHERS:
 
31
  os.makedirs(VIDEO_DIR, exist_ok=True)
32
 
33
  # --------------------------------------------------
34
+ # Album → Publisher mapping (who made it)
35
  # --------------------------------------------------
36
  ALBUM_PUBLISHERS = {
37
  "B2c5n8hH4uWRoAW": "Alex Rose",
 
42
  "B2c5ON9t3uz8kT7": "Cole Vandepoll",
43
  }
44
 
45
+ # --------------------------------------------------
46
+ # Album → Category mapping (what kind of content it is)
47
+ # --------------------------------------------------
48
+ ALBUM_CATEGORIES = {
49
+ "B2c5n8hH4uWRoAW": "Fun",
50
+ "B2c5yeZFhHXzdFg": "Rockets",
51
+ "B2cGI9HKKtaAF3T": "Sam Content Library",
52
+ "B2c59UlCquMMGkJ": "Serious",
53
+ "B2cJ0DiRHusi12z": "Music",
54
+ "B2c5ON9t3uz8kT7": "Cole Content Creator", # "Same as Cole's profile"
55
+ }
56
+
57
  # --------------------------------------------------
58
  # HTTP client
59
  # --------------------------------------------------
 
141
  with open(INDEX_FILE, "w", encoding="utf-8") as f:
142
  json.dump(data, f, indent=2)
143
 
144
+ def backfill_index_categories():
145
+ """
146
+ Fix previously cached entries that used the old bug:
147
+ category == publisher (or category missing).
148
+
149
+ After this runs once, your /feed/videos will be correct even
150
+ if you already had index.json created before the category fix.
151
+ """
152
+ try:
153
+ idx = load_index()
154
+ changed = False
155
+
156
+ for v in idx.get("videos", []):
157
+ token = v.get("source_album", "")
158
+ correct_category = ALBUM_CATEGORIES.get(token, "Uncategorized")
159
+ correct_publisher = ALBUM_PUBLISHERS.get(token, "Unknown")
160
+
161
+ # Ensure publisher is correct too (safe cleanup)
162
+ if v.get("publisher") in (None, "", "Unknown") and correct_publisher != "Unknown":
163
+ v["publisher"] = correct_publisher
164
+ changed = True
165
+
166
+ # Fix category if missing or wrong
167
+ if v.get("category") in (None, "", v.get("publisher")) or v.get("category") != correct_category:
168
+ v["category"] = correct_category
169
+ changed = True
170
+
171
+ if changed:
172
+ save_index(idx)
173
+ logging.info("Backfilled index.json categories/publishers")
174
+ except Exception:
175
+ logging.exception("Backfill failed (non-fatal)")
176
+
177
  # --------------------------------------------------
178
  # Downloader
179
  # --------------------------------------------------
 
200
  known = {v["id"] for v in index["videos"]}
201
 
202
  publisher = ALBUM_PUBLISHERS.get(token, "Unknown")
203
+ category = ALBUM_CATEGORIES.get(token, "Uncategorized")
204
 
205
  album_dir = os.path.join(VIDEO_DIR, token)
206
  os.makedirs(album_dir, exist_ok=True)
 
257
  # --------------------------------------------------
258
  @app.on_event("startup")
259
  async def start_polling():
260
+ # Fix any old cached feed entries first
261
+ backfill_index_categories()
262
+
263
  async def loop():
264
  while True:
265
  for token in ALBUM_PUBLISHERS: