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(Hulu): add watching to activity #9385

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions websites/H/Hulu/Hulu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"Hulu.viewNetwork": {
"description": "User is looking at a TV network.",
"message": "Viewing Network:"
},
"Hulu.viewSportEpisode": {
"description": "User is watching a sports episode.",
"message": "Viewing Sports Episode:"
},
"Hulu.viewSportTeam": {
"description": "User is viewing info about a sports team.",
"message": "Viewing Sports Team:"
},
"Hulu.viewMyStuff": {
"description": "User is accessing their saved content.",
"message": "Viewing My Stuff"
},
"Hulu.viewMyDVR": {
"description": "User is viewing their recorded shows.",
"message": "Viewing My DVR:"
},
"Hulu.onHulu": {
"description": "User is viewing on Hulu.",
"message": "On Hulu"
},
"Hulu.viewWatchHistory": {
"description": "User is looking at their watch history.",
"message": "Viewing Watch History"
}
}
9 changes: 7 additions & 2 deletions websites/H/Hulu/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
{
"name": "GURRMAN375D",
"id": "446528923535278082"
},
{
"name": "kuriel.",
"id": "354233941550694400"
}
],
"service": "Hulu",
Expand All @@ -21,15 +25,16 @@
"en": "Watch current hit shows, classic series and acclaimed movies instantly with Hulu.",
"fr": "Regardez des émissions à succès, des séries classiques et des films acclamés instantanément avec Hulu.",
"nl": "Bekijk huidige hitshows, klassieke series en veelgeprezen films direct met Hulu.",
"pt-br": "Assista shows de sucesso, séries clássicas e filmes aclamados instanteamente com Hulu.",
"pt": "Veja programas de sucesso, séries clássicas e filmes aclamados instantaneamente com Hulu.",
"pt-br": "Assista shows de sucesso, séries clássicas e filmes aclamados instantaneamente com Hulu.",
"ro": "Vizionează spectacolele de succes, seriale clasice și filme apreciate instantaneu cu Hulu.",
"uk": "Дивіться поточні хітові шоу, класичні серіали та відомі фільми миттєво з Hulu."
},
"url": [
"hulu.com",
"www.hulu.com"
],
"version": "1.3.35",
"version": "1.3.36",
"logo": "https://cdn.rcd.gg/PreMiD/websites/H/Hulu/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/H/Hulu/assets/thumbnail.jpg",
"color": "#66AA33",
Expand Down
66 changes: 43 additions & 23 deletions websites/H/Hulu/presence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Assets } from 'premid'
import { ActivityType, Assets, getTimestamps } from 'premid'

const presence = new Presence({
clientId: '607719679011848220',
Expand All @@ -8,6 +8,20 @@
pause: 'general.paused',
live: 'general.live',
search: 'general.searching',
viewMovie: 'general.viewMovie',
viewCategory: 'general.viewCategory',
viewGenre: 'general.viewGenre',
viewSeries: 'general.viewSeries',
watchingLive: 'general.watchingLive',
watching: 'general.watching',
browsing: 'general.browsing',
viewNetwork: 'Hulu.viewNetwork',
viewSportEpisode: 'Hulu.viewSportEpisode',
viewSportTeam: 'Hulu.viewSportTeam',
viewMyStuff: 'Hulu.viewMyStuff',
viewMyDVR: 'Hulu.viewMyDVR',
onHulu: 'Hulu.onHulu',
viewWatchHistory: 'Hulu.viewWatchHistory',
})

function capitalize(text: string): string {
Expand All @@ -21,6 +35,7 @@
let video: HTMLVideoElement | null = null
let details
let state
let name
let smallImageKey
let smallImageText
let startTimestamp
Expand All @@ -32,13 +47,13 @@
elapsed = Math.floor(Date.now() / 1000)
}

details = 'Browsing'
details = await (strings.browsing)
startTimestamp = elapsed

