Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AnimeLib): new presence #9023

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions websites/A/AnimeLib/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const iframe = new iFrame();

iframe.on("UpdateData", async () => {
const video = document.querySelector("video");

if (video && !isNaN(video.duration)) {
iframe.send({
duration: video.duration,
currentTime: video.currentTime,
paused: video.paused,
});
}
});
228 changes: 228 additions & 0 deletions websites/A/AnimeLib/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
interface CommonData {
id: number;
name: string;
rus_name: string;
eng_name: string;
alt_name: string;
slug: string;
slug_url: string;
cover: Cover;
stats: Stat[];
}

export interface AnimeData extends Omit<CommonData, "stats"> {
ageRestriction: AnimeAgeRestriction;
cover: Cover;
/**
* Example: 18 января 1991 г.
*/
releaseDateString: string;
shiki_rate: number;
shikimori_href: string;
status: AnimeStatus;
type: AnimeType;
/**
* Check if it exists. If it is, the anime is licensed and no anime data will be present
*/
toast?: {
message: string;
type: string;
};
}

export interface UserData {
id: number;
username: string;
avatar: UserAvatar;
last_online_at: Date;
}

export type CharacterData = CommonData;
export type PersonData = CommonData;
export type PublisherData = CommonData;
export type TeamData = Omit<CommonData, "stats" | "rus_name">;

export interface CollectionData {
id: number;
name: string;
user: Author;
}

export interface ReviewData {
id: number;
title: string;
user: Author;
related: ReviewRelation;
}

interface ReviewRelation {
rus_name: string;
eng_name: string;
cover: Cover;
}

interface Author {
id: string;
username: string;
avatar: UserAvatar;
}

interface Stat {
value: number;
formated: string;
short: string;
tag: "titles" | "subscribers";
label: string;
}

interface UserAvatar {
filename: string;
url: string;
}

interface Cover {
filename: string;
default: string;
thumbnail: string;
}

interface AnimeAgeRestriction {
id: number; // yet to be typed properly
label: string;
}

interface AnimeStatus {
id: number; // yet to be typed properly
label: string;
}

interface AnimeType {
id: number; // yet to be typed properly
label: string;
}

interface CachedResponse {
id: string;
data: AnimeData | UserData | CharacterData | CollectionData | ReviewData;
}

let cachedResponse: CachedResponse;

export class AnimeLib {
private static api = "https://api2.mangalib.me/api";

public static async getAnime(
path: string,
id: string
): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
if (path.endsWith("/watch")) path = path.slice(0, -6);

cachedResponse = {
id,
...(await (
await fetch(`${this.api}/anime/${path.split("/")[3]}`)
).json()),
};
}

return cachedResponse;
}

public static async getUser(id: string): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (await fetch(`${this.api}/user/${id}`)).json()),
};
}

return cachedResponse;
}

public static async getCharacter(
path: string,
id: string
): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (
await fetch(`${this.api}/character/${path.split("/")[3]}`)
).json()),
};
}

return cachedResponse;
}

public static async getPerson(
path: string,
id: string
): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (
await fetch(`${this.api}/people/${path.split("/")[3]}`)
).json()),
};
}

return cachedResponse;
}

public static async getCollection(id: string): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (await fetch(`${this.api}/collections/${id}`)).json()),
};
}

return cachedResponse;
}

public static async getReview(id: string): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (await fetch(`${this.api}/reviews/${id}`)).json()),
};
}

return cachedResponse;
}

public static async getTeam(
path: string,
id: string
): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (
await fetch(`${this.api}/teams/${path.split("/")[3]}`)
).json()),
};
}

return cachedResponse;
}

public static async getPublisher(
path: string,
id: string
): Promise<CachedResponse> {
if (!cachedResponse || cachedResponse.id !== id) {
cachedResponse = {
id,
...(await (
await fetch(`${this.api}/publisher/${path.split("/")[3]}`)
).json()),
};
}

return cachedResponse;
}
}
35 changes: 35 additions & 0 deletions websites/A/AnimeLib/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"$schema": "https://schemas.premid.app/metadata/1.12",
"apiVersion": 1,
"author": {
"id": "437154602626973697",
"name": "Kitosight"
},
"service": "AnimeLib",
"altnames": [
"AniLib"
],
"description": {
"en": "Watch anime online in Russian",
"ru": "Смотреть аниме онлайн на русском"
},
"url": "anilib.me",
"version": "1.0.0",
"logo": "https://i.imgur.com/8vAN1DA.png",
"thumbnail": "https://i.imgur.com/W1iU6v0.png",
"color": "#A020F0",
"category": "anime",
"tags": [
"anime"
],
"iframe": true,
"iFrameRegExp": ".*",

Check warning on line 26 in websites/A/AnimeLib/metadata.json

View workflow job for this annotation

GitHub Actions / Presence Validator

Presence (AnimeLib) has metadata.iFrameRegExp set to '.*', please change this if possible
"settings": [
{
"id": "private-watching",
"title": "Private Anime Watching",
"icon": "fad fa-user-secret",
"value": false
}
]
}
Loading
Loading