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

Provider reviews #334

Merged
merged 27 commits into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5679f2e
fix(frontend): do not display useless notification
IgnisDa Sep 8, 2023
baed703
feat(backend): display time taken for summary calculation
IgnisDa Sep 8, 2023
890b070
feat(backend): add field to return provider reviews
IgnisDa Sep 9, 2023
c36515c
feat(backend): remove `async_recursion`
IgnisDa Sep 9, 2023
96ab847
feat(backend): return scores for anilist and vndb
IgnisDa Sep 9, 2023
1d9a1ee
feat(backend): return audible rating
IgnisDa Sep 9, 2023
ca24da1
feat(backend): return google books rating
IgnisDa Sep 9, 2023
625280b
feat(backend): return igdb rating
IgnisDa Sep 9, 2023
df601b7
feat(backend): (do not) return itunes rating
IgnisDa Sep 9, 2023
9d7e8ce
feat(backend): return manga updates rating
IgnisDa Sep 9, 2023
891e337
feat(backend): return MAL rating
IgnisDa Sep 9, 2023
cdb30cf
feat(backend): (do not) return openlibrary rating
IgnisDa Sep 9, 2023
66bf515
feat(backend): return listennotes rating
IgnisDa Sep 9, 2023
50cee56
fix(backend): get total count for vndb
IgnisDa Sep 9, 2023
c0aa0a8
fix(backend): get rating from tmdb
IgnisDa Sep 9, 2023
89ec171
refactor(backend): remove useless struct
IgnisDa Sep 9, 2023
de565c0
feat(backend): add provider rating column
IgnisDa Sep 9, 2023
4ad8514
feat(backend): commit provider rating to db
IgnisDa Sep 9, 2023
920b2cc
feat(backend): return provider rating for media
IgnisDa Sep 9, 2023
604f02d
feat(frontend): add logos
IgnisDa Sep 9, 2023
adffbf6
fix(backend): get count for vndb details
IgnisDa Sep 9, 2023
d56d02f
chore(backend): add comment
IgnisDa Sep 9, 2023
91e3c4f
feat(frontend): diplay rating for providers
IgnisDa Sep 9, 2023
f66c884
fix(frontend): use new output for anilist
IgnisDa Sep 9, 2023
4b1015b
feat(backend): support env variable for listennotes
IgnisDa Sep 9, 2023
4df3364
build(backend): bump version
IgnisDa Sep 9, 2023
9f4b7e3
fix(frontend): reduce rating size
IgnisDa Sep 9, 2023
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
14 changes: 1 addition & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "2.15.1"
version = "2.15.2"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand All @@ -21,7 +21,6 @@ async-graphql = { version = "6.0.4", features = [
"uuid",
] }
async-graphql-axum = "6.0.4"
async-recursion = "1.0.4"
async-trait = "0.1.73"
aws-sdk-s3 = "0.30.0"
axum = { version = "0.6.20", features = ["macros", "multipart"] }
Expand Down
11 changes: 9 additions & 2 deletions apps/backend/src/background.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{sync::Arc, time::Instant};

