mcpField
Y
YouTube Trends API

YouTube Trends API

リモート
trendsapi.aiデータ・分析12 週間前に更新
リポジトリ公式サイト

YouTube Trends API について

YouTube Trends APIは、YouTubeの検索関心度の履歴、成長率、リアルタイムのトレンドを取得するクライアントライブラリとHTTP APIです。検索関心の推移分析や現在のトレンド追跡を行う開発者向けです。

主な機能

  1. 01キーワード関心度の時系列取得
  2. 02指定期間ごとの成長率測定
  3. 03YouTubeのリアルタイムトレンド取得
  4. 04Python・JavaScript SDKの利用
  5. 05HTTP APIへのアクセス

活用シーン

  1. 01キーワードへの関心の推移を追跡
  2. 02期間ごとのキーワード成長率を比較
  3. 03現在のYouTubeトレンドを確認

設定

リモートサーバーはインストール不要です。クライアントを選んで設定をコピーするか、ワンクリックで導入できます。

エンドポイントhttps://youtube.api.trendsapi.ai/mcp
インストールコマンドをコピー
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

コマンドはターミナルで実行し、JSON は各クライアントの MCP 設定に貼り付けて再起動します。認可が必要なサーバーは初回接続時にログインを求めます。

すべてのエンドポイント
Streamable HTTPhttps://youtube.api.trendsapi.ai/mcp認証が必要

ツール

詳細

YouTube 検索関心度 API

YouTube Trends API による YouTube 検索関心度のトレンドです。履歴、成長率、YouTube のリアルタイムトレンドを確認できます。

License: MIT PyPI Python npm

キー:trendsapi.ai/#get-key。HTTP の仕様とすべてのソース:trendsapi-ai/trendsapi。

認証

pip install trendsapi-youtube
export TRENDSAPI_KEY=your_key

Python 3.9 以降。同じキーを HTTP API に使用します。

from trendsapi_youtube import TrendsAPI

client = TrendsAPI()                    # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")

キーワードヘルパーのデフォルトは source: "youtube" です。同じクライアントで他のプラットフォームにアクセスするには、source= を渡してください。正式なフルクライアント(すべてのソースに対応、プリセットなし):trendsapi。

メソッド

メソッドREST mode戻り値
get_time_series(keyword, source=, data_mode=)get_time_serieslist[TrendsDataPoint]
get_growth(keyword, percent_growth=, source=, data_mode=)get_growthGetGrowthResponse
get_live(limit=, offset=, category=)get_top_trendsGetTopTrendsResponse
get_top_trends(type=, ...)get_top_trendsGetTopTrendsResponse

source は小文字です(youtube)。type は指定どおりの文字列です(YouTube Trending)。これらを混在させると 400 エラーになります。

from trendsapi_youtube import TrendsAPI

client = TrendsAPI()                    # TRENDSAPI_KEY
# client = TrendsAPI(api_key="YOUR_KEY")

series = client.get_time_series("sourdough starter")
print(series[-1].date, series[-1].value)

growth = client.get_growth("sourdough starter", percent_growth=["3M", "12M"])
print(growth.results[0].growth, growth.results[0].direction)

hot = client.get_live(limit=10)
print(hot.data)                         # [[1, "..."], ...]

get_time_series

points = client.get_time_series("sourdough starter")

各データポイント:

フィールド常に含まれる説明
dateはいYYYY-MM-DD
valueはいこの系列の 0~100 の指数
keywordはい指定したキーワード
volumeいいえ入手可能な場合の絶対検索量
source または datatypeいいえパイプラインのラベル

Python は list[TrendsDataPoint] を返します。["date"] ではなく .date と .value を使用してください。 JS は同じフィールドをオブジェクトのプロパティとして返します。

get_growth

g = client.get_growth("sourdough starter", percent_growth=["12M", "3M", "YTD"])
print(g.results[0].growth, g.results[0].direction)

percent_growth のデフォルト値:["12M"]。プリセット:7D 14D 30D 1M 2M 3M 6M 9M 12M/1Y 18M 24M/2Y 36M/3Y 48M 60M/5Y MTD QTD YTD。カスタム指定:{"name": "Launch", "recent": "2024-06-01", "baseline": "2024-01-01"}。

