ShokoAnime / ShokoServer

Repository for Shoko Server.
https://shokoanime.com/
MIT License
405 stars 74 forks source link

Feature request: Relation graphs #846

Closed revam closed 1 year ago

revam commented 4 years ago

Posting here because I was told to in Discord.

I think it would be cool to query once for a relation-graph containing all relations (both directly and indirectly) to a series.

Suggested implemention

Expose an endpoint that returns all relations that touch the series at some point (directly or indirectly), made possible by grouping all relations stored AniDB_Anime_Relation in a new table (AniDB_Anime_Relation_List?) and querying for the group/list that contain the series id, then returning all relations (from AniDB_Anime_Relation) in that group/list.

Example endpoint

/api/v3/Series/{id}/Graph or maybe /api/v3/Graph/FromSeries/{seriesId}

Example responses

1) A graph was found GET /api/v3/Series/1/Graph, or GET /api/v3/Series/2/Graph, or GET /api/v3/Series/3/Graph

[
  { "seriesId": 1, "relatedSeriesId": 2, "relationType": "sequel" },
  { "seriesId": 2, "relatedSeriesId": 1, "relationType": "preequel" },
  { "seriesId": 1, "relatedSeriesId": 3, "relationType": "spin-off" },
  { "seriesId": 3, "relatedSeriesId": 1, "relationType": "main story" }
]

2) A graph was not found GET /api/v3/Series/0/Graph

[]

Expected use-case:

General use-cases (e.g. media server integrations. desktop)

maxpiva commented 4 years ago

Please notice, that getting the whole graph from anidb requires multiple anidb API calls, one for every relation the series has. If I'm not wrong. Currently, Shoko graphs only the ones that already have.

revam commented 4 years ago

So, what would be best, 1) expose only local relations, or 2) map the rest of the graph, potentially downloading the metadata for series not stored on disk, or 3) expose all relations in Shoko's database, with a setting to download all metadata for series not stored on disk. Personally I lean on option three or one.

@maxpiva What do you think?

maxpiva commented 4 years ago

Number three is great, but we already discussed this: Please check Shoko.Server/Models/SVR_AniDB_Anime.cs#L1342

da3dsoul commented 4 years ago

Personally, I use a depth of 3, and since I usually have at least all of the seasons (and maybe not all ovas), I'll have the entire tree

revam commented 1 year ago

We have /api/v3/Series/<shoko series id>/Relations, /api/v3/Series/AniDB/<anidb series id>/Relations, and /api/v3/Group/<shoko group id>/Relations, which is good enough and can be used to crawl the relations client-side to create a graph, so closing this for now. I'm actually using the first endpoint I mentioned already in Shokofin to get the relations for the series.