use apalis::prelude::{Job, JobContext, JobError};
use sea_orm::prelude::DateTimeUtc;
Expand Down Expand Up @@ -116,9 +116,16 @@ pub async fn perform_application_job(
misc_service.calculate_user_summary(user_id).await.unwrap();
}
ApplicationJob::RecalculateUserSummary(user_id) => {
let start = Instant::now();
tracing::trace!("Calculating summary for user {:?}", user_id);
misc_service.calculate_user_summary(user_id).await.unwrap();
tracing::trace!("Summary calculation complete for user {:?}", user_id);
let end = Instant::now();
let diff = end - start;
tracing::trace!(
"Summary calculation complete for user {:?}, (took {}s)",
user_id,
diff.as_secs()
);
}
ApplicationJob::UpdateMetadata(metadata) => {
let notifications = misc_service.update_metadata(metadata.id).await.unwrap();
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/entities/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use async_trait::async_trait;
use chrono::NaiveDate;
use rust_decimal::Decimal;
use sea_orm::{entity::prelude::*, ActiveValue};
use serde::{Deserialize, Serialize};

Expand All @@ -22,6 +23,7 @@ pub struct Model {
pub lot: MetadataLot,
pub last_updated_on: DateTimeUtc,
pub title: String,
// FIXME: Remove this
#[sea_orm(indexed)]
pub identifier: String,
pub description: Option<String>,
Expand All @@ -31,6 +33,7 @@ pub struct Model {
pub source: MetadataSource,
pub specifics: MediaSpecifics,
pub production_status: String,
pub provider_rating: Option<Decimal>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
7 changes: 4 additions & 3 deletions apps/backend/src/importer/goodreads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ pub async fn import(input: DeployGoodreadsImportInput) -> Result<ImportResult> {
role: "Author".to_owned(),
image: None,
}],
genres: vec![],
provider_rating: None,
images: vec![MetadataImage {
url: StoredUrl::Url(d.book_large_image_url),
lot: MetadataImageLot::Poster,
}],
publish_year: d.book_published.parse().ok(),
publish_date: None,
specifics: MediaSpecifics::Book(BookSpecifics {
pages: d.book.num_pages.parse().ok(),
}),
publish_year: d.book_published.parse().ok(),
publish_date: None,
genres: vec![],
suggestions: vec![],
groups: vec![],
},
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/importer/media_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult
image: None,
})
.collect(),
provider_rating: None,
genres: vec![],
images: vec![],
publish_year: None,
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/migrator/m20230410_create_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ pub enum Metadata {
Identifier,
// the provider source
Source,
// the rating from the provider
ProviderRating,
// details about the media
Specifics,
}
Expand Down Expand Up @@ -182,6 +184,7 @@ impl MigrationTrait for Migration {
.not_null(),
)
.col(ColumnDef::new(Metadata::PublishYear).integer())
.col(ColumnDef::new(Metadata::ProviderRating).decimal().null())
.col(ColumnDef::new(Metadata::PublishDate).date())
.col(ColumnDef::new(Metadata::Images).json())
.col(ColumnDef::new(Metadata::Identifier).string().not_null())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use sea_orm_migration::prelude::*;

use super::Metadata;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
if !manager.has_column("metadata", "provider_rating").await? {
manager
.alter_table(
Table::alter()
.table(Metadata::Table)
.add_column(ColumnDef::new(Metadata::ProviderRating).decimal().null())
.to_owned(),
)
.await?;
}
Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
2 changes: 2 additions & 0 deletions apps/backend/src/migrator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod m20230830_add_comments_field_to_review;
mod m20230901_create_metadata_group;
mod m20230901_create_partial_metadata;
mod m20230902_remove_useless_tables;
mod m20230909_add_provider_rating_field_to_metadata;

