YouTube Trend Topics
Mine real trending YouTube titles for short-video ideas
- topics_json
- topics_text
YoutubeTrendTopics is the ideation stage of the Story JSON Nodes pack (stepan-bogatorjov/comfy_scenes_json_node), and it answers the question the rest of the pack is built around: what story should we generate next? It calls the official YouTube Data API v3 - no scraping, no downloads - pulls recently published videos for your query and region, and returns a ranked list of topic candidates scored for how well they'd work as AI short-video storytelling.
If the pack is a YouTube-shorts factory, this is the market research department. The default query, "what happens inside", is not random: it's a curiosity-stem title pattern the ranking explicitly rewards. The node fetches video stats (views, likes, comments, duration), computes views-per-hour and engagement, and multiplies by a relevance boost derived from the title - patterns like "what happens if", "why you should never", "the hidden truth", "survival", "explained" all add points. Then it filters the noise: music videos, reactions, livestreams, gameplay, podcasts get dropped or heavily penalized. The output is JSON you can feed straight into the story generator.
How it works
Two API calls: search for video IDs in the window, then videos.list for details. Each result is scored (views_per_hour × 0.7 + engagement × 0.2 + recency × 0.1, times the title boost), then filtered by min_views, exclude/include keyword lists, a Shorts preference (clips ≤90s get a boost, >600s get halved), and a hard language re-check via the lingua-language-detector package - because YouTube's relevanceLanguage is only a hint. It never crashes the graph: problems come back as an {"error": ...} JSON plus an ERROR: text line.
The inputs that matter
- api_key - a YouTube Data API v3 key. Leave empty to use a
YOUTUBE_API_KEYenv var or a.envfile (there's an.env.examplein the repo). - query - the search stem ("what happens inside" by default).
- region_code - ISO code, default
US. - max_results - up to 50.
- published_after_days - how far back to look (default 7).
- order -
viewCount,date, orrelevance. - video_duration / safe_search / language - the usual YouTube filters; language defaults to
en. - min_views, exclude_keywords, include_keywords, prefer_shorts, output_format - the ranking and output dials.
- Outputs: topics_json (the full ranked records) and topics_text (a plain "1. title" list). In text mode both outputs mirror the text.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/stepan-bogatorjov/comfy_scenes_json_node
The pack's own dependencies (requests, lingua-language-detector) install with it via Manager. Then get a free YouTube Data API v3 key from the Google Cloud console (APIs & Services → Credentials → Create credentials → API key) - the repo's .env.example is there for exactly this.
Troubleshooting
The key resolution order is input → env var → .env, and the errors are unusually good about telling you which one you skipped - plus, in one of the nicest touches in this pack, if lingua-language-detector is missing the error prints the exact Python interpreter to install it into (the python_embeded problem strikes again). If you get "no videos returned", widen the window or the query; if you get "all fetched videos were filtered out", loosen min_views or exclude_keywords. And keep in mind this is an idea generator, not a fact engine - the scored "topics" are cleaned-up YouTube titles, so treat them as creative prompts for your story pipeline rather than guaranteed hits.
Inputs (15)
| Name | Type | Default | Description |
|---|---|---|---|
| api_key | STRING | — | |
| query | STRING | what happens inside | — |
| region_code | STRING | US | — |
| max_results | INT | 251–50 | — |
| published_after_days | INT | 71–365 | — |
| order | COMBO | viewCount | 3 options: relevance, date, viewCount |
| video_duration | COMBO | short | 4 options: any, short, medium, long |
| safe_search | COMBO | moderate | 3 options: none, moderate, strict |
| language | COMBO | en | 11 options: any, en, ru, es, fr, de, +5 |
| category_filteropt | STRING | — | |
| min_viewsopt | INT | 00–1000000000 | — |
| exclude_keywordsopt | STRING | — | |
| include_keywordsopt | STRING | — | |
| prefer_shortsopt | BOOLEAN | true | — |
| output_formatopt | COMBO | json | 2 options: json, text |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| topics_json | STRING | — |
| topics_text | STRING | — |