基本概念
Content
Section titled “Content”Content はライブ配信やアーカイブ動画などを統一的に扱う型です。type: "broadcast" | "archive" | "scheduled" | "clip" の Discriminated Union として定義されています。
const content = await client.resolve(url);
if (content.type === "broadcast") { console.log(content.viewerCount); // 視聴者数 console.log(content.startedAt); // 配信開始日時}
if (content.type === "archive") { console.log(content.duration); // 再生時間(秒) console.log(content.viewCount); // 再生回数 console.log(content.publishedAt); // 公開日時}タイプガード
Section titled “タイプガード”Content コンパニオンオブジェクトで型を絞り込めます:
import { Content } from "@unified-live/core";
if (Content.isBroadcast(content)) { // content が Broadcast に絞り込まれる console.log(content.viewerCount);}
if (Content.isArchive(content)) { // content が Archive に絞り込まれる console.log(content.duration);}共通フィールド
Section titled “共通フィールド”すべてのコンテンツ型(Broadcast、Archive、ScheduledBroadcast、Clip)は以下のフィールドを共有します:
| フィールド | 型 | 説明 |
|---|---|---|
id | string | プラットフォーム固有のコンテンツ ID |
platform | string | "youtube", "twitch", "twitcasting" |
title | string | コンテンツのタイトル |
description | string | コンテンツの説明 |
tags | string[] | コンテンツのタグ |
url | string | コンテンツの URL |
thumbnail | Thumbnail | サムネイル画像(url, width, height) |
channel | ChannelRef | チャンネル参照(id, name, url) |
sessionId | string? | ライブとアーカイブを紐付ける ID(後述) |
languageCode | string? | コンテンツの言語コード |
raw | unknown | プラットフォーム API の生レスポンス — 利用時はプラットフォーム固有の型にキャストしてください |
Channel
Section titled “Channel”Channel は配信チャンネルまたはユーザーアカウントを表します:
const channel = await client.getChannel("youtube", "UC_x5XG1OV2P6uZZ5FSM9Ttw");
console.log(channel.id); // "UC_x5XG1OV2P6uZZ5FSM9Ttw"console.log(channel.platform); // "youtube"console.log(channel.name); // チャンネル名console.log(channel.url); // チャンネル URLconsole.log(channel.thumbnail); // サムネイル(任意)URL 解析
Section titled “URL 解析”クライアントは URL からプラットフォームを自動判別します:
// YouTubeconst content = await client.resolve("https://www.youtube.com/watch?v=abc123");// Twitchconst content = await client.resolve("https://www.twitch.tv/videos/123456");// TwitCastingconst content = await client.resolve("https://twitcasting.tv/user/movie/123");// 取得せずに URL だけ解析const resolved = client.match("https://www.youtube.com/watch?v=abc123");// { platform: "youtube", type: "content", id: "abc123" }const resolved = client.match("https://www.twitch.tv/username");// { platform: "twitch", type: "channel", id: "username" }対応 URL 形式
Section titled “対応 URL 形式”YouTube:
youtube.com/watch?v=VIDEO_IDyoutu.be/VIDEO_IDyoutube.com/channel/CHANNEL_IDyoutube.com/@handleyoutube.com/live/VIDEO_ID
Twitch:
twitch.tv/videos/VIDEO_IDtwitch.tv/USERNAME
TwitCasting:
twitcasting.tv/USER_ID/movie/MOVIE_IDtwitcasting.tv/USER_ID
Session ID
Section titled “Session ID”sessionId はライブ配信とそのアーカイブ動画を紐付けます。YouTube や TwitCasting ではライブとアーカイブが同じ ID を共有しますが、Twitch では異なる ID が使われます。sessionId はプラットフォームに関係なく安定したリンクを提供します。
// ライブ配信中const live = await client.resolve("https://youtube.com/watch?v=abc123");console.log(live.sessionId); // "abc123"
// 配信終了後のアーカイブも同じ sessionIdconst archive = await client.resolve("https://youtube.com/watch?v=abc123");console.log(archive.sessionId); // "abc123"次のステップ
Section titled “次のステップ”- プラットフォームプラグイン — 各プラットフォームの設定方法
- エラーハンドリング — エラー処理