Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 Work on fixing channels #2921

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"eslint": "9.6.0",
"eslint-plugin-cypress": "3.3.0",
"globals": "15.8.0",
"knip": "5.24.2",
"knip": "5.24.3",
"prettier": "3.3.2",
"prettier-plugin-organize-imports": "4.0.0",
"typescript": "5.5.3"
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/src/common/innertube/innertubeFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const innertubeFetch = async (input: InputType, init?: RequestInit) => {
url = input.url;
}

console.log(url);

return vtFetch.rawFetch(url, {
...(typeof input === 'string' ? {} : input),
...init,
Expand Down
2 changes: 1 addition & 1 deletion server/src/common/proxyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const getSocksProxyAgent = (proxyUrl: string) => {
const socksProxy = parseSocksURL(proxyUrl);
const socksProxyAgent = socksDispatcher(socksProxy);
return {
proxyAgent: socksDispatcher(socksProxy),
proxyAgent: socksProxyAgent,
done: async () => {
await socksProxyAgent.close();
}
Expand Down
28 changes: 23 additions & 5 deletions server/src/core/channels/channels.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from 'fs';
import { Model } from 'mongoose';
import path from 'path';
import { General } from 'server/common/general.schema';
import { innertubeClient } from 'server/common/innertube/innertube';
import sharp from 'sharp';
import { checkParams, throwChannelError } from './channels.helper';
import { ChannelCommunityPostsContinuationDto } from './dto/response/channel-community-posts-continuation.dto';
Expand All @@ -30,6 +31,24 @@ export class ChannelsService {
private readonly GeneralModel: Model<General>
) {}

async resolveId(channelId: string): Promise<string> {
if (!checkParams(channelId)) {
throw new BadRequestException('Error fetching channel homepage', 'Invalid channelId');
}
if (channelId.startsWith('UC') && channelId.length === 24) {
return channelId;
}

const innertube = await innertubeClient();

const page = await innertube.resolveURL(`http://youtube.com/${channelId}`);
if (page?.payload?.browseId) {
return page.payload.browseId;
}

throw new NotFoundException('Channel not found');
}

async getChannelHome(channelId: string): Promise<ChannelHomeDto | ChannelInfoError> {
if (!checkParams(channelId)) {
throw new BadRequestException('Error fetching channel homepage', 'Invalid channelId');
Expand All @@ -43,12 +62,11 @@ export class ChannelsService {
// }
}

getChannelInfo(channelId: string): Promise<ChannelInfoDto | ChannelInfoError> {
if (!checkParams(channelId)) {
throw new BadRequestException('Error fetching channel info', 'Invalid channelId');
}
async getChannelInfo(channelId: string): Promise<ChannelInfoDto | ChannelInfoError> {
try {
return YoutubeGrabber.getChannelInfo({ channelId }) as unknown as Promise<ChannelInfoDto>;
const id = await this.resolveId(channelId);
const innertube = await innertubeClient();
return (await innertube.getChannel(id)).getAbout() as any;
} catch (error) {
throwChannelError(error, 'Error fetching channel info');
}
Expand Down
10 changes: 10 additions & 0 deletions server/src/core/channels/yt-channel-info/app/YoutubeGrabber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export class YoutubeGrabber {
.topicChannelDetailsRenderer;
// = topicChannelDetailsRenderer
}

if (!channelHeaderData) {
channelHeaderData =
channelPageDataResponse?.header?.pageHeaderRenderer?.content?.pageHeaderViewModel;
}

const headerTabs = channelPageDataResponse?.contents?.twoColumnBrowseResultsRenderer?.tabs;
const channelTabs = headerTabs
.filter(tab => tab?.tabRenderer !== undefined && tab?.tabRenderer !== null)
Expand Down Expand Up @@ -151,6 +157,10 @@ export class YoutubeGrabber {

if (typeof channelHeaderData?.banner !== 'undefined') {
bannerThumbnails = channelHeaderData?.banner?.thumbnails;

if (!bannerThumbnails) {
bannerThumbnails = channelHeaderData?.banner?.imageBannerViewModel?.image?.sources;
}
}

const subscriberSplit = subscriberText?.split(' ');
Expand Down
Loading