API wrapper for the trace.moe API written in TypeScript.
Using yarn:
$ yarn add trace-moe-apiUsing npm:
$ npm i trace-moe-apisearchForAnimeSceneWithMediaURL(mediaURL: string | URL, options?: SearchOptions): Promise<SearchResponse>;
searchForAnimeSceneWithMediaAtPath(mediaPath: string, options?: SearchOptions): Promise<SearchResponse>;
fetchAPILimits(): Promise<APILimitsResponse>;
downloadVideoFromResult(result: SearchResult, options?: MediaDownloadOptions): Promise<string>;
downloadImageFromResult(result: SearchResult, options?: MediaDownloadOptions): Promise<string>;interface SearchOptions {
shouldCutBlackBorders?: boolean;
anilistID?: number | string;
shouldIncludeExtraAnilistInfo?: boolean;
}interface MediaDownloadOptions {
size?: MediaSize;
shouldMute?: boolean;
minDuration?: number;
maxDuration?: number;
directory?: string;
name?: string;
}import { createTraceMoeAPIWrapper, MediaSize, SearchError } from "trace-moe-api";
const traceMoeAPIWrapper = createTraceMoeAPIWrapper();
// const traceMoeAPIWrapper = createTraceMoeAPIWrapper({ apiKey });
try {
const apiLimits = await traceMoeAPI.fetchAPILimits();
if (apiLimits.remainingQuota > 0) {
const mediaURL = "https://images.plurk.com/32B15UXxymfSMwKGTObY5e.jpg";
const response = await traceMoeAPIWrapper.searchForAnimeSceneWithMediaURL(mediaURL);
// const response = await traceMoeAPIWrapper.searchForAnimeSceneWithMediaAtPath(mediaPath);
if (response.results.length > 0) {
const result = response.results[0];
console.log(result.anilistInfo.id);
const downloadPath = await traceMoeAPIWrapper.downloadVideoFromResult(result, MediaSize.large);
// const downloadPath = await traceMoeAPIWrapper.downloadImageFromResult(result, MediaSize.large);
// Do something with `downloadPath`...
}
}
} catch (error) {
if (error instanceof SearchError) {
// Do something with `error`...
}
}{
checkedFramesCount: 173362743,
totalQuota: 100,
remainingQuota: 90,
results: [] // Array of `SearchResult` objects
}{
anilistInfo: { id: 21034 },
filename: "Gochuumon wa Usagi Desuka2 - 01 (BD 1280x720 x264 AAC).mp4",
episode: 1,
episodeStart: 1,
episodeEnd: 1,
duration: 1418.0834,
fromTimestamp: 272.1886,
atTimestamp: 279.7795,
toTimestamp: 282.6574,
similarityPercentage: 99.22,
videoURL: "Preview video URL",
imageURL: "Preview image URL"
}{
id: 21034,
malID: 29787,
synonyms: ["Gochiusa"],
title: {
nativeTitle: "ご注文はうさぎですか??",
romajiTitle: "Gochuumon wa Usagi desu ka??",
englishTitle: "Is the Order a Rabbit?? Season 2"
},
isNSFWAnime: false
}{
id: "Either your API key or your IP address",
priority: 0,
concurrency: 1,
totalQuota: 100,
remainingQuota: 90
}