Skip to content

Add gameChannelId, gameName, and uploadDateISO in BaseVideo #74

@Hello-May

Description

@Hello-May

Hello, first and foremost, I would like to express my gratitude for creating and maintaining this fantastic library.

We have a project that requires some additional information to be crawled:

  1. Game categories content below game-related videos.
    add gameChannelId and gameName fields in BaseVideo.ts

My Editor Commits War Crimes  Horizon Zero Dawn

  1. uploadDate in YYYY-MM-DD format with the same time zone.
    Two uploadDate can be found in the json data, one of which is the original:
target.uploadDate = videoInfo.dateText.simpleText;

I guess it is the local time zone string.

The other is:

target.uploadDateISO = videoInfo.microformat.playerMicroformatRenderer.uploadDate;

Its format is always YYYY-MM-DD and I guess it's in 0 timezone.


I try to write like this as follows:

  • BaseVideo.ts
...
/** The date in ISO format this video is uploaded at */
uploadDateISO!: string;
/** The game's channel id that this video related */
gameChannelId!: string;
/** The game's name id that this video related */
gameName!: string;
...
  • BaseVideoParser.ts
static loadBaseVideo(target: BaseVideo, data: YoutubeRawData): BaseVideo {
  ...
  target.uploadDateISO = videoInfo.microformat.playerMicroformatRenderer.uploadDate;

  const { endpoint, title: gameTitle } = videoInfo.metadataRowContainer?.metadataRowContainerRenderer?.rows?.at(0)?.richMetadataRowRenderer?.contents?.at(0)?.richMetadataRenderer || {};
  target.gameChannelId = endpoint?.browseEndpoint?.browseId || null;
  target.gameName = gameTitle?.simpleText || null;
  ...
}
...
static parseRawData(data: YoutubeRawData): YoutubeRawData {
   ...
   const { videoDetails, microformat } = data[2].playerResponse;
   return { ...secondaryInfo, ...primaryInfo, videoDetails, microformat };
 }

Print out the result.

const video = await youtube.getVideo("VNwldCV78fU");
console.log("===>", video.title, video.uploadDateISO, video.gameChannelId, video.gameName);

// My Editor Commits War Crimes | Horizon Zero Dawn
// 2023-01-26
// UCzdvNoUM78qdDqjPEXGq9zw
// Horizon Zero Dawn

I'm not sure the naming and writing are correct, please correct me if any wrong.
We hope that this can be implemented as a new feature in the future. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions