Skip to content

Commit 823b045

Browse files
authored
feat(Vix): add activity (#10352)
1 parent 20864f2 commit 823b045

File tree

2 files changed

+166
-0
lines changed

2 files changed

+166
-0
lines changed

websites/V/Vix/metadata.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "https://schemas.premid.app/metadata/1.16",
3+
"apiVersion": 1,
4+
"author": {
5+
"id": "432215088686956565",
6+
"name": "_xdoritos"
7+
},
8+
"service": "Vix",
9+
"description": {
10+
"en": "Vix is your favorite plataform to watch movies and series online.",
11+
"es": "Vix es tu plataforma favorita para ver películas y series en línea."
12+
},
13+
"url": "vix.com",
14+
"regExp": "^https?[:][/][/]([a-z0-9-]+[.])*vix[.]com[/]",
15+
"version": "1.0.0",
16+
"logo": "https://imgur.com/nrVsqoB.png",
17+
"thumbnail": "https://imgur.com/QUskhNc.png",
18+
"color": "#000000",
19+
"category": "videos",
20+
"tags": [
21+
"video",
22+
"streaming",
23+
"movies"
24+
]
25+
}

websites/V/Vix/presence.ts

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import { ActivityType, Assets, getTimestampsFromMedia } from 'premid'
2+
3+
const presence = new Presence({
4+
clientId: '1449327500814712842',
5+
})
6+
const browsingTimestamp = Math.floor(Date.now() / 1000)
7+
8+
enum ActivityAssets {
9+
Logo = 'https://imgur.com/nrVsqoB.png',
10+
}
11+
12+
let cache: {
13+
text: string
14+
nombreSerie: string
15+
episodioSerie: string
16+
bannerImg: string
17+
episodioNombre: string
18+
} = {
19+
text: '',
20+
nombreSerie: '',
21+
episodioSerie: '',
22+
bannerImg: ActivityAssets.Logo,
23+
episodioNombre: '',
24+
}
25+
26+
async function videoData(text: string) {
27+
if (text === cache.text && cache.nombreSerie !== '') {
28+
return {
29+
nombreSerie: cache.nombreSerie,
30+
episodioSerie: cache.episodioSerie,
31+
bannerImg: cache.bannerImg,
32+
episodioNombre: cache.episodioNombre,
33+
}
34+
}
35+
36+
const nombreSerie = document.querySelector('[class*="GEPA0QG"] > div > *')?.textContent || ''
37+
38+
const episodioSerie = document.querySelector('h2')?.parentElement?.querySelector('span:nth-child(1)')?.textContent || ''
39+
40+
const episodioNombre = document.querySelector('span:nth-child(2)')?.textContent || ''
41+
42+
const bannerElement = document.querySelector('meta[property="og:image"]')
43+
const bannerImg = bannerElement?.getAttribute('content') || ActivityAssets.Logo
44+
45+
cache = {
46+
text,
47+
nombreSerie,
48+
episodioSerie,
49+
bannerImg,
50+
episodioNombre,
51+
}
52+
53+
return {
54+
nombreSerie,
55+
episodioSerie,
56+
bannerImg,
57+
episodioNombre,
58+
}
59+
}
60+
61+
presence.on('UpdateData', async () => {
62+
const { pathname } = document.location
63+
const presenceData: PresenceData = {
64+
largeImageKey: ActivityAssets.Logo,
65+
startTimestamp: browsingTimestamp,
66+
smallImageKey: Assets.Search,
67+
type: ActivityType.Watching,
68+
state: 'Navegando en Vix',
69+
}
70+
71+
if (pathname.includes('/video/')) {
72+
const elVideo = document.querySelector<HTMLVideoElement>('video')
73+
const infoSerie = await videoData(pathname)
74+
if (elVideo && infoSerie) {
75+
presenceData.name = infoSerie.nombreSerie || 'Vix'
76+
presenceData.details = `${infoSerie.episodioSerie} - ${infoSerie.episodioNombre}`
77+
presenceData.state = 'Viendo en Vix'
78+
presenceData.largeImageKey = infoSerie.bannerImg || ActivityAssets.Logo
79+
presenceData.largeImageText = `${infoSerie.nombreSerie} Viendo en Vix`
80+
81+
if (!elVideo.paused) {
82+
presenceData.smallImageText = 'Reproduciendo'
83+
presenceData.smallImageKey = Assets.Play
84+
85+
if (elVideo && !Number.isNaN(elVideo.duration)) {
86+
const [startTs, endTs] = getTimestampsFromMedia(elVideo)
87+
presenceData.startTimestamp = startTs
88+
presenceData.endTimestamp = endTs
89+
}
90+
}
91+
else {
92+
presenceData.smallImageText = 'Pausado'
93+
presenceData.smallImageKey = Assets.Pause
94+
delete presenceData.startTimestamp
95+
delete presenceData.endTimestamp
96+
}
97+
}
98+
}
99+
else if (pathname.includes('/detail/')) {
100+
const nameSerie = document.querySelector('main h1')?.textContent || 'Vix'
101+
const descSerie = document.querySelector('[class*="DetailBody_description"]')?.textContent || 'Sin descripción'
102+
103+
presenceData.details = nameSerie || 'Navegando en Vix'
104+
presenceData.state = descSerie || 'Explorando en Vix'
105+
presenceData.largeImageKey = ActivityAssets.Logo
106+
presenceData.largeImageText = 'Explorando en Vix'
107+
presenceData.smallImageKey = Assets.Reading
108+
}
109+
else if (pathname.includes('/ondemandplus')) {
110+
const categoryMap = {
111+
series: 'Series',
112+
peliculas: 'Películas',
113+
novelas: 'Novelas',
114+
music: 'Musica',
115+
podcasts: 'Podcast',
116+
} as const
117+
const parts = pathname.split('/ondemandplus/')
118+
const slug = parts[1]?.split('/')[0]
119+
120+
const categoryName = slug && slug in categoryMap ? categoryMap[slug as keyof typeof categoryMap] : 'Pagina Principal'
121+
122+
presenceData.details = 'Navegando en Vix'
123+
presenceData.state = `Viendo: ${categoryName}`
124+
presenceData.largeImageText = 'Navegando en Vix'
125+
presenceData.smallImageKey = Assets.Reading
126+
}
127+
else if (pathname.includes('/noticias')) {
128+
presenceData.details = 'Explorando en Vix'
129+
presenceData.state = 'Viendo Noticias'
130+
presenceData.largeImageText = 'Viendo Noticias'
131+
presenceData.smallImageKey = Assets.Reading
132+
}
133+
else if (pathname.includes('/canales')) {
134+
const canalName = document.querySelector('header h2, section h2')?.textContent || 'Canales'
135+
136+
presenceData.details = 'Explorando Canales'
137+
presenceData.state = `Viendo: ${canalName}`
138+
presenceData.largeImageText = `Viendo: ${canalName}`
139+
}
140+
presence.setActivity(presenceData)
141+
})

0 commit comments

Comments
 (0)