Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
81 changes: 72 additions & 9 deletions websites/A/AnimeAv1/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
export interface IFrameData {
currentTime?: number
duration?: number
paused?: boolean
}

const iframe = new iFrame()

iframe.on('UpdateData', async () => {
const video = document.querySelector('video')
function getCandidateVideos(): HTMLVideoElement[] {
return Array.from(document.querySelectorAll<HTMLVideoElement>('video'))
}

function getBestVideoElement(): HTMLVideoElement | null {
const candidates = getCandidateVideos()
if (!candidates.length)
return null

if (candidates.length === 1)
return candidates[0] ?? null

const withScore = candidates.map((video) => {
const duration = Number(video.duration)
const currentTime = Number(video.currentTime)
const hasKnownDuration = Number.isFinite(duration) && duration > 0
const hasProgress = Number.isFinite(currentTime) && currentTime > 0
const score
= (video.readyState ?? 0) * 10
+ (hasKnownDuration ? 100 : 0)
+ (hasProgress ? 25 : 0)

return { video, score }
})

withScore.sort((a, b) => b.score - a.score)
return withScore[0]?.video ?? null
}

function getFiniteDuration(video: HTMLVideoElement): number {
const rawDuration = Number(video.duration)
if (Number.isFinite(rawDuration) && rawDuration > 0)
return rawDuration

const seekable = video.seekable
if (seekable && seekable.length > 0) {
const end = Number(seekable.end(seekable.length - 1))
if (Number.isFinite(end) && end > 0)
return end
}

const buffered = video.buffered
if (buffered && buffered.length > 0) {
const end = Number(buffered.end(buffered.length - 1))
if (Number.isFinite(end) && end > 0)
return end
}

return Number.NaN
}

iframe.on('UpdateData', async () => {
const video = getBestVideoElement()
if (!video) {
iframe.send({})
return
}

try {
const data: any = {
duration: video.duration,
currentTime: video.currentTime,
const duration = getFiniteDuration(video)
const currentTime = Number(video.currentTime)

if (!Number.isFinite(currentTime)) {
iframe.send({})
return
}

const data: IFrameData = {
currentTime,
paused: video.paused,
}

if (!Number.isNaN(data.duration) && !Number.isNaN(data.currentTime))
iframe.send(data)
else
iframe.send({})
if (Number.isFinite(duration) && duration > 0)
data.duration = duration

iframe.send(data)
}
catch {
iframe.send({})
Expand Down
38 changes: 30 additions & 8 deletions websites/A/AnimeAv1/metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$schema": "https://schemas.premid.app/metadata/1.16",
"apiVersion": 1,
"author": {
"name": "Dasp",
Expand All @@ -9,15 +10,36 @@
"en": "AnimeAv1 is an Anime streaming platform offering high-quality content with Spanish subtitles."
},
"url": "animeav1.com",
"version": "1.0.2",
"logo": "https://cdn.rcd.gg/PreMiD/websites/A/AnimeAv1/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/A/AnimeAv1/assets/thumbnail.png",
"regExp": "(animeav1\\.com)",
"version": "1.0.3",
"logo": "https://i.imgur.com/Xk3y6wK.png",
"thumbnail": "https://i.imgur.com/siQRcFt.png",
"color": "#FF66CC",
"category": "anime",
"tags": [
"anime",
"video",
"stream",
"español"
"tags": ["anime", "video", "stream", "espanol"],
"iframe": true,
"iFrameRegExp": ".*(?:animeav1\\.com|animeav1\\.uns\\.bio|pixeldrain\\.com|zilla-networks\\.com|solariaarchitecture\\.cyou).*(?:/.*)?$",
"settings": [
{
"id": "showProgress",
"title": "Show episode progress",
"icon": "fa-solid fa-stopwatch",
"value": true,
"description": "Shows playback progress when available (Discord progress bar + time text)."
},
{
"id": "cacheMode",
"title": "Cache mode",
"icon": "fa-solid fa-database",
"value": "session",
"values": ["off", "session", "persistent"]
},
{
"id": "cacheTtlMinutes",
"title": "Cache TTL (minutes)",
"icon": "fa-solid fa-clock",
"value": 360,
"placeholder": "360"
}
]
}
Loading
Loading