pub use m20230410_create_metadata::{Metadata, MetadataImageLot, MetadataLot, MetadataSource};
pub use m20230417_create_user::{UserLot, UserToMetadata};
Expand Down Expand Up @@ -58,6 +59,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230901_create_metadata_group::Migration),
Box::new(m20230902_remove_useless_tables::Migration),
Box::new(m20230901_create_partial_metadata::Migration),
Box::new(m20230909_add_provider_rating_field_to_metadata::Migration),
]
}
}
36 changes: 21 additions & 15 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ struct GraphqlMediaDetails {
title: String,
identifier: String,
description: Option<String>,
provider_rating: Option<Decimal>,
production_status: String,
lot: MetadataLot,
source: MetadataSource,
Expand Down Expand Up @@ -1473,30 +1474,31 @@ impl MiscellaneousService {

let mut resp = GraphqlMediaDetails {
id: model.id,
group,
lot: model.lot,
title: model.title,
source: model.source,
identifier: model.identifier,
production_status: model.production_status,
description: model.description,
publish_year: model.publish_year,
publish_date: model.publish_date,
source: model.source,
lot: model.lot,
creators,
genres,
poster_images,
backdrop_images,
publish_year: model.publish_year,
provider_rating: model.provider_rating,
production_status: model.production_status,
book_specifics: None,
movie_specifics: None,
show_specifics: None,
video_game_specifics: None,
visual_novel_specifics: None,
audio_book_specifics: None,
podcast_specifics: None,
movie_specifics: None,
manga_specifics: None,
anime_specifics: None,
podcast_specifics: None,
video_game_specifics: None,
audio_book_specifics: None,
visual_novel_specifics: None,
group,
genres,
creators,
source_url,
suggestions,
poster_images,
backdrop_images,
};
match model.specifics {
MediaSpecifics::AudioBook(a) => {
Expand Down Expand Up @@ -2276,6 +2278,7 @@ impl MiscellaneousService {
metadata_id: i32,
title: String,
description: Option<String>,
provider_rating: Option<Decimal>,
images: Vec<MetadataImage>,
specifics: MediaSpecifics,
creators: Vec<MetadataCreator>,
Expand Down Expand Up @@ -2397,6 +2400,7 @@ impl MiscellaneousService {
let mut meta: metadata::ActiveModel = meta.into();
meta.last_updated_on = ActiveValue::Set(Utc::now());
meta.title = ActiveValue::Set(title);
meta.provider_rating = ActiveValue::Set(provider_rating);
meta.description = ActiveValue::Set(description);
meta.images = ActiveValue::Set(MetadataImages(images));
meta.production_status = ActiveValue::Set(production_status);
Expand Down Expand Up @@ -2579,6 +2583,7 @@ impl MiscellaneousService {
identifier: ActiveValue::Set(details.identifier),
specifics: ActiveValue::Set(details.specifics),
production_status: ActiveValue::Set(details.production_status),
provider_rating: ActiveValue::Set(details.provider_rating),
..Default::default()
};
let metadata = metadata.insert(&self.db).await?;
Expand Down Expand Up @@ -3004,7 +3009,6 @@ impl MiscellaneousService {
Ok(results)
}

#[async_recursion::async_recursion]
pub async fn commit_media(
&self,
lot: MetadataLot,
Expand Down Expand Up @@ -3455,6 +3459,7 @@ impl MiscellaneousService {
metadata_id,
details.title,
details.description,
details.provider_rating,
details.images,
details.specifics,
details.creators,
Expand Down Expand Up @@ -3892,6 +3897,7 @@ impl MiscellaneousService {
publish_date: None,
specifics,
production_status: "Released".to_owned(),
provider_rating: None,
suggestions: vec![],
groups: vec![],
};
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ pub mod media {
pub specifics: MediaSpecifics,
pub suggestions: Vec<PartialMetadata>,
pub groups: Vec<(metadata_group::Model, Vec<PartialMetadata>)>,
pub provider_rating: Option<Decimal>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/providers/anilist/details.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ query DetailsQuery($id: Int!) {
role
}
}
averageScore
recommendations {
nodes {
mediaRecommendation {
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/providers/anilist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use async_trait::async_trait;
use graphql_client::{GraphQLQuery, Response};
use http_types::mime;
use itertools::Itertools;
use rust_decimal::Decimal;
use surf::{http::headers::ACCEPT, Client};

use crate::{
Expand Down Expand Up @@ -241,6 +242,7 @@ async fn details(client: &Client, id: &str) -> Result<MediaDetails> {
}
})
.collect();
let score = details.average_score.map(|s| Decimal::from(s));
Ok(MediaDetails {
identifier: details.id.to_string(),
title: details.title.unwrap().user_preferred.unwrap(),
Expand All @@ -255,6 +257,7 @@ async fn details(client: &Client, id: &str) -> Result<MediaDetails> {
publish_date: None,
specifics,
suggestions,
provider_rating: score,
groups: vec![],
})
}
Expand Down
24 changes: 24 additions & 0 deletions apps/backend/src/providers/audible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use async_trait::async_trait;
use convert_case::{Case, Casing};
use http_types::mime;
use itertools::Itertools;
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use serde_json::json;
use strum::{Display, EnumIter, IntoEnumIterator};
Expand Down Expand Up @@ -51,6 +52,7 @@ impl Default for PrimaryQuery {
"product_extended_attrs",
"series",
"relationships",
"rating",
]
.join(","),
image_sizes: ["2400"].join(","),
Expand Down Expand Up @@ -87,12 +89,24 @@ struct AudibleRelationshipItem {
sort: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
struct AudibleRating {
display_average_rating: Option<Decimal>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
struct AudibleRatings {
num_reviews: i32,
overall_distribution: AudibleRating,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
struct AudibleItem {
asin: String,
title: String,
authors: Option<Vec<NamedObject>>,
narrators: Option<Vec<NamedObject>>,
rating: Option<AudibleRatings>,
product_images: Option<AudiblePoster>,
merchandising_summary: Option<String>,
publisher_summary: Option<String>,
Expand Down Expand Up @@ -352,6 +366,15 @@ impl AudibleService {
}),
);
let description = item.publisher_summary.or(item.merchandising_summary);
let rating = if let Some(r) = item.rating {
if r.num_reviews > 0 {
r.overall_distribution.display_average_rating
} else {
None
}
} else {
None
};
MediaDetails {
identifier: item.asin,
lot: MetadataLot::AudioBook,
Expand All @@ -378,6 +401,7 @@ impl AudibleService {
runtime: item.runtime_length_min,
}),
images,
provider_rating: rating,
suggestions: vec![],
groups: vec![],
}
Expand Down
Loading