Skip to content

Commit 9c0645d

Browse files
authored
feat(Voirdrama): restore activity (#10734)
1 parent a2c68c5 commit 9c0645d

3 files changed

Lines changed: 220 additions & 0 deletions

File tree

websites/V/Voirdrama/iframe.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const iframe = new iFrame()
2+
3+
iframe.on('UpdateData', async () => {
4+
const video = document.querySelector<HTMLVideoElement>('video')
5+
if (video && !Number.isNaN(video.duration)) {
6+
iframe.send({
7+
duration: video.duration,
8+
currentTime: video.currentTime,
9+
paused: video.paused,
10+
})
11+
}
12+
})

websites/V/Voirdrama/metadata.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"$schema": "https://schemas.premid.app/metadata/1.16",
3+
"apiVersion": 1,
4+
"author": {
5+
"id": "671037171611729920",
6+
"name": "atom_skully"
7+
},
8+
"contributors": [
9+
{
10+
"id": "709704536821858304",
11+
"name": "cyadine"
12+
}
13+
],
14+
"service": "Voirdrama",
15+
"description": {
16+
"en": "Watch and download for free your Korean, Chinese, Japanese, Asian dramas in HD and FHD in VF and VOSTFR in streaming ddl on voirdrama.to",
17+
"fr": "Regarder et telecharger gratuitement vos dramas coréens chinois japonais asiatique en HD et FHD en VF et VOSTFR en streaming ddl sur voirdrama.to"
18+
},
19+
"url": "voirdrama.to",
20+
"regExp": "^https?[:][/][/]([a-z0-9-]+[.])*voirdrama[.]to[/]",
21+
"version": "1.0.0",
22+
"logo": "https://i.imgur.com/RkcVWHJ.png",
23+
"thumbnail": "https://i.imgur.com/ioAhLcH.png",
24+
"color": "#c41f32",
25+
"category": "videos",
26+
"tags": [
27+
"drama",
28+
"video",
29+
"media"
30+
],
31+
"iframe": true,
32+
"iFrameRegExp": "^https?[:][/][/](?:vidmoly[.]biz[/]embed[-]|f16px[.]com[/]e[/]|streamhide[.]to[/]e[/]|voe[.]sx[/]e[/]|streamtape[.]com[/]e[/]|my[.]mail[.]ru[/]video[/]embed[/]|(?:www[.])?yourupload[.]com[/]embed[/])",
33+
"settings": [
34+
{
35+
"id": "lang",
36+
"multiLanguage": true
37+
},
38+
{
39+
"id": "privacy",
40+
"title": "Privacy Mode",
41+
"icon": "fad fa-user-secret",
42+
"value": false
43+
},
44+
{
45+
"id": "timestamps",
46+
"title": "Show Timestamps",
47+
"icon": "fad fa-stopwatch",
48+
"value": true
49+
},
50+
{
51+
"id": "buttons",
52+
"title": "Show Buttons",
53+
"icon": "fas fa-compress-arrows-alt",
54+
"value": true
55+
}
56+
]
57+
}

