fix gomovies

This commit is contained in:
TPN 2024-04-01 11:39:12 +00:00
parent 9119c0675e
commit e58b6b64c2
2 changed files with 113 additions and 37 deletions

View File

@ -2,7 +2,12 @@ import { load } from 'cheerio';
import { flags } from '@/entrypoint/utils/targets';
import { makeSourcerer } from '@/providers/base';
import { doodScraper } from '@/providers/embeds/dood';
import { mixdropScraper } from '@/providers/embeds/mixdrop';
import { upcloudScraper } from '@/providers/embeds/upcloud';
import { upstreamScraper } from '@/providers/embeds/upstream';
import { vidCloudScraper } from '@/providers/embeds/vidcloud';
import { voeScraper } from '@/providers/embeds/voe';
import { NotFoundError } from '@/utils/errors';
import { getSource } from './source';
@ -16,9 +21,8 @@ export const goMoviesScraper = makeSourcerer({
flags: [flags.CORS_ALLOWED],
disabled: true,
async scrapeShow(ctx) {
const search = await ctx.proxiedFetcher<string>(`/ajax/search`, {
method: 'POST',
body: new URLSearchParams({ keyword: ctx.media.title }),
const search = await ctx.proxiedFetcher(`/search/${ctx.media.title.replaceAll(/[^a-z0-9A-Z]/g, '-')}`, {
method: 'GET',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
@ -26,12 +30,12 @@ export const goMoviesScraper = makeSourcerer({
});
const searchPage = load(search);
const mediaElements = searchPage('a.nav-item');
const mediaElements = searchPage('div.film-detail');
const mediaData = mediaElements.toArray().map((movieEl) => {
const name = searchPage(movieEl).find('h3.film-name')?.text();
const year = searchPage(movieEl).find('div.film-infor span:first-of-type')?.text();
const path = searchPage(movieEl).attr('href');
const name = searchPage(movieEl).find('h2.film-name a')?.text();
const year = searchPage(movieEl).find('span.fdi-item:first')?.text();
const path = searchPage(movieEl).find('h2.film-name a').attr('href');
return { name, year, path };
});
@ -89,21 +93,57 @@ export const goMoviesScraper = makeSourcerer({
},
});
const upcloudSource = await getSource(ctx, sources);
// there's a better way to do this but I'm too lazy to do that
const upcloudSource = await getSource(ctx, sources, 'upcloud');
const vidcloudSource = await getSource(ctx, sources, 'vidcloud');
const voeSource = await getSource(ctx, sources, 'voe');
const doodSource = await getSource(ctx, sources, 'doodstream');
const upstreamSource = await getSource(ctx, sources, 'upstream');
const mixdropSource = await getSource(ctx, sources, 'mixdrop');
const embeds = [
{
embedId: upcloudScraper.id,
url: upcloudSource?.link ?? null,
},
{
embedId: vidCloudScraper.id,
url: vidcloudSource?.link ?? null,
},
{
embedId: voeScraper.id,
url: voeSource?.link ?? null,
},
{
embedId: doodScraper.id,
url: doodSource?.link ?? null,
},
{
embedId: upstreamScraper.id,
url: upstreamSource?.link ?? null,
},
{
embedId: mixdropScraper.id,
url: mixdropSource?.link ?? null,
},
];
const filteredEmbeds = embeds
.filter((embed) => embed.url !== null)
.map((embed) => ({
embedId: embed.embedId,
url: embed.url as string,
}));
if (filteredEmbeds.length === 0) throw new Error('No valid embeds found.');
return {
embeds: [
{
embedId: upcloudScraper.id,
url: upcloudSource.link,
},
],
embeds: filteredEmbeds,
};
},
async scrapeMovie(ctx) {
const search = await ctx.proxiedFetcher<string>(`ajax/search`, {
method: 'POST',
body: new URLSearchParams({ keyword: ctx.media.title }),
const search = await ctx.proxiedFetcher(`/search/${ctx.media.title.replaceAll(/[^a-z0-9A-Z]/g, '-')}`, {
method: 'GET',
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
@ -111,12 +151,12 @@ export const goMoviesScraper = makeSourcerer({
});
const searchPage = load(search);
const mediaElements = searchPage('a.nav-item');
const mediaElements = searchPage('div.film-detail');
const mediaData = mediaElements.toArray().map((movieEl) => {
const name = searchPage(movieEl).find('h3.film-name')?.text();
const year = searchPage(movieEl).find('div.film-infor span:first-of-type')?.text();
const path = searchPage(movieEl).attr('href');
const name = searchPage(movieEl).find('h2.film-name a')?.text();
const year = searchPage(movieEl).find('span.fdi-item:first')?.text();
const path = searchPage(movieEl).find('h2.film-name a').attr('href');
return { name, year, path };
});
@ -136,15 +176,52 @@ export const goMoviesScraper = makeSourcerer({
baseUrl: gomoviesBase,
});
const upcloudSource = await getSource(ctx, sources);
// there's a better way to do this but I'm too lazy to do that
const upcloudSource = await getSource(ctx, sources, 'upcloud');
const vidcloudSource = await getSource(ctx, sources, 'vidcloud');
const voeSource = await getSource(ctx, sources, 'voe');
const doodSource = await getSource(ctx, sources, 'doodstream');
const upstreamSource = await getSource(ctx, sources, 'upstream');
const mixdropSource = await getSource(ctx, sources, 'mixdrop');
const embeds = [
{
embedId: upcloudScraper.id,
url: upcloudSource?.link ?? null,
},
{
embedId: vidCloudScraper.id,
url: vidcloudSource?.link ?? null,
},
{
embedId: voeScraper.id,
url: voeSource?.link ?? null,
},
{
embedId: doodScraper.id,
url: doodSource?.link ?? null,
},
{
embedId: upstreamScraper.id,
url: upstreamSource?.link ?? null,
},
{
embedId: mixdropScraper.id,
url: mixdropSource?.link ?? null,
},
];
const filteredEmbeds = embeds
.filter((embed) => embed.url !== null)
.map((embed) => ({
embedId: embed.embedId,
url: embed.url as string,
}));
if (filteredEmbeds.length === 0) throw new Error('No valid embeds found.');
return {
embeds: [
{
embedId: upcloudScraper.id,
url: upcloudSource.link,
},
],
embeds: filteredEmbeds,
};
},
});

View File

@ -1,31 +1,30 @@
import { load } from 'cheerio';
import { ScrapeContext } from '@/utils/context';
import { NotFoundError } from '@/utils/errors';
import { gomoviesBase } from '.';
export async function getSource(ctx: ScrapeContext, sources: any) {
const upcloud = load(sources)('a[title*="upcloud" i]');
export async function getSource(ctx: ScrapeContext, sources: any, title: string) {
const source = load(sources)(`a[title*=${title} i]`);
const upcloudDataId = upcloud?.attr('data-id') ?? upcloud?.attr('data-linkid');
const sourceDataId = source?.attr('data-id') ?? source?.attr('data-linkid');
if (!upcloudDataId) throw new NotFoundError('Upcloud source not available');
if (!sourceDataId) return undefined;
const upcloudSource = await ctx.proxiedFetcher<{
const sourceData = await ctx.proxiedFetcher<{
type: 'iframe' | string;
link: string;
sources: [];
title: string;
tracks: [];
}>(`/ajax/sources/${upcloudDataId}`, {
}>(`/ajax/sources/${sourceDataId}`, {
headers: {
'X-Requested-With': 'XMLHttpRequest',
},
baseUrl: gomoviesBase,
});
if (!upcloudSource.link || upcloudSource.type !== 'iframe') throw new NotFoundError('No upcloud stream found');
if (!sourceData.link || sourceData.type !== 'iframe') return undefined;
return upcloudSource;
return sourceData;
}