diff --git a/websites/H/HDrezka/metadata.json b/websites/H/HDrezka/metadata.json index ea606cf9bbc8..da598df56cf3 100644 --- a/websites/H/HDrezka/metadata.json +++ b/websites/H/HDrezka/metadata.json @@ -14,7 +14,7 @@ "service": "HDrezka", "description": { "en": "Website for watching movies, cartoons, anime and TV series.", - "ru": "Сайт для просмтра фильмов, аниме мультфильмов и сериалов." + "ru": "Сайт для просмотра фильмов, аниме, мультфильмов и сериалов." }, "url": [ "rezka.ag", @@ -24,7 +24,7 @@ "rezka-ua.co" ], "regExp": "^https?[:][/][/](rezka[.]ag|hdrezka[.]ag|rezka-ua[.]org|standby-rezka[.]tv|rezka-ua[.]co)[/]", - "version": "1.2.1", + "version": "1.3.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/thumbnail.jpeg", "color": "#DA3D36", @@ -33,5 +33,49 @@ "video", "media", "animation" + ], + "settings": [ + { + "id": "privacy", + "title": "Privacy Mode", + "icon": "fad fa-user-secret", + "value": false + }, + { + "id": "showBrowsingStatus", + "title": "Show Browsing Status", + "icon": "fad fa-book-reader", + "value": true + }, + { + "id": "showCover", + "title": "Show Cover", + "icon": "fas fa-images", + "value": true, + "if": { + "privacy": false + } + }, + { + "id": "timestamp", + "title": "Show Timestamps (Progress Bar)", + "icon": "fad fa-stopwatch", + "value": true, + "if": { + "privacy": false + } + }, + { + "id": "showSmallImages", + "title": "Show Small Images", + "icon": "fad fa-pause", + "value": true + }, + { + "id": "showTitleAsPresence", + "title": "Shot Title As Presence", + "icon": "fas fa-heading", + "value": true + } ] } diff --git a/websites/H/HDrezka/presence.ts b/websites/H/HDrezka/presence.ts index 275658e4dbdd..4c47067f19fb 100644 --- a/websites/H/HDrezka/presence.ts +++ b/websites/H/HDrezka/presence.ts @@ -1,56 +1,107 @@ +import { ActivityType, Assets, getTimestampsFromMedia } from 'premid' + const presence = new Presence({ clientId: '1191450515670843533', }) presence.on('UpdateData', async () => { - const presenceData: PresenceData = { - details: 'Где-то на сайте', + const [ + privacyMode, + showBrowsingStatus, + showCover, + showTimestamp, + showSmallImages, + showTitleAsPresence, + ] = await Promise.all([ + presence.getSetting('privacy'), + presence.getSetting('showBrowsingStatus'), + presence.getSetting('showCover'), + presence.getSetting('timestamp'), + presence.getSetting('showSmallImages'), + presence.getSetting('showTitleAsPresence'), + ]) + + const presenceData: any = { largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png', } - const contentType = document - .querySelector('meta[property=\'og:url\']') - ?.getAttribute('content') - ?.split('/')[3] - const currentType = contentType === 'films' - ? 'фильм' - : contentType === 'series' - ? 'сериал' - : contentType === 'cartoons' - ? 'мультфильм' - : contentType === 'animation' - ? 'аниме' - : 'чего-то' - - if (document.location.pathname === '/') - presenceData.details = 'На главной странице' - - if ( - document.location.pathname === '/films' - || document.location.pathname === '/series' - || document.location.pathname === '/cartoons' - || document.location.pathname === '/animation' - || document.location.pathname.match(/\/(films|series|cartoons|animation)\//) - ) { - if (document.location.pathname.match(/\/(?:films|series|cartoons|animation)\/.+/)) { - presenceData.details = `Смотрит ${currentType}` - presenceData.state = `${ - document.querySelector('.b-post__title h1')?.textContent - }` - presenceData.largeImageKey = document.querySelector('.b-sidecover a img')?.src - presenceData.smallImageKey = 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png' - presenceData.buttons = [ - { - label: 'Открыть страницу', - url: document - .querySelector('meta[property=\'og:url\']') - ?.getAttribute('content') ?? '', - }, - ] + + const urlPath = document.location.pathname + const contentType = document.querySelector('meta[property=\'og:url\']')?.getAttribute('content')?.split('/')[3] + const isMediaPage = urlPath.match(/\/(films|series|cartoons|animation)\/.+/) + + if (privacyMode && isMediaPage) { + return presence.setActivity({ + details: 'Watching something private', + largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png', + }) + } + + if (document.location.pathname === '/') { + if (!showBrowsingStatus) + return presence.clearActivity() + presenceData.details = 'Browsing the Home Page' + } + else if (isMediaPage) { + const title = document.querySelector('.b-post__title h1')?.textContent?.trim() + const coverImage = document.querySelector('.b-sidecover a img')?.src + + if (showTitleAsPresence && !privacyMode) { + presenceData.name = title + } + else { + presenceData.details = title + } + + presenceData.largeImageKey = (showCover && coverImage) ? coverImage : 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png' + + const video = document.querySelector('video') + + if (video && !video.paused) { + if (showTimestamp) { + const [startTimestamp, endTimestamp] = getTimestampsFromMedia(video) + presenceData.startTimestamp = startTimestamp + presenceData.endTimestamp = endTimestamp + } + presenceData.type = ActivityType.Watching + if (showSmallImages) { + presenceData.smallImageKey = Assets.Play + presenceData.smallImageText = 'Watching' + } + } + else if (showSmallImages) { + presenceData.smallImageKey = Assets.Pause + presenceData.smallImageText = 'Paused' + } + + const isSeries = ['series', 'animation', 'cartoons'].includes(contentType || '') + + if (isSeries) { + const activeSeason = document.querySelector('.b-simple_season__item.active')?.textContent?.trim() + const activeEpisode = document.querySelector('.b-simple_episode__item.active')?.textContent?.trim() + + if (activeSeason && activeEpisode) { + presenceData.state = ` ${activeSeason}, ${activeEpisode}` + } + else { + presenceData.state = 'Watching a series' + } } else { - presenceData.details = `Ищет ${currentType}` - presenceData.smallImageKey = 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/0.png' + presenceData.state = 'Watching a movie' + } + + const translator = document.querySelector('.b-translator__item.active')?.textContent?.trim() + if (translator) { + presenceData.largeImageText = `Voiceover: ${translator}` } + + presenceData.buttons = [{ label: 'Watch on Rezka', url: document.location.href }] + } + else { + if (!showBrowsingStatus) + return presence.clearActivity() + presenceData.details = 'Exploring the website' } + presence.setActivity(presenceData) })