Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/youtube/BaseChannel/BaseChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface BaseChannelProperties extends BaseProperties {
export class BaseChannel extends Base implements BaseChannelProperties {
id!: string;
/** The channel's name */
name!: string;
name?: string;
/** The channel's handle start with @ */
handle?: string;
/** The channel's description */
Expand Down
26 changes: 13 additions & 13 deletions src/youtube/BaseVideo/BaseVideoParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ export class BaseVideoParser {
const videoInfo = BaseVideoParser.parseRawData(data);

// Basic information
target.id = videoInfo.videoDetails.videoId;
target.title = videoInfo.videoDetails.title;
target.uploadDate = videoInfo.dateText.simpleText;
target.viewCount = +videoInfo.videoDetails.viewCount || null;
target.isLiveContent = videoInfo.videoDetails.isLiveContent;
target.thumbnails = new Thumbnails().load(videoInfo.videoDetails.thumbnail.thumbnails);
target.id = videoInfo?.videoDetails?.videoId;
target.title = videoInfo?.videoDetails?.title;
target.uploadDate = videoInfo?.dateText?.simpleText;
target.viewCount = +videoInfo?.videoDetails?.viewCount || null;
target.isLiveContent = videoInfo?.videoDetails?.isLiveContent;
target.thumbnails = new Thumbnails().load(videoInfo?.videoDetails?.thumbnail?.thumbnails);

// Channel
const { title, thumbnail, subscriberCountText } = videoInfo.owner.videoOwnerRenderer;
const { title, thumbnail, subscriberCountText } = videoInfo?.owner?.videoOwnerRenderer || {};

target.channel = new BaseChannel({
client: target.client,
id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
name: title.runs[0].text,
id: title?.runs?.[0]?.navigationEndpoint?.browseEndpoint?.browseId,
name: title?.runs?.[0]?.text,
subscriberCount: subscriberCountText?.simpleText,
thumbnails: new Thumbnails().load(thumbnail.thumbnails),
thumbnails: new Thumbnails().load(thumbnail?.thumbnails),
});

// Like Count and Dislike Count
const topLevelButtons = videoInfo.videoActions.menuRenderer.topLevelButtons;
const topLevelButtons = videoInfo?.videoActions?.menuRenderer?.topLevelButtons;
target.likeCount = topLevelButtons
? stripToInt(BaseVideoParser.parseButtonRenderer(topLevelButtons[0]))
: null;
Expand All @@ -40,7 +40,7 @@ export class BaseVideoParser {
videoInfo.superTitleLink?.runs
?.map((r: YoutubeRawData) => r.text.trim())
.filter((t: string) => t) || [];
target.description = videoInfo.videoDetails.shortDescription || "";
target.description = videoInfo?.videoDetails?.shortDescription || "";

// related videos
let secondaryContents =
Expand All @@ -62,7 +62,7 @@ export class BaseVideoParser {
}

// captions
if (videoInfo.captions) {
if (videoInfo?.captions) {
target.captions = new VideoCaptions({ client: target.client, video: target }).load(
videoInfo.captions.playerCaptionsTracklistRenderer
);
Expand Down
8 changes: 4 additions & 4 deletions src/youtube/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,16 @@ export class Client {

const [nextResponse, playerResponse] = await Promise.all([nextPromise, playerPromise]);

const data = { response: nextResponse.data, playerResponse: playerResponse.data };
const data = { response: nextResponse?.data, playerResponse: playerResponse?.data };

if (
!data.response?.contents?.twoColumnWatchNextResults.results.results.contents ||
data.playerResponse.playabilityStatus.status === "ERROR"
!data.response?.contents?.twoColumnWatchNextResults?.results?.results?.contents ||
data.playerResponse?.playabilityStatus?.status === "ERROR"
) {
return undefined as T;
}

return (!data.playerResponse.playabilityStatus.liveStreamability
return (!data.playerResponse?.playabilityStatus?.liveStreamability
? new Video({ client: this }).load(data)
: new LiveVideo({ client: this }).load(data)) as T;
}
Expand Down
12 changes: 6 additions & 6 deletions src/youtube/MixPlaylist/MixPlaylistParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { MixPlaylist } from "./MixPlaylist";

export class MixPlaylistParser {
static loadMixPlaylist(target: MixPlaylist, data: YoutubeRawData): MixPlaylist {
const twoColumnWatchNextResults = data.contents.twoColumnWatchNextResults;
const playlist = twoColumnWatchNextResults.playlist.playlist;
target.title = playlist.titleText.simpleText;
target.id = playlist.playlistId;
target.videoCount = playlist.contents.length;
target.videos = MixPlaylistParser.parseVideos(playlist.contents, target.client);
const twoColumnWatchNextResults = data?.contents?.twoColumnWatchNextResults;
const playlist = twoColumnWatchNextResults?.playlist?.playlist;
target.title = playlist?.titleText?.simpleText;
target.id = playlist?.playlistId;
target.videoCount = playlist?.contents?.length;
target.videos = MixPlaylistParser.parseVideos(playlist?.contents, target.client);

return target;
}
Expand Down
6 changes: 3 additions & 3 deletions src/youtube/Playlist/PlaylistParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class PlaylistParser {
if (videoOwner) {
const { title, thumbnail } = videoOwner.videoOwnerRenderer;
target.channel = new BaseChannel({
id: title.runs[0].navigationEndpoint.browseEndpoint.browseId,
name: title.runs[0].text,
thumbnails: new Thumbnails().load(thumbnail.thumbnails),
id: title?.runs?.[0]?.navigationEndpoint?.browseEndpoint?.browseId,
name: title?.runs?.[0]?.text,
thumbnails: new Thumbnails().load(thumbnail?.thumbnails),
client: target.client,
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/youtube/VideoCompact/VideoCompactParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class VideoCompactParser {

const channel = new BaseChannel({
client: target.client,
name: metadataRows[0].metadataParts[0].text.content,
name: metadataRows?.[0]?.metadataParts?.[0]?.text?.content,
id:
decoratedAvatarViewModel.rendererContext.commandContext.onTap.innertubeCommand
.browseEndpoint.browseId,
Expand All @@ -87,7 +87,7 @@ export class VideoCompactParser {
),
});

const isLive = thumbnailBadge.icon?.sources[0].clientResource.imageName === "LIVE";
const isLive = thumbnailBadge.icon?.sources?.[0]?.clientResource?.imageName === "LIVE";

target.channel = channel;
target.id = data.contentId;
Expand All @@ -97,9 +97,9 @@ export class VideoCompactParser {
target.thumbnails = new Thumbnails().load(
data.contentImage.thumbnailViewModel.image.sources
);
target.viewCount = stripToInt(metadataRows[1].metadataParts[0].text.content);
target.viewCount = stripToInt(metadataRows?.[1]?.metadataParts?.[0]?.text?.content);
target.uploadDate = !isLive
? metadataRows[1].metadataParts[metadataRows[1].metadataParts.length - 1].text.content
? metadataRows?.[1]?.metadataParts?.[metadataRows?.[1]?.metadataParts?.length - 1]?.text?.content
: undefined;

return target;
Expand Down