Skip to content

Commit

Permalink
collect more media info in home
Browse files Browse the repository at this point in the history
  • Loading branch information
DatL4g committed Apr 25, 2024
1 parent acfcc9c commit 7743fee
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 234 deletions.
63 changes: 55 additions & 8 deletions anilist/src/commonMain/graphql/AiringQuery.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
query AiringQuery(
$page: Int,
$perPage: Int,
$statusVersion: Int,
$html: Boolean,
$sort: [AiringSort],
$airingAtGreater: Int
) {
Expand All @@ -12,22 +14,67 @@ query AiringQuery(
media {
id,
idMal,
isAdult,
genres,
status(version: $statusVersion),
description(asHtml: $html),
episodes,
duration,
chapters,
countryOfOrigin,
popularity,
isFavourite,
isFavouriteBlocked,
isAdult,
format,
bannerImage,
coverImage {
extraLarge,
large,
medium,
color
},
averageScore,
title {
english,
native,
romaji,
userPreferred
},
bannerImage,
coverImage {
color,
large,
extraLarge,
medium
nextAiringEpisode {
episode,
airingAt
},
rankings {
rank,
allTime,
year,
season,
type
},
genres,
characters(sort: [FAVOURITES_DESC,RELEVANCE]) {
nodes {
id,
name {
first,
middle
last,
full,
native,
userPreferred
},
image {
large,
medium
}
}
},
mediaListEntry {
score(format: POINT_5)
},
trailer {
id,
site,
thumbnail
}
}
}
Expand Down
65 changes: 56 additions & 9 deletions anilist/src/commonMain/graphql/SeasonQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,75 @@ query SeasonQuery(
$season: MediaSeason,
$preventGenres: [String],
$type: MediaType,
$adultContent: Boolean
$adultContent: Boolean,
$statusVersion: Int,
$html: Boolean,
) {
Page(page: $page, perPage: $perPage) {
media(sort: $sort, seasonYear: $year, season: $season, genre_not_in: $preventGenres, type: $type, isAdult: $adultContent) {
id,
idMal,
isAdult,
genres,
status(version: $statusVersion),
description(asHtml: $html),
episodes,
duration,
chapters,
countryOfOrigin,
popularity,
isFavourite,
isFavouriteBlocked,
isAdult,
format,
bannerImage,
coverImage {
extraLarge,
large,
medium,
color
},
averageScore,
title {
english,
native,
romaji,
userPreferred
},
bannerImage,
coverImage {
color,
large,
medium,
extraLarge
nextAiringEpisode {
episode,
airingAt
},
rankings {
rank,
allTime,
year,
season,
type
},
genres,
characters(sort: [FAVOURITES_DESC,RELEVANCE]) {
nodes {
id,
name {
first,
middle
last,
full,
native,
userPreferred
},
image {
large,
medium
}
}
},
mediaListEntry {
score(format: POINT_5)
},
trailer {
id,
site,
thumbnail
}
}
}
Expand Down
63 changes: 55 additions & 8 deletions anilist/src/commonMain/graphql/TrendingQuery.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ query TrendingQuery(
$page: Int,
$perPage: Int,
$type: MediaType,
$statusVersion: Int,
$html: Boolean,
$sort: [MediaSort],
$adultContent: Boolean,
$preventGenres: [String]
Expand All @@ -15,22 +17,67 @@ query TrendingQuery(
) {
id,
idMal,
isAdult,
genres,
status(version: $statusVersion),
description(asHtml: $html),
episodes,
duration,
chapters,
countryOfOrigin,
popularity,
isFavourite,
isFavouriteBlocked,
isAdult,
format,
bannerImage,
coverImage {
extraLarge,
large,
medium,
color
},
averageScore,
title {
english,
native,
romaji,
userPreferred
},
bannerImage,
coverImage {
color,
large,
extraLarge,
medium
nextAiringEpisode {
episode,
airingAt
},
rankings {
rank,
allTime,
year,
season,
type
},
genres,
characters(sort: [FAVOURITES_DESC,RELEVANCE]) {
nodes {
id,
name {
first,
middle
last,
full,
native,
userPreferred
},
image {
large,
medium
}
}
},
mediaListEntry {
score(format: POINT_5)
},
trailer {
id,
site,
thumbnail
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class AiringTodayStateMachine(
sort = Optional.present(listOf(AiringSort.TIME)),
airingAtGreater = Optional.present(
Clock.System.now().minus(1.hours).epochSeconds.toInt()
)
),
statusVersion = Optional.present(2),
html = Optional.present(true)
),
adultContent = adultContent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal object Cache {
expireAfterWriteDuration = 2.hours
}

private val medium = InMemoryKache<MediumQuery, Medium.Full>(
private val medium = InMemoryKache<MediumQuery, Medium>(
maxSize = 10L * 1024 * 1024
) {
strategy = KacheStrategy.LRU
Expand Down Expand Up @@ -79,13 +79,13 @@ internal object Cache {
}.getOrNull() ?: data
}

suspend fun getMedium(key: MediumQuery): Medium.Full? {
suspend fun getMedium(key: MediumQuery): Medium? {
return suspendCatching {
medium.get(key)
}.getOrNull()
}

suspend fun setMedium(key: MediumQuery, data: Medium.Full): Medium.Full {
suspend fun setMedium(key: MediumQuery, data: Medium): Medium {
return suspendCatching {
medium.put(key, data)
}.getOrNull() ?: data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MediumStateMachine(
query.execute().data ?: query.toFlow().saveFirstOrNull()?.data
}.mapSuccess<State> {
it.Media?.let { data ->
State.Success(state.snapshot.query, Medium.Full(data))
State.Success(state.snapshot.query, Medium(data))
}
}

Expand Down Expand Up @@ -88,14 +88,14 @@ class MediumStateMachine(
MediumQuery(
id = Optional.present(id),
statusVersion = Optional.present(2),
html = Optional.present(false)
html = Optional.present(true)
)
)
}

data class Success(
internal val query: MediumQuery,
val data: Medium.Full
val data: Medium
) : State

data class Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class TrendingAnimeStateMachine(
Optional.present(AdultContent.Genre.allTags)
} else {
Optional.absent()
}
},
statusVersion = Optional.present(2),
html = Optional.present(true)
)
)
}
Expand Down
Loading

0 comments on commit 7743fee

Please sign in to comment.