if (path.includes('/hub')) {
header = document.querySelector('.Hub__title')
title = document.querySelector('.SimpleModalNav__title')
details = 'Viewing Category'
details = await (strings.viewCategory)
if (header) {
state = header.textContent
if (title)
Expand All @@ -48,7 +63,7 @@
else if (path.includes('/genre')) {
header = document.querySelector('.Hub__title')
title = document.querySelector('.SimpleModalNav__title')
details = 'Viewing Genre'
details = await (strings.viewGenre)
if (header) {
state = header.textContent
if (title)
Expand All @@ -58,7 +73,7 @@
else if (path.includes('/series')) {
title = document.querySelector('.Masthead__title')
item = document.querySelector('.Subnav__item.active')
details = 'Viewing Series'
details = await (strings.viewSeries)
if (title) {
state = title.textContent
if (item)
Expand All @@ -68,7 +83,7 @@
else if (path.includes('/movie')) {
title = document.querySelector('.Masthead__title')
item = document.querySelector('.Subnav__item.active')
details = 'Viewing Movie'
details = await (strings.viewMovie)
if (title) {
state = title.textContent
if (item)
Expand All @@ -80,7 +95,7 @@
'.SimpleModalNav__brandImage',
)
item = document.querySelector('.Subnav__item.active')
details = 'Viewing Network'
details = await (strings.viewNetwork)
if (brand) {
state = brand.alt
if (item)
Expand All @@ -90,7 +105,7 @@
else if (path.includes('/sports_episode')) {
title = document.querySelector('.Masthead__title')
item = document.querySelector('.Subnav__item.active')
details = 'Viewing Sports Episode'
details = await (strings.viewSportEpisode)
if (title) {
state = title.textContent
if (item)
Expand All @@ -100,7 +115,7 @@
else if (path.includes('/sports_team')) {
title = document.querySelector('.Masthead__title')
item = document.querySelector('.Subnav__item.active')
details = 'Viewing Sports Team'
details = await (strings.viewSportTeam)
if (title) {
state = title.textContent
if (item)
Expand All @@ -109,7 +124,7 @@
}
else if (path.includes('/search')) {
const input = document.querySelector<HTMLInputElement>('.cu-search-input')
details = 'Searching'
details = (await strings).search
smallImageKey = Assets.Search
smallImageText = (await strings).search
if (input && input.value.length > 0)
Expand All @@ -120,19 +135,19 @@
'.LiveGuide__filter-item--selected',
)
title = document.querySelector('.ModalHeader__showname')
details = 'Viewing Live'
details = await (strings.watchingLive)
if (category) {
state = capitalize(category.textContent!)
if (title)
state = `${state} (${title.textContent})`
}
}
else if (path.includes('/my-stuff')) {
details = 'Viewing My Stuff'
details = await (strings.viewMyStuff)
}
else if (path.includes('/manage-dvr')) {
item = document.querySelector('.Subnav__item.active')
details = 'Viewing My DVR'
details = await (strings.viewMyDVR)
if (item)
state = capitalize(item.textContent!)
}
Expand All @@ -141,14 +156,16 @@
if (video) {
title = document.querySelector('.metadata-area__second-line')
const content = document.querySelector('.metadata-area__third-line')
const timestamps = presence.getTimestamps(
const timestamps = getTimestamps(
Math.floor(video.currentTime),
Math.floor(video.duration),
)
const live = timestamps[1] === Infinity
details = 'Watching'
if (title)
details = title.textContent
details = await (strings.watching)
if (title) {
details = await (strings.onHulu)
name = title.textContent
}

if (content?.textContent && content.textContent.length > 0)
state = content.textContent
Expand All @@ -171,22 +188,24 @@
}
else {
video = document.querySelector('video#content-video-player')
details = 'Viewing Watch History'
details = await (strings.viewWatchHistory)
if (video) {
title = document.querySelector(
'#web-player-app div.PlayerMetadata__titleText',
)
const content = document.querySelector(
'#web-player-app div.PlayerMetadata__subTitle',
)
const timestamps = presence.getTimestamps(
const timestamps = getTimestamps(
Math.floor(video.currentTime),
Math.floor(video.duration),
)
const live = timestamps[1] === Infinity
details = 'Watching'
if (title)
details = title.textContent
details = await (strings.watching)
if (title) {
details = await (strings.onHulu)
name = title.textContent
}

if (content?.textContent && content.textContent.length > 0)
state = content.textContent
Expand All @@ -212,14 +231,15 @@

presence.setActivity(
{
type: ActivityType.Watching,
details,
name,
state,
largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/H/Hulu/assets/logo.png',
smallImageKey,
smallImageText,
startTimestamp,
endTimestamp,
},
video ? !video.paused : true,
)
})
Loading