Nodes/Story JSON Nodes/YouTube Trend Topics
ComfyUI Node

YouTube Trend Topics

Mine real trending YouTube titles for short-video ideas

By stepan-bogatorjov·Created 6 months ago·Updated 2 months ago· 0
YouTube Trend Topics
    • topics_json
    • topics_text
    ◄api_key►
    ◄querywhat happens inside►
    ◄region_codeUS►
    ◄max_results25►
    ◄published_after_days7►
    ◄orderviewCount►
    ◄video_durationshort►
    ◄safe_searchmoderate►
    ◄languageen►
    ◄category_filter►
    ◄min_views0►
    ◄exclude_keywords►
    ◄include_keywords►
    ◄prefer_shortstrue►
    ◄output_formatjson►

    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_KEY env var or a .env file (there's an .env.example in 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, or relevance.
    • 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.

    Categoryyoutube

    Inputs (15)

    NameTypeDefaultDescription
    api_keySTRING—
    querySTRINGwhat happens inside—
    region_codeSTRINGUS—
    max_resultsINT251–50—
    published_after_daysINT71–365—
    orderCOMBOviewCount3 options: relevance, date, viewCount
    video_durationCOMBOshort4 options: any, short, medium, long
    safe_searchCOMBOmoderate3 options: none, moderate, strict
    languageCOMBOen11 options: any, en, ru, es, fr, de, +5
    category_filteroptSTRING—
    min_viewsoptINT00–1000000000—
    exclude_keywordsoptSTRING—
    include_keywordsoptSTRING—
    prefer_shortsoptBOOLEANtrue—
    output_formatoptCOMBOjson2 options: json, text

    Outputs (2)

    NameTypeDescription
    topics_jsonSTRING—
    topics_textSTRING—