コンテンツにスキップ

基本概念

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); // 公開日時
}

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);
}

すべてのコンテンツ型(BroadcastArchiveScheduledBroadcastClip)は以下のフィールドを共有します:

フィールド説明
idstringプラットフォーム固有のコンテンツ ID
platformstring"youtube", "twitch", "twitcasting"
titlestringコンテンツのタイトル
descriptionstringコンテンツの説明
tagsstring[]コンテンツのタグ
urlstringコンテンツの URL
thumbnailThumbnailサムネイル画像(url, width, height
channelChannelRefチャンネル参照(id, name, url
sessionIdstring?ライブとアーカイブを紐付ける ID(後述)
languageCodestring?コンテンツの言語コード
rawunknownプラットフォーム API の生レスポンス — 利用時はプラットフォーム固有の型にキャストしてください

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); // チャンネル URL
console.log(channel.thumbnail); // サムネイル(任意)

クライアントは URL からプラットフォームを自動判別します:

// YouTube
const content = await client.resolve("https://www.youtube.com/watch?v=abc123");
// Twitch
const content = await client.resolve("https://www.twitch.tv/videos/123456");
// TwitCasting
const 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" }

YouTube:

  • youtube.com/watch?v=VIDEO_ID
  • youtu.be/VIDEO_ID
  • youtube.com/channel/CHANNEL_ID
  • youtube.com/@handle
  • youtube.com/live/VIDEO_ID

Twitch:

  • twitch.tv/videos/VIDEO_ID
  • twitch.tv/USERNAME

TwitCasting:

  • twitcasting.tv/USER_ID/movie/MOVIE_ID
  • twitcasting.tv/USER_ID

sessionId はライブ配信とそのアーカイブ動画を紐付けます。YouTube や TwitCasting ではライブとアーカイブが同じ ID を共有しますが、Twitch では異なる ID が使われます。sessionId はプラットフォームに関係なく安定したリンクを提供します。

// ライブ配信中
const live = await client.resolve("https://youtube.com/watch?v=abc123");
console.log(live.sessionId); // "abc123"
// 配信終了後のアーカイブも同じ sessionId
const archive = await client.resolve("https://youtube.com/watch?v=abc123");
console.log(archive.sessionId); // "abc123"