フィールド説明
search_termキーワード
data_sourceソース
results期間ごとに 1 つのオブジェクト(period、growth、direction、日付、値)
metadata件数/成功フラグ

複数の期間を指定しても、リクエスト数は 1 件です。Python:growth.results[0].growth。JS:growth.results[0].growth。

get_live

hot = client.get_live(limit=10)
フィールド説明
as_of_tsスナップショットの時刻
typeフィード名
limit、offset、countページネーション
data[rank, label] 形式の行

Python:hot.data。JS:hot.data。offset= と category= は任意です(Amazon Best Sellers by Category、Top Websites のみ)。

非同期処理

import asyncio
from trendsapi_youtube import AsyncTrendsAPI

async def main():
    c = AsyncTrendsAPI()
    return await asyncio.gather(
        c.get_time_series("sourdough starter"),
        c.get_time_series("sourdough starter", source="google search"),
    )

asyncio.run(main())

200 の応答 1 件につき、課金対象のリクエスト 1 件です。

Pandas

from dataclasses import asdict
import pandas as pd
from trendsapi_youtube import TrendsAPI

df = pd.DataFrame(asdict(p) for p in TrendsAPI().get_time_series("sourdough starter"))
df["date"] = pd.to_datetime(df["date"])
print(df.set_index("date")["value"].resample("ME").mean().tail())

JavaScript / TypeScript

npm install trendsapi-youtube

Node 18 以降、Deno、Bun、Workers に対応しています。同じ API キーを使用します。上記のフィールド表が適用されます。

メソッド
メソッドREST mode戻り値
getTimeSeries(keyword, { source, data_mode })get_time_series週ごとのデータポイント
getGrowth(keyword, { percent_growth, source, data_mode })get_growth成長率オブジェクト
getLive({ limit, offset, category })get_top_trendsリアルタイムフィード
getTopTrends({ type, ... })get_top_trendsリアルタイムフィード
import { TrendsAPI } from "trendsapi-youtube";

const client = new TrendsAPI({ apiKey: process.env.TRENDSAPI_KEY! });
const series = await client.getTimeSeries("sourdough starter");
console.log(series.at(-1)?.date, series.at(-1)?.value);

const growth = await client.getGrowth("sourdough starter", {
  percent_growth: ["3M", "12M"],
});
console.log(growth.results[0].growth, growth.results[0].direction);

const live = await client.getLive({ limit: 10 });
console.log(live.data);                 // [[1, "..."], ...]

呼び出し(curl)

フィールド値
エンドポイントPOST https://api.trendsapi.ai/api
認証Authorization: Bearer $TRENDSAPI_KEY
履歴get_time_series または get_growth と source: youtube を使用
キーワード検索フレーズ(例:サワードウスターター)
リアルタイムの typeYouTube Trending
curl -sS -X POST https://api.trendsapi.ai/api \
  -H "Authorization: Bearer $TRENDSAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{"mode":"get_time_series","source":"youtube","keyword":"sourdough starter"}'

ソースに関する注記

  • value は YouTube 上でのこの検索語に対する 0~100 の値であり、動画のメタデータではありません。
  • type は youtube ではなく YouTube Trending です。
  • このエンドポイントでは regionCode を指定できません。

エラー

HTTPクライアント
200ペイロードを解析しました。Python のデータクラス/JS の型付きオブジェクト
400例外が発生します。source または type のスペルを修正してください
401例外が発生します。TRENDSAPI_KEY を確認してください
404例外が発生します。そのキーワードの系列はありません。再試行しないでください
429例外が発生します。クォータ
5xxクライアントが再試行した後、例外が発生します

HTTP の body フィールドは JSON 文字列です。SDK がデコードします。生の curl では、body をもう一度解析する必要があります。

サイト:https://trendsapi.ai/trends/youtube-trends。

ライセンス

MIT。LICENSE をご覧ください。

コメント

MCP は初めてですか?

プロトコルの概要から最初のサーバーの導入まで、よくある疑問にまとめて答えます。

AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。