bep40 commited on
Commit
613a0ca
·
verified ·
1 Parent(s): 98e2122

Restore 100% of 179cea282 + keep youtube FPT Play video feed

Browse files
Files changed (1) hide show
  1. app_v2_entry.py +7 -25
app_v2_entry.py CHANGED
@@ -968,42 +968,26 @@ def _is_auto_post(p):
968
  source in ("hot_short", "fptplay", "ai", "auto_rewrite", "topic_article")
969
 
970
  def _created_ts(p):
971
- """Best-effort creation timestamp normalized to a common millisecond scale
972
- so all posts sort correctly regardless of how `created` / id was stored.
973
-
974
- Timeline sources:
975
- - p.created / p.ts : may be seconds(10d), ms(13d), or us(16d) epoch
976
- - p.id : numeric ms/microsecond timestamp for auto_rewrite
977
- posts that omit `created`
978
-
979
- Returns milliseconds-since-epoch (int) for a consistent sort key."""
980
  for field in ("created", "ts"):
981
  v = p.get(field)
982
  if v is not None:
983
  try:
984
- n = int(v)
985
- return _normalize_epoch(n)
986
  except (ValueError, TypeError):
987
  pass
 
988
  pid = str(p.get("id", "")).strip()
989
  if pid.isdigit() and len(pid) >= 12:
990
  try:
991
- return _normalize_epoch(int(pid))
992
  except (ValueError, TypeError):
993
  pass
994
  return 0
995
 
996
- def _normalize_epoch(n):
997
- """Normalize a bare epoch number to milliseconds.
998
- < 1e11 -> seconds (×1000)
999
- < 1e14 -> milliseconds (as-is)
1000
- >= 1e14 -> microseconds (÷1000)"""
1001
- if n < 10_000_000_000: # 10 digits → seconds
1002
- return n * 1000
1003
- if n < 100_000_000_000_00: # 13 digits → milliseconds
1004
- return n
1005
- return n // 1000 # 16 digits → microseconds → ms
1006
-
1007
  def _wall_posts_for_view():
1008
  """Apply the user-facing wall filtering + sorting:
1009
  1) Hide auto-generated posts that have a wrong/placeholder image (no
@@ -1140,8 +1124,6 @@ def api_yt_feed(channel_id: str = Query(default="UC4LvrpNXujjbGOS4RDvr41g")):
1140
  Returns parsed feed videos as JSON for the Tường AI wall."""
1141
  videos = _fetch_youtube_rss_feed(channel_id)
1142
  return JSONResponse({"videos": videos, "count": len(videos)})
1143
-
1144
-
1145
  @app.post("/api/ai/short/{post_id}")
1146
  def api_ai_short(post_id: str):
1147
  """Generate a short video for a wall post.
 
968
  source in ("hot_short", "fptplay", "ai", "auto_rewrite", "topic_article")
969
 
970
  def _created_ts(p):
971
+ """Best-effort creation timestamp. Posts created by the AI pipeline often
972
+ store `created` as a millisecond epoch; some older posts (auto_rewrite)
973
+ omit it and instead embed the timestamp in the `id` (Unix ms). Fall back
974
+ to 0 so sorting never crashes."""
 
 
 
 
 
975
  for field in ("created", "ts"):
976
  v = p.get(field)
977
  if v is not None:
978
  try:
979
+ return int(v)
 
980
  except (ValueError, TypeError):
981
  pass
982
+ # try to derive from id (numeric prefix = Unix ms timestamp)
983
  pid = str(p.get("id", "")).strip()
984
  if pid.isdigit() and len(pid) >= 12:
985
  try:
986
+ return int(pid)
987
  except (ValueError, TypeError):
988
  pass
989
  return 0
990
 
 
 
 
 
 
 
 
 
 
 
 
991
  def _wall_posts_for_view():
992
  """Apply the user-facing wall filtering + sorting:
993
  1) Hide auto-generated posts that have a wrong/placeholder image (no
 
1124
  Returns parsed feed videos as JSON for the Tường AI wall."""
1125
  videos = _fetch_youtube_rss_feed(channel_id)
1126
  return JSONResponse({"videos": videos, "count": len(videos)})
 
 
1127
  @app.post("/api/ai/short/{post_id}")
1128
  def api_ai_short(post_id: str):
1129
  """Generate a short video for a wall post.