@danhachuel/thunderbolt 0.4.66 → 0.4.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app/main.py +22 -20
  2. package/package.json +1 -1
package/app/main.py CHANGED
@@ -1855,8 +1855,20 @@ def format_metric_number(value: Any) -> str:
1855
1855
  return str(value)
1856
1856
 
1857
1857
 
1858
+ def classify_channel_platform(channel: Any) -> str:
1859
+ """Return the persisted platform, or unknown when it is not explicit."""
1860
+ if not isinstance(channel, dict):
1861
+ return "unknown"
1862
+ value = str(channel.get("platform") or "").strip().casefold().replace(" ", "")
1863
+ if value in {"youtube", "yt"}:
1864
+ return "youtube"
1865
+ if value in {"tiktok", "tik-tok", "tt"}:
1866
+ return "tiktok"
1867
+ return "unknown"
1868
+
1869
+
1858
1870
  def _tiktok_channel_records() -> list[dict[str, Any]]:
1859
- return [channel for channel in read_json("channels.json", []) if isinstance(channel, dict) and channel.get("platform") == "tiktok"]
1871
+ return [channel for channel in read_json("channels.json", []) if classify_channel_platform(channel) == "tiktok"]
1860
1872
 
1861
1873
 
1862
1874
  def _tiktok_avatar_url(value: dict[str, Any]) -> str:
@@ -2087,22 +2099,8 @@ def render_tiktok_channels():
2087
2099
  st.success("Canal TikTok cadastrado.")
2088
2100
  st.rerun()
2089
2101
  def is_youtube_channel_record(channel: Any) -> bool:
2090
- """Return whether a persisted channel belongs in the YouTube UI."""
2091
- if not isinstance(channel, dict):
2092
- return False
2093
- platform = str(channel.get("platform") or "").strip().casefold().replace(" ", "")
2094
- if "tiktok" in platform or platform in {"tik-tok", "tt"}:
2095
- return False
2096
- def contains_tiktok_marker(value: Any) -> bool:
2097
- if isinstance(value, dict):
2098
- return any(contains_tiktok_marker(key) or contains_tiktok_marker(item) for key, item in value.items())
2099
- if isinstance(value, (list, tuple, set)):
2100
- return any(contains_tiktok_marker(item) for item in value)
2101
- return "tiktok" in str(value or "").strip().casefold().replace(" ", "") or str(value or "").strip().casefold() == "tik-tok"
2102
-
2103
- if contains_tiktok_marker(channel):
2104
- return False
2105
- return True
2102
+ """Return whether a persisted channel is explicitly identified as YouTube."""
2103
+ return classify_channel_platform(channel) == "youtube"
2106
2104
 
2107
2105
 
2108
2106
  def render_channels():
@@ -2216,6 +2214,7 @@ def render_channels():
2216
2214
  "video_count": int(video_count) or None,
2217
2215
  "view_count": int(view_count) or None,
2218
2216
  "metrics_source": imported.get("metrics_source", "youtube_public_page"),
2217
+ "platform": "youtube",
2219
2218
  }
2220
2219
  channel = create_channel(name, url, metadata)
2221
2220
  st.success(f"Canal {channel['name']} guardado.")
@@ -2349,6 +2348,7 @@ def render_channels():
2349
2348
  "metrics_source": "spreadsheet",
2350
2349
  "import_source": "spreadsheet",
2351
2350
  "description_source": description_status,
2351
+ "platform": "youtube",
2352
2352
  }
2353
2353
  created = create_channel(str(row.get("name") or "").strip(), str(row.get("url") or "").strip(), metadata)
2354
2354
  current_channels.append(created)
@@ -2496,6 +2496,7 @@ def render_channels():
2496
2496
  "language": batch_language,
2497
2497
  "style_wide": style_value,
2498
2498
  "last_youtube_sync": now(),
2499
+ "platform": "youtube",
2499
2500
  })
2500
2501
  created_names.append(data.get("name", channel_id))
2501
2502
  except Exception as exc:
@@ -2559,6 +2560,7 @@ def render_channels():
2559
2560
  "video_count": int(video_count) or None,
2560
2561
  "view_count": int(view_count) or None,
2561
2562
  "metrics_source": "manual",
2563
+ "platform": "youtube",
2562
2564
  })
2563
2565
  st.success(f"Canal {channel['name']} guardado manualmente.")
2564
2566
  st.rerun()
@@ -2861,7 +2863,7 @@ def render_new_video(page_title: str = "Criação de Vídeos", prefix: str = "ne
2861
2863
  create_tab = tabs[0]
2862
2864
  draft_tab = tabs[1] if len(tabs) > 1 else None
2863
2865
  with create_tab:
2864
- all_channels = [c for c in read_json("channels.json", []) if isinstance(c, dict) and ((channel_platform == "tiktok" and c.get("platform") == "tiktok") or (channel_platform != "tiktok" and c.get("platform", "youtube") != "tiktok"))]
2866
+ all_channels = [c for c in read_json("channels.json", []) if classify_channel_platform(c) == channel_platform]
2865
2867
  active_channels = [c for c in all_channels if c.get("active", True)]
2866
2868
  if not all_channels:
2867
2869
  st.warning("Cadastre pelo menos um canal antes de criar vídeos.")
@@ -4804,7 +4806,7 @@ def render_automation():
4804
4806
  st.caption(f"Última verificação do worker: {last_tick}")
4805
4807
  if worker_status.get("last_error"):
4806
4808
  st.error(f"Último erro do worker: {worker_status['last_error']}")
4807
- channels = [channel for channel in read_json("channels.json", []) if isinstance(channel, dict) and channel.get("platform", "youtube") != "tiktok"]
4809
+ channels = [channel for channel in read_json("channels.json", []) if is_youtube_channel_record(channel)]
4808
4810
  if not channels:
4809
4811
  st.info("Nenhum canal cadastrado para configurar.")
4810
4812
  for channel in channels:
@@ -7900,7 +7902,7 @@ def render_update_youtube_videos():
7900
7902
  st.title("Update Youtube Vídeos")
7901
7903
  st.caption("Actualize título, descrição e thumbnail de vídeos publicados sem alterar o ficheiro de vídeo.")
7902
7904
  settings = read_json("settings.json", {})
7903
- channels = [channel for channel in read_json("channels.json", []) if isinstance(channel, dict) and channel.get("platform", "youtube") != "tiktok" and channel.get("active", True)]
7905
+ channels = [channel for channel in read_json("channels.json", []) if is_youtube_channel_record(channel) and channel.get("active", True)]
7904
7906
  if not channels:
7905
7907
  st.info("Cadastre pelo menos um canal YouTube activo antes de actualizar vídeos.")
7906
7908
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danhachuel/thunderbolt",
3
- "version": "0.4.66",
3
+ "version": "0.4.68",
4
4
  "description": "Thunderbolt — interface local para operação de canais faceless e motor MoneyPrinterTurbo",
5
5
  "license": "MIT",
6
6
  "main": "scripts/cli.mjs",