Skip to content

Commit

Permalink
Refactor: improve metadata reading with alternative episode number re…
Browse files Browse the repository at this point in the history
…ference
  • Loading branch information
mateussouzaweb committed Feb 10, 2024
1 parent 4e77299 commit 3c295d6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 40 deletions.
15 changes: 8 additions & 7 deletions src/scripts/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ const listHistory: Callback = async ({ state, render }) => {
const items = response.data.filter((item) => {
return item.panel.type === 'episode'
}).map((item) => {
const metadata = item.panel.episode_metadata
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
number: item.panel.episode_metadata.episode_number,
number: metadata.episode_number || metadata.episode,
name: item.panel.title,
description: item.panel.description,
duration: item.panel.episode_metadata.duration_ms / 1000,
duration: metadata.duration_ms / 1000,
playhead: item.playhead,
premium: item.panel.episode_metadata.is_premium_only,
season_id: item.panel.episode_metadata.season_id,
season_name: item.panel.episode_metadata.season_title,
serie_id: item.panel.episode_metadata.series_id,
serie_name: item.panel.episode_metadata.series_title,
premium: metadata.is_premium_only,
season_id: metadata.season_id,
season_name: metadata.season_title,
serie_id: metadata.series_id,
serie_name: metadata.series_title,
}
})

Expand Down
30 changes: 16 additions & 14 deletions src/scripts/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,39 @@ const listResults: Callback = async ({ state, render }) => {
const history = (historyResponse.data || []).filter((item) => {
return item.panel.type === 'episode'
}).map((item) => {
const metadata = item.panel.episode_metadata
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
number: item.panel.episode_metadata.episode_number,
number: metadata.episode_number || metadata.episode,
name: item.panel.title,
description: item.panel.description,
duration: item.panel.episode_metadata.duration_ms / 1000,
duration: metadata.duration_ms / 1000,
playhead: item.playhead,
premium: item.panel.episode_metadata.is_premium_only,
season_id: item.panel.episode_metadata.season_id,
season_name: item.panel.episode_metadata.season_title,
serie_id: item.panel.episode_metadata.series_id,
serie_name: item.panel.episode_metadata.series_title,
premium: metadata.is_premium_only,
season_id: metadata.season_id,
season_name: metadata.season_title,
serie_id: metadata.series_id,
serie_name: metadata.series_title,
}
})

const watchlistResponse = await App.watchlist({'n': '4'})
const watchlist = (watchlistResponse.data || []).map((item) => {
const metadata = item.panel.episode_metadata
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
number: item.panel.episode_metadata.episode_number,
number: metadata.episode_number || metadata.episode,
name: item.panel.title,
description: item.panel.description,
duration: item.panel.episode_metadata.duration_ms / 1000,
duration: metadata.duration_ms / 1000,
playhead: item.playhead,
premium: item.panel.episode_metadata.is_premium_only,
season_id: item.panel.episode_metadata.season_id,
season_name: item.panel.episode_metadata.season_title,
serie_id: item.panel.episode_metadata.series_id,
serie_name: item.panel.episode_metadata.series_title,
premium: metadata.is_premium_only,
season_id: metadata.season_id,
season_name: metadata.season_title,
serie_id: metadata.series_id,
serie_name: metadata.series_title,
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/scripts/serie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const listEpisodes: Callback = async ({ state, render }) => {
return {
id: item.id,
image: App.getImage(item.images.thumbnail).source,
number: item.episode_number,
number: item.episode_number || item.episode,
name: item.title,
description: item.description,
duration: item.duration_ms / 1000,
Expand Down
25 changes: 14 additions & 11 deletions src/scripts/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ const loadEpisode: Callback = async ({ state }) => {
const episodeId = state.episodeId
const episodeResponse = await App.episode(episodeId, {})
const episodeInfo = episodeResponse.data[0]
const episodeMetadata = episodeInfo.episode_metadata

const serieName = episodeInfo.episode_metadata.series_title
const seasonNumber = episodeInfo.episode_metadata.season_number
const episodeNumber = Number(episodeInfo.episode_metadata.episode_number)
const serieName = episodeMetadata.series_title
const seasonNumber = episodeMetadata.season_number
const episodeNumber = episodeMetadata.episode_number || episodeMetadata.episode
const episodeName = episodeInfo.title

const streamsLink = String(episodeInfo.streams_link)
Expand Down Expand Up @@ -140,11 +141,12 @@ const loadClosestEpisodes: Callback = async ({ state }) => {

if( previousResponse.data && previousResponse.data.length ){
const item = previousResponse.data[0].panel
const serieId = item.episode_metadata.series_id
const seasonId = item.episode_metadata.season_id
const metadata = item.episode_metadata
const serieId = metadata.series_id
const seasonId = metadata.season_id
const episodeId = item.id
const seasonNumber = item.episode_metadata.season_number
const episodeNumber = item.episode_metadata.episode_number
const seasonNumber = metadata.season_number
const episodeNumber = metadata.episode_number || metadata.episode
const episodeUrl = '/serie/' + serieId + '/season/' + seasonId + '/episode/' + episodeId + '/video'

previous.dataset.url = episodeUrl
Expand All @@ -157,11 +159,12 @@ const loadClosestEpisodes: Callback = async ({ state }) => {

if( nextResponse.data && nextResponse.data.length ){
const item = nextResponse.data[0].panel
const serieId = item.episode_metadata.series_id
const seasonId = item.episode_metadata.season_id
const metadata = item.episode_metadata
const serieId = metadata.series_id
const seasonId = metadata.season_id
const episodeId = item.id
const seasonNumber = item.episode_metadata.season_number
const episodeNumber = item.episode_metadata.episode_number
const seasonNumber = metadata.season_number
const episodeNumber = metadata.episode_number || metadata.episode
const episodeUrl = '/serie/' + serieId + '/season/' + seasonId + '/episode/' + episodeId + '/video'

next.dataset.url = episodeUrl
Expand Down
15 changes: 8 additions & 7 deletions src/scripts/watchlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ const listWatchlist: Callback = async ({ state, render }) => {
})

const items = response.data.map((item) => {
const metadata = item.panel.episode_metadata
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
number: item.panel.episode_metadata.episode_number,
number: metadata.episode_number || metadata.episode,
name: item.panel.title,
description: item.panel.description,
duration: item.panel.episode_metadata.duration_ms / 1000,
duration: metadata.duration_ms / 1000,
playhead: item.playhead,
premium: item.panel.episode_metadata.is_premium_only,
season_id: item.panel.episode_metadata.season_id,
season_name: item.panel.episode_metadata.season_title,
serie_id: item.panel.episode_metadata.series_id,
serie_name: item.panel.episode_metadata.series_title,
premium: metadata.is_premium_only,
season_id: metadata.season_id,
season_name: metadata.season_title,
serie_id: metadata.series_id,
serie_name: metadata.series_title,
}
})

Expand Down

0 comments on commit 3c295d6

Please sign in to comment.