mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
add scraper types
This commit is contained in:
parent
de97ee165d
commit
b3c4ad5e15
7 changed files with 57 additions and 11 deletions
|
@ -4,8 +4,6 @@ module.exports = {
|
|||
webpack: {
|
||||
alias: {
|
||||
"@": path.resolve(__dirname, "src/"),
|
||||
"@components": path.resolve(__dirname, "src/components"),
|
||||
"@scrapers": path.resolve(__dirname, "src/scrapers"),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
8
paths.json
Normal file
8
paths.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./src",
|
||||
"paths": {
|
||||
"@/*": [ "*"]
|
||||
}
|
||||
}
|
||||
}
|
18
src/App.tsx
18
src/App.tsx
|
@ -1,8 +1,24 @@
|
|||
import { GetProviderFromId, SearchProviders, MWMedia, MWMediaType } from '@/scrapers';
|
||||
import { useState } from 'react';
|
||||
import './index.css';
|
||||
|
||||
function App() {
|
||||
const [results, setResults] = useState<MWMedia[]>([]);
|
||||
|
||||
async function runSearch() {
|
||||
const results = await SearchProviders({ type: MWMediaType.MOVIE, searchQuery: "abc" });
|
||||
setResults(results);
|
||||
}
|
||||
|
||||
return (
|
||||
<p>Hello world</p>
|
||||
<>
|
||||
<h1>Search</h1>
|
||||
<button onClick={() => runSearch()}>Search</button>
|
||||
<h1>Search results</h1>
|
||||
{results.map(v=>(
|
||||
<p>{v.title} ({GetProviderFromId(v.providerId)?.displayName})</p>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
import { theFlixScraper } from "./list/theflix";
|
||||
import { MWMediaProvider } from "./scrapers";
|
||||
import { MWMediaProvider, MWQuery } from "./types";
|
||||
export * from "./types";
|
||||
|
||||
export const mediaProviders: MWMediaProvider[] = [
|
||||
const mediaProvidersUnchecked: MWMediaProvider[] = [
|
||||
theFlixScraper
|
||||
]
|
||||
export const mediaProviders: MWMediaProvider[] = mediaProvidersUnchecked.filter(v=>v.enabled);
|
||||
|
||||
export async function SearchProviders(query: MWQuery) {
|
||||
const allQueries = mediaProviders.map(provider => provider.searchForMedia(query));
|
||||
const allResults = await Promise.all(allQueries);
|
||||
|
||||
return allResults.flatMap(results => results);
|
||||
}
|
||||
|
||||
export function GetProviderFromId(id: string) {
|
||||
return mediaProviders.find(v=>v.id===id);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
import { MWMedia, MWMediaProvider, MWMediaType, MWPortableMedia, MWQuery } from "../../scrapers";
|
||||
import { MWMedia, MWMediaProvider, MWMediaType, MWPortableMedia, MWQuery } from "@/scrapers/types";
|
||||
|
||||
export const theFlixScraper: MWMediaProvider = {
|
||||
id: "theflix",
|
||||
enabled: true,
|
||||
type: MWMediaType.MOVIE,
|
||||
getMediaFromPortable(media: MWPortableMedia): MWMedia {
|
||||
displayName: "TheFlix",
|
||||
|
||||
async getMediaFromPortable(media: MWPortableMedia): Promise<MWMedia> {
|
||||
return {
|
||||
...media,
|
||||
title: "title here"
|
||||
}
|
||||
},
|
||||
searchForMedia(query: MWQuery): MWMedia[] {
|
||||
return [];
|
||||
|
||||
async searchForMedia(query: MWQuery): Promise<MWMedia[]> {
|
||||
return [{
|
||||
mediaId: "a",
|
||||
providerId: this.id,
|
||||
title: "testing",
|
||||
}];
|
||||
},
|
||||
}
|
||||
|
|
|
@ -19,8 +19,10 @@ export interface MWQuery {
|
|||
|
||||
export interface MWMediaProvider {
|
||||
id: string, // id of provider, must be unique
|
||||
enabled: boolean,
|
||||
type: MWMediaType,
|
||||
displayName: string,
|
||||
|
||||
getMediaFromPortable(media: MWPortableMedia): MWMedia,
|
||||
searchForMedia(query: MWQuery): MWMedia[],
|
||||
getMediaFromPortable(media: MWPortableMedia): Promise<MWMedia>,
|
||||
searchForMedia(query: MWQuery): Promise<MWMedia[]>,
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"extends": "./paths.json",
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
|
|
Loading…
Reference in a new issue