websites/V/Voirdrama/presence.ts

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import { ActivityType, Assets, getTimestamps } from 'premid'
2+
3+
let video = {
4+
duration: 0,
5+
currentTime: 0,
6+
paused: true,
7+
}
8+
9+
const presence = new Presence({
10+
clientId: '1234098856376012860',
11+
})
12+
13+
const pathArr = document.location.pathname.split('/')
14+
const browsingTimestamp = Math.floor(Date.now() / 1000)
15+
const pages: Record<string, PresenceData> = {
16+
'liste-dramas': {
17+
state: 'Listes de dramas',
18+
},
19+
'nouveaux-ajouts': {
20+
state: 'Nouveaux dramas',
21+
},
22+
}
23+
24+
presence.on(
25+
'iFrameData',
26+
(data: { duration: number, currentTime: number, paused: boolean }) => {
27+
if (data?.duration)
28+
video = data
29+
},
30+
)
31+
32+
presence.on('UpdateData', async () => {
33+
const strings = await presence.getStrings({
34+
play: 'general.playing',
35+
pause: 'general.paused',
36+
home: 'general.viewHome',
37+
viewEpisode: 'general.buttonViewEpisode',
38+
viewPage: 'general.viewPage',
39+
browsing: 'general.browsing',
40+
searchFor: 'general.searchFor',
41+
})
42+
const [privacyMode, showTimestamps, showButtons] = await Promise.all(
43+
[
44+
presence.getSetting<boolean>('privacy'),
45+
presence.getSetting<boolean>('timestamps'),
46+
presence.getSetting<boolean>('buttons'),
47+
],
48+
)
49+
50+
let presenceData: PresenceData = {
51+
details: strings.home,
52+
type: ActivityType.Watching,
53+
largeImageKey: 'https://i.imgur.com/RkcVWHJ.png',
54+
startTimestamp: browsingTimestamp,
55+
}
56+
57+
if (privacyMode) {
58+
presenceData.details = strings.browsing
59+
}
60+
switch (pathArr[1]) {
61+
case 'drama': {
62+
const title = document.querySelector('ol > li:nth-child(2) > a')
63+
presenceData.details = 'Visite la page du drama :'
64+
presenceData.state = document.querySelector(
65+
'div.post-title > h1',
66+
)?.textContent
67+
if (privacyMode) {
68+
delete presenceData.state
69+
presenceData.details = strings.browsing
70+
}
71+
if (
72+
!Number.isNaN(video.duration)
73+
&& title
74+
&& !!document.querySelector('li.active')
75+
) {
76+
const [startTimestamp, endTimestamp] = getTimestamps(
77+
video.currentTime,
78+
video.duration,
79+
)
80+
81+
presenceData.details = title.textContent
82+
presenceData.state = `Episode: ${document
83+
.querySelector('li.active')
84+
?.textContent
85+
?.split('-')
86+
.pop()}`;
87+
[presenceData.startTimestamp, presenceData.endTimestamp] = [
88+
startTimestamp,
89+
endTimestamp,
90+
]
91+
presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play
92+
presenceData.smallImageText = video.paused
93+
? strings.pause
94+
: strings.play
95+
presenceData.buttons = [
96+
{
97+
label: strings.viewEpisode,
98+
url: document.location.href,
99+
},
100+
{
101+
label: 'Voir le drama',
102+
url: title.getAttribute('href'),
103+
},
104+
]
105+
if (video.paused) {
106+
delete presenceData.startTimestamp
107+
delete presenceData.endTimestamp
108+
}
109+
}
110+
break
111+
}
112+
case 'drama-genre':
113+
presenceData.details = strings.viewPage
114+
presenceData.state = `Listes drama du genre "${
115+
document.querySelector('h1')?.textContent
116+
}"`
117+
if (privacyMode) {
118+
delete presenceData.state
119+
presenceData.details = strings.browsing
120+
}
121+
break
122+
default:
123+
if (document.location.search.startsWith('?s')) {
124+
presenceData.details = strings.searchFor
125+
presenceData.state = new URLSearchParams(document.location.search).get(
126+
's',
127+
)
128+
presenceData.smallImageKey = Assets.Search
129+
}
130+
else if (Object.keys(pages).includes(pathArr[1]!)) {
131+
presenceData.details = strings.viewPage
132+
}
133+
presenceData = { ...presenceData, ...pages[pathArr[1]!] } as PresenceData
134+
if (privacyMode) {
135+
delete presenceData.state
136+
delete presenceData.smallImageKey
137+
presenceData.details = strings.browsing
138+
}
139+
break
140+
}
141+
142+
if (!showButtons || privacyMode)
143+
delete presenceData.buttons
144+
if (!showTimestamps) {
145+
delete presenceData.startTimestamp
146+
delete presenceData.endTimestamp
147+
}
148+
if (presenceData.details)
149+
presence.setActivity(presenceData)
150+
else presence.clearActivity()
151+
})

0 commit comments

Comments
 (0)