mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-04 03:27:14 -05:00 
			
		
		
		
	Solving a bug with genres in the crawler and adding a genre api
This commit is contained in:
		
							parent
							
								
									7d7265ba12
								
							
						
					
					
						commit
						2293eb9494
					
				@ -37,6 +37,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
		WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
 | 
							WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
 | 
				
			||||||
		WatchItem GetMovieWatchItem(string movieSlug);
 | 
							WatchItem GetMovieWatchItem(string movieSlug);
 | 
				
			||||||
		People GetPeopleBySlug(string slug);
 | 
							People GetPeopleBySlug(string slug);
 | 
				
			||||||
 | 
							IEnumerable<Genre> GetGenres();
 | 
				
			||||||
		Genre GetGenreBySlug(string slug);
 | 
							Genre GetGenreBySlug(string slug);
 | 
				
			||||||
		Studio GetStudioBySlug(string slug);
 | 
							Studio GetStudioBySlug(string slug);
 | 
				
			||||||
		Collection GetCollection(string slug);
 | 
							Collection GetCollection(string slug);
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
using System.Collections.Generic;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
using Newtonsoft.Json;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Models
 | 
					namespace Kyoo.Models
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using System.Reflection;
 | 
					using System.Reflection;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,7 +2,6 @@
 | 
				
			|||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Kyoo.Models.Watch;
 | 
					using Kyoo.Models.Watch;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Diagnostics.CodeAnalysis;
 | 
					 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
using Kyoo.Models.Exceptions;
 | 
					using Kyoo.Models.Exceptions;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
@ -196,9 +195,14 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return (from people in _database.Peoples where people.Slug == slug select people).FirstOrDefault();
 | 
								return (from people in _database.Peoples where people.Slug == slug select people).FirstOrDefault();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public IEnumerable<Genre> GetGenres()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.Genres;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		public IEnumerable<Genre> GetGenreForShow(long showID)
 | 
							public IEnumerable<Genre> GetGenreForShow(long showID)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return ((from show in _database.Shows where show.ID == showID select show.Genres).FirstOrDefault());
 | 
								return (from show in _database.Shows where show.ID == showID select show.Genres).FirstOrDefault();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Genre GetGenreBySlug(string slug)
 | 
							public Genre GetGenreBySlug(string slug)
 | 
				
			||||||
@ -368,7 +372,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				Show show = _database.Entry(edited).IsKeySet
 | 
									Show show = _database.Entry(edited).IsKeySet
 | 
				
			||||||
					? _database.Shows.FirstOrDefault(x => x.ID == edited.ID)
 | 
										? _database.Shows.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
					: GetShowBySlug(edited.Slug);
 | 
										: _database.Shows.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (show == null)
 | 
									if (show == null)
 | 
				
			||||||
					throw new ItemNotFound($"No show could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
										throw new ItemNotFound($"No show could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
				
			|||||||
@ -136,6 +136,11 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
					People existing = _libraryManager.GetPeopleBySlug(x.Slug);
 | 
										People existing = _libraryManager.GetPeopleBySlug(x.Slug);
 | 
				
			||||||
					return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x;
 | 
										return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x;
 | 
				
			||||||
				}).ToList();
 | 
									}).ToList();
 | 
				
			||||||
 | 
								show.Genres = show.Genres.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Genre existing = _libraryManager.GetGenreBySlug(x.Slug);
 | 
				
			||||||
 | 
									return existing ?? x;
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
			return show;
 | 
								return show;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										26
									
								
								Kyoo/Views/API/GenresAPI.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Kyoo/Views/API/GenresAPI.cs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
 | 
					using Kyoo.Models;
 | 
				
			||||||
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Kyoo.API
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						[Route("api/genres")]
 | 
				
			||||||
 | 
						[Route("api/genre")]
 | 
				
			||||||
 | 
						[ApiController]
 | 
				
			||||||
 | 
						public class GenresAPI : ControllerBase
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							private readonly ILibraryManager _libraryManager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public GenresAPI(ILibraryManager libraryManager)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								_libraryManager = libraryManager;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public ActionResult<IEnumerable<Genre>> Index()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _libraryManager.GetGenres().ToList();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,5 +1,4 @@
 | 
				
			|||||||
using System;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Kyoo.Models;
 | 
					 | 
				
			||||||
using Microsoft.AspNetCore.Mvc;
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using Kyoo.Controllers;
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user