-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add series metadata interface * Add series indexing
- Loading branch information
1 parent
38e925d
commit 9692106
Showing
17 changed files
with
310 additions
and
57 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/core/src/components/molecules/GridItems/SeriesGridItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Card, CardContent, CardMedia } from "@mui/material"; | ||
import React from "react"; | ||
import { useFileUrl } from "../../../hooks"; | ||
import { ISeriesMetaData } from "../../../service"; | ||
import fallback from './no-poster.png'; | ||
|
||
export function SeriesPosterGridItem(props: { serie: ISeriesMetaData; }) { | ||
const url = useFileUrl(props.serie.posters[0]?.cid, fallback); | ||
|
||
return ( | ||
<Card sx={{ width: 240 }}> | ||
<CardMedia image={url} sx={{ height: 360, width: 240 }} /> | ||
<CardContent>{props.serie.title}</CardContent> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Grid } from "@mui/material"; | ||
import { useComputed } from "@preact/signals-react"; | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { ISeriesLibrary } from '../../service/Library/ILibrary'; | ||
import { SeriesPosterGridItem } from '../molecules/GridItems/SeriesGridItem'; | ||
import { LoadScreen } from "../molecules/LoadScreen"; | ||
import { useApp } from "../pages/AppContext"; | ||
import { ILibraryProps } from "../pages/LibraryManager"; | ||
|
||
export function SeriesLibrary(props: ILibraryProps<ISeriesLibrary>) { | ||
const [_t] = useTranslation(); | ||
const { profile } = useApp(); | ||
|
||
const library = profile.libraries.get(props.library.name); | ||
const index = useComputed(() => library?.value.index); | ||
|
||
return useComputed(() => { | ||
const i = index.value; | ||
|
||
return i?.cid == undefined ? ( | ||
<LoadScreen text={_t('Loading')} /> | ||
) : ( | ||
<Grid container spacing={1} sx={{ height: '100%', justifyContent: 'center' }}> | ||
{i.values.map(v => <Grid item key={v.title}><SeriesPosterGridItem serie={v} /></Grid>)} | ||
</Grid> | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IFileInfo } from '../indexer'; | ||
|
||
export interface ISeriesMetaData { | ||
title: string; | ||
posters: IFileInfo[]; | ||
yearStart?: number; | ||
yearEnd?: number; | ||
seasons: ISeasonMetaData[]; | ||
} | ||
|
||
export interface ISeasonMetaData { | ||
posters: IFileInfo[]; | ||
episodes: IEpisodeMetaData[]; | ||
} | ||
|
||
export interface IEpisodeMetaData { | ||
title: string; | ||
file: IFileInfo; | ||
thumbnails: IFileInfo[]; | ||
date?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type { IGenericMetaData } from './IGenericMetaData' | ||
export type { IGenericMetaData } from './IGenericMetaData'; | ||
export type { IGenericLibrary } from './IGenericLibrary'; | ||
export type { ILibrary, IMovieLibrary } from './ILibrary'; | ||
export type { IMovieMetaData } from './IMovieMetaData'; | ||
export type { IEpisodeMetaData, ISeriesMetaData, ISeasonMetaData } from './ISeriesMetaData'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { IIpfsService } from "../IIpfsService"; | ||
import { IEpisodeMetaData, IGenericLibrary, ISeasonMetaData, ISeriesMetaData } from "../Library"; | ||
import { IFileInfo } from "./IFileInfo"; | ||
import { IIndexFetcher } from './IIndexFetcher'; | ||
import { Regexes } from "./Regexes"; | ||
|
||
export class SeriesIndexFetcher implements IIndexFetcher<ISeriesMetaData[]> { | ||
constructor(private readonly node: IIpfsService, private readonly lib: IGenericLibrary<ISeriesMetaData, 'series'>) { | ||
} | ||
|
||
public async fetchIndex(): Promise<ISeriesMetaData[]> { | ||
const files = (await this.node.ls(this.lib.root.toString())).filter(f => f.type == 'dir'); | ||
const index = []; | ||
for (const file of files) { | ||
index.push(await this.extractSeriesMetaData(this.node, file)); | ||
} | ||
|
||
return index; | ||
} | ||
|
||
public async extractSeriesMetaData(node: IIpfsService, entry: IFileInfo): Promise<ISeriesMetaData> { | ||
const entries = await this.node.ls(entry.cid); | ||
const files = entries.filter(f => f.type == 'file'); | ||
const folders = entries.filter(f => f.type !== 'file'); | ||
|
||
return { | ||
title: entry.name, | ||
posters: files.filter(f => Regexes.Poster.exec(f.name) != null), | ||
seasons: await Promise.all(folders.map(season => this.extractSeasonMetaData(node, season))), | ||
}; | ||
} | ||
|
||
public async extractSeasonMetaData(node: IIpfsService, entry: IFileInfo, skeleton?: any): Promise<ISeasonMetaData> { | ||
const entries = await this.node.ls(entry.cid); | ||
const files = entries.filter(f => f.type == 'file'); | ||
const folders = entries.filter(f => f.type !== 'file'); | ||
|
||
return { | ||
posters: files.filter(f => Regexes.Poster.exec(f.name) != null), | ||
episodes: await Promise.all(folders.map(episode => this.extractEpisodeMetaData(node, episode))), | ||
}; | ||
} | ||
public async extractEpisodeMetaData(node: IIpfsService, entry: IFileInfo, skeleton?: any): Promise<IEpisodeMetaData> { | ||
const files = (await this.node.ls(entry.cid)).filter(f => f.type == 'file'); | ||
|
||
return { | ||
title: entry.name, | ||
file: files.filter(f => f.name.endsWith('.mp4'))[0], | ||
thumbnails: files.filter(f => Regexes.Thumbnail.exec(f.name) != null), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export type { IFileInfo } from './IFileInfo'; | ||
export { MovieIndexFetcher } from './MovieIndexFetcher'; | ||
export { SeriesIndexFetcher } from './SeriesIndexFetcher'; | ||
export { Regexes } from './Regexes'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.