LoginSignup
0
0

More than 1 year has passed since last update.

SHOWROOMでライバーが参加してるイベントのポイントを取得

Last updated at Posted at 2021-12-30

Room IDの取得

配信者ごとに割り当てられるIDです

パターン1 一人ずつ取得

ライバーのページを取得

  • ライバーの配信ページを取得。この時、ライバーが配信中である必要は無いです。
  • 例:https://www.showroom-live.com/sendaiflavor_pink_BD

roomId取得

  • 取得したソース(正確にはそのソースに展開されたJavaScript)に roomId":217603 といった部分があるので適当に抜き出します。
  • ChromeのConsoleで試すなら、ページを開いた状態で、以下みたいな感じで抜き出せます。
// '217603'
const roomId = document.body.innerHTML.match(/roomId":(\d+)/)[1];

パターン2 イベントページで一括取得

イベントページを取得

  • 例:https://www.showroom-live.com/event/ramen_mitani

roomId取得

  • JQueryやcheerioが使える環境ならこんな感じで抜き出します
  const result = [];
  $('.listcardinfo').each((index, value) => {
    // console.log(value);
    const name = $(value).find(".listcardinfo-main-text").text();
    const id = $(value).find("a").attr("href").replace("/", "");
    const roomId = $(value).find("a").attr("data-room-id");
    result.push({
      name: name,
      id: id, // 配信ページのURL
      roomId: roomId
    })
  });

イベント参加情報の取得

GETする

  • https://www.showroom-live.com/api/room/event_and_support?room_id=${roomId} を取得します
  • 例: https://www.showroom-live.com/api/room/event_and_support?room_id=217603
  • なんかこんな感じのJSONが返ってきます。配信中に取得してみると、ポイントはほぼリアルタイムで反映されてそうです。
    image.png

  • 型定義はこんな感じ。SHOWROOMそんなに詳しくないのでよくわかってないところもあります。

type EventAndSupport = {
  support: any;
  regular_event: any;
  event: {
    ranking: {
      /** 前回の順位 */
      before_rank: number;
      /** 最高順位 */
      max_rank: number;
      /** ポイント数 */
      point: number;
      /** 次の順位とのポイント差っぽい */
      gap: number;
      /** 空文字っぽい */
      text: string;
      sequence_num: number;
      /** 配信中にアニメーション表示するかどうか */
      is_animation: number;
      next_rank: number;
      /** 順位 */
      rank: number;
    };
    /** イベント名 */
    event_name: string;
    /** イベントID */
    event_id: number;
    quest: {
      /** 各ユーザが投げたポイント数を見れるURL */
      contributor_list_url: string;
      support: {
        /** 達成したらtrue */
        is_achieved: boolean;
        /** 目標ポイント */
        goal_point: number;
        /** チュートリアルのURL */
        tutorial_url: string;
        /** 目標のタイトル */
        title: string;
        /** 目標固有のID */
        support_id: number;
        /** 次のレベル */
        next_level: number;
        /** 現在のポイント */
        current_point: number;
      };
      /** 達成項目のリスト */
      quest_list: {
        number_of_items: number;
        /** @example "#ff0000" */
        color: string;
        goal_point: number;
        rest_items: number;
        title: string;
        quest_level: number;
        is_acquired: boolean;
      }[];
      text: any;
      /** 現在のレベル */
      quest_level: number;
    };
    /** イベントの説明 */
    event_description: string;
    /**
     * イベント種別
     * @example "quest"
     */
    event_type: string;
    image: string;
    /** 終了時刻のUnixタイム。ミリ秒は抜いてある */
    ended_at: number;
    /** 開始時刻のUnixタイム。ミリ秒は抜いてある */
    started_at: number;
    /** チュートリアルのURL */
    tutorial_url: string;
    /** イベントのURL */
    event_url: string;
    end_animation: {
      value: number;
      trigger_time: number;
      type: number;
    }[];
  };
};
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0