@animepaste/database
Version:
Local SQLite database used for Anime Paste CLI
196 lines (186 loc) • 4.87 kB
TypeScript
import * as Prisma from '@prisma/client';
import { Video, Prisma as Prisma$1, Resource } from '@prisma/client';
export { Resource } from '@prisma/client';
interface VideoInfo<T extends string = string> {
/**
* Storage type, only supports Ali OSS
*
* @default 'ali'
*/
platform: T;
/**
* Video ID
*/
videoId: string;
/**
* Video title
*/
title: string;
/**
* Creation time
*/
createdAt: string;
/**
* Cover image
*/
cover?: string;
/**
* Play urls
*/
playUrl: string[];
/**
* Video source
*/
source: VideoSource;
}
interface VideoSource {
magnetId?: string;
directory?: string;
hash?: string;
}
interface DatabaseOption {
url?: string;
}
declare abstract class AbstractDatabase {
private static DefaultFilepath;
protected readonly filepath: string;
protected readonly prisma: Prisma.PrismaClient;
constructor(option?: DatabaseOption);
ensure(): Promise<void>;
}
declare class VideoStore<T extends string = string> extends AbstractDatabase {
constructor(option: DatabaseOption);
createVideo(payload: VideoInfo<T>): Promise<Video>;
updateVideo(payload: VideoInfo<T>): Promise<Video>;
findVideo(platform: string, id: string): Promise<VideoInfo<T> | undefined>;
deleteVideo(platform: string, id: string): Promise<void>;
list(): Promise<VideoInfo<T>[]>;
private toVideoInfo;
}
interface ParsedMagnet {
title: string;
ep: number | undefined;
alias: string[];
tags: string[];
}
declare class MagnetParser {
private readonly TAGS;
private readonly REMOVE;
constructor();
parse(title: string): ParsedMagnet;
normalize(title: string): string;
normalizeMagnetTitle(originTitle: string): string;
hevc(magnet: {
tags: string[];
}): boolean;
quality(magnet: {
tags: string[];
}): 1080 | 720;
language(magnet: {
tags: string[];
}): "zh-Hans" | "zh-Hant";
private removeBracket;
private removePrefix;
private extractTags;
private extractEP;
private extractAlias;
}
interface IndexOption {
/**
* Index stop date
*
* @default 'subMonths(new Date(), 6)'
*/
limit?: Date | undefined;
/**
* Fetch page start
*
* @default '1'
*/
startPage?: number | undefined;
/**
* Fetch page limit
*
* @default 'undefined'
*/
endPage?: number | undefined;
/**
* Break when page found
*
* @default 'true'
*/
earlyStop?: boolean | undefined;
/**
* Handle progress event
*/
listener?: (state: {
page: number;
url: string;
timestamp?: Date;
ok?: number;
}) => void;
}
declare class MagnetStore extends AbstractDatabase {
private _timestamp;
readonly parser: MagnetParser;
constructor(option?: DatabaseOption);
index({ limit, startPage, endPage, earlyStop, listener }?: IndexOption): Promise<void>;
search(keyword: string | string[], option?: IndexOption & {
Video?: boolean;
Episode?: boolean;
}): Promise<(Prisma.Resource & {
Video: Prisma.Video | null;
Episode: Prisma.Episode | null;
})[]>;
createResource(payload: Prisma.Prisma.ResourceCreateInput): Promise<Prisma.Resource | undefined>;
createResources(payloads: Prisma.Prisma.ResourceCreateInput[]): Promise<Prisma.Resource[]>;
findById(id: string): Promise<Prisma.Resource | undefined>;
timestamp(newValue?: Date): Promise<Date>;
list(option?: {
skip?: number;
take?: number;
order?: 'asc' | 'desc';
}): Promise<Prisma.Resource[]>;
destroy(): Promise<void>;
idToLink(magnetId: string): string;
}
declare function fetchResource(page: number): Promise<Prisma$1.ResourceCreateInput[]>;
declare function proxy(): {
protocol: string;
host: string;
port: number;
} | undefined;
interface Episode {
/**
* 条目内的集数, 从 1 开始
*/
ep: number;
/**
* fansub
*/
fansub: string;
/**
* Video qulity
*/
quality: 1080 | 720;
/**
* 简体和繁体
*/
language: 'zh-Hans' | 'zh-Hant';
/**
* Link to the parent Anime
*/
bgmId: string;
/**
* Magnet resource
*/
magnet: Resource;
}
declare class EpisodeStore extends AbstractDatabase {
readonly parser: MagnetParser;
private toEpisode;
createEpisode(bgmId: string, magnet: Resource): Promise<Episode | undefined>;
findEpisode(magnetId: string): Promise<Episode | undefined>;
listEpisodes(bgmId: string): Promise<Episode[]>;
}
export { Episode, EpisodeStore, IndexOption, MagnetParser, MagnetStore, ParsedMagnet, VideoInfo, VideoSource, VideoStore, fetchResource, proxy };