mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-03 19:17:16 -05:00 
			
		
		
		
	Reworking the whole library manager
This commit is contained in:
		
							parent
							
								
									3fc032c0a1
								
							
						
					
					
						commit
						f720545d67
					
				@ -1,76 +1,70 @@
 | 
				
			|||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Kyoo.Controllers
 | 
					namespace Kyoo.Controllers
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	public interface ILibraryManager
 | 
						public interface ILibraryManager
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		//Read values
 | 
							// Get by slug
 | 
				
			||||||
		Studio GetStudio(long showID);
 | 
							Library GetLibrary(string librarySlug);
 | 
				
			||||||
		IEnumerable<PeopleLink> GetPeople(long showID);
 | 
							Collection GetCollection(string slug);
 | 
				
			||||||
		IEnumerable<Genre> GetGenreForShow(long showID);
 | 
							Show GetShow(string slug);
 | 
				
			||||||
		IEnumerable<Season> GetSeasons(long showID);
 | 
							Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
 | 
				
			||||||
		int GetSeasonCount(string showSlug, long seasonNumber);
 | 
							Episode GetMovieEpisode(string movieSlug);
 | 
				
			||||||
		IEnumerable<Show> GetShowsInCollection(long collectionID);
 | 
							Genre GetGenre(string slug);
 | 
				
			||||||
		IEnumerable<Show> GetShowsInLibrary(long libraryID);
 | 
							Studio GetStudio(string slug);
 | 
				
			||||||
		IEnumerable<Show> GetShowsByPeople(string peopleSlug);
 | 
							People GetPeople(string slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Get all
 | 
				
			||||||
 | 
							IEnumerable<Library> GetLibraries();
 | 
				
			||||||
 | 
							IEnumerable<Show> GetShows();
 | 
				
			||||||
 | 
							IEnumerable<Episode> GetEpisodes();
 | 
				
			||||||
 | 
							IEnumerable<Studio> GetStudios();
 | 
				
			||||||
 | 
							IEnumerable<Genre> GetGenres();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Other get helpers
 | 
				
			||||||
 | 
							Show GetShowByPath(string path);
 | 
				
			||||||
		IEnumerable<string> GetLibrariesPath();
 | 
							IEnumerable<string> GetLibrariesPath();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Internal read
 | 
							// Search
 | 
				
			||||||
		(Track video, IEnumerable<Track> audios, IEnumerable<Track> subtitles) GetStreams(long episodeID, string showSlug);
 | 
					 | 
				
			||||||
		Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced);
 | 
					 | 
				
			||||||
		Track GetSubtitleById(long id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		//Public read
 | 
					 | 
				
			||||||
		IEnumerable<Show> GetShows();
 | 
					 | 
				
			||||||
		IEnumerable<Show> SearchShows(string searchQuery);
 | 
					 | 
				
			||||||
		IEnumerable<Collection> SearchCollections(string searchQuery);
 | 
							IEnumerable<Collection> SearchCollections(string searchQuery);
 | 
				
			||||||
		Library GetLibrary(string librarySlug);
 | 
							IEnumerable<Show> SearchShows(string searchQuery);
 | 
				
			||||||
		Library GetLibraryForShow(string showSlug);
 | 
					 | 
				
			||||||
		IEnumerable<Library> GetLibraries();
 | 
					 | 
				
			||||||
		IEnumerable<Studio> GetStudios();
 | 
					 | 
				
			||||||
		Show GetShowBySlug(string slug);
 | 
					 | 
				
			||||||
		Show GetShow(string path);
 | 
					 | 
				
			||||||
		Season GetSeason(string showSlug, long seasonNumber);
 | 
					 | 
				
			||||||
		IEnumerable<Episode> GetEpisodes(string showSlug);
 | 
					 | 
				
			||||||
		IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber);
 | 
					 | 
				
			||||||
		Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber);
 | 
					 | 
				
			||||||
		WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true);
 | 
					 | 
				
			||||||
		WatchItem GetMovieWatchItem(string movieSlug);
 | 
					 | 
				
			||||||
		People GetPeopleBySlug(string slug);
 | 
					 | 
				
			||||||
		IEnumerable<Genre> GetGenres();
 | 
					 | 
				
			||||||
		Genre GetGenreBySlug(string slug);
 | 
					 | 
				
			||||||
		Studio GetStudioBySlug(string slug);
 | 
					 | 
				
			||||||
		Collection GetCollection(string slug);
 | 
					 | 
				
			||||||
		IEnumerable<Episode> GetAllEpisodes();
 | 
					 | 
				
			||||||
		IEnumerable<Episode> SearchEpisodes(string searchQuery);
 | 
							IEnumerable<Episode> SearchEpisodes(string searchQuery);
 | 
				
			||||||
		IEnumerable<People> SearchPeople(string searchQuery);
 | 
					 | 
				
			||||||
		IEnumerable<Genre> SearchGenres(string searchQuery);
 | 
							IEnumerable<Genre> SearchGenres(string searchQuery);
 | 
				
			||||||
		IEnumerable<Studio> SearchStudios(string searchQuery);
 | 
							IEnumerable<Studio> SearchStudios(string searchQuery);
 | 
				
			||||||
 | 
							IEnumerable<People> SearchPeople(string searchQuery);
 | 
				
			||||||
		//Check if value exists
 | 
					 | 
				
			||||||
		bool IsCollectionRegistered(string collectionSlug, out long collectionID);
 | 
					 | 
				
			||||||
		bool IsShowRegistered(string showPath, out long showID);
 | 
					 | 
				
			||||||
		bool IsSeasonRegistered(long showID, long seasonNumber, out long seasonID);
 | 
					 | 
				
			||||||
		bool IsEpisodeRegistered(string episodePath, out long episodeID);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//Register values
 | 
							//Register values
 | 
				
			||||||
		long RegisterLibrary(Library library);
 | 
							void Register(object obj);
 | 
				
			||||||
		long RegisterCollection(Collection collection);
 | 
					 | 
				
			||||||
		long RegisterShow(Show show);
 | 
					 | 
				
			||||||
		long EditShow(Show show);
 | 
					 | 
				
			||||||
		long RegisterMovie(Episode movie);
 | 
					 | 
				
			||||||
		long RegisterSeason(Season season);
 | 
					 | 
				
			||||||
		long EditSeason(Season season);
 | 
					 | 
				
			||||||
		long RegisterEpisode(Episode episode);
 | 
					 | 
				
			||||||
		long EditEpisode(Episode episode);
 | 
					 | 
				
			||||||
		long RegisterTrack(Track track);
 | 
					 | 
				
			||||||
		void RegisterShowLinks(Library library, Collection collection, Show show);
 | 
							void RegisterShowLinks(Library library, Collection collection, Show show);
 | 
				
			||||||
		IEnumerable<MetadataID> ValidateExternalIDs(IEnumerable<MetadataID> ids);
 | 
							Task SaveChanges();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		void RemoveShow(long showID);
 | 
							// Edit values
 | 
				
			||||||
		void RemoveSeason(long seasonID);
 | 
							void Edit(Library library, bool resetOld);
 | 
				
			||||||
		void RemoveEpisode(long episodeID);
 | 
							void Edit(Collection collection, bool resetOld);
 | 
				
			||||||
		void ClearSubtitles(long episodeID);
 | 
							void Edit(Show show, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(Season season, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(Episode episode, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(Track track, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(People people, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(Studio studio, bool resetOld);
 | 
				
			||||||
 | 
							void Edit(Genre genre, bool resetOld);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Validate values
 | 
				
			||||||
 | 
							Library Validate(Library library);
 | 
				
			||||||
 | 
							Collection Validate(Collection collection);
 | 
				
			||||||
 | 
							Show Validate(Show show);
 | 
				
			||||||
 | 
							Season Validate(Season season);
 | 
				
			||||||
 | 
							Episode Validate(Episode episode);
 | 
				
			||||||
 | 
							People Validate(People people);
 | 
				
			||||||
 | 
							Studio Validate(Studio studio);
 | 
				
			||||||
 | 
							Genre Validate(Genre genre);
 | 
				
			||||||
 | 
							IEnumerable<MetadataID> Validate(IEnumerable<MetadataID> id);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Remove values
 | 
				
			||||||
 | 
							void RemoveShow(Show show);
 | 
				
			||||||
 | 
							void RemoveSeason(Season season);
 | 
				
			||||||
 | 
							void RemoveEpisode(Episode episode);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -7,10 +7,10 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
	public interface ITranscoder
 | 
						public interface ITranscoder
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Should transcode to a mp4 container (same video/audio format if possible, no subtitles).
 | 
							// Should transcode to a mp4 container (same video/audio format if possible, no subtitles).
 | 
				
			||||||
		Task<string> Transmux(WatchItem episode);
 | 
							Task<string> Transmux(Episode episode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Should transcode to a mp4 container with a h264 video format and a AAC audio format, no subtitles.
 | 
							// Should transcode to a mp4 container with a h264 video format and a AAC audio format, no subtitles.
 | 
				
			||||||
		Task<string> Transcode(WatchItem episode);
 | 
							Task<string> Transcode(Episode episode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Get video and audio tracks infos (codec, name, language...)
 | 
							// Get video and audio tracks infos (codec, name, language...)
 | 
				
			||||||
		Task<Track[]> GetTrackInfo(string path);
 | 
							Task<Track[]> GetTrackInfo(string path);
 | 
				
			||||||
 | 
				
			|||||||
@ -12,7 +12,7 @@ namespace Kyoo.Models
 | 
				
			|||||||
		public string Poster { get; set; }
 | 
							public string Poster { get; set; }
 | 
				
			||||||
		public string Overview { get; set; }
 | 
							public string Overview { get; set; }
 | 
				
			||||||
		[JsonIgnore] public string ImgPrimary { get; set; }
 | 
							[JsonIgnore] public string ImgPrimary { get; set; }
 | 
				
			||||||
		public IEnumerable<Show> Shows;
 | 
							public virtual IEnumerable<Show> Shows { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Collection() { }
 | 
							public Collection() { }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -38,17 +38,11 @@ namespace Kyoo.Models
 | 
				
			|||||||
				return this;
 | 
									return this;
 | 
				
			||||||
			if (ID == -1)
 | 
								if (ID == -1)
 | 
				
			||||||
				ID = collection.ID;
 | 
									ID = collection.ID;
 | 
				
			||||||
			if (Slug == null)
 | 
								Slug ??= collection.Slug;
 | 
				
			||||||
				Slug = collection.Slug;
 | 
								Name ??= collection.Name;
 | 
				
			||||||
			if (Name == null)
 | 
								Poster ??= collection.Poster;
 | 
				
			||||||
				Name = collection.Name;
 | 
								Overview ??= collection.Overview;
 | 
				
			||||||
			if (Poster == null)
 | 
								ImgPrimary ??= collection.ImgPrimary;
 | 
				
			||||||
				Poster = collection.Poster;
 | 
					 | 
				
			||||||
			if (Overview == null)
 | 
					 | 
				
			||||||
				Overview = collection.Overview;
 | 
					 | 
				
			||||||
			if (ImgPrimary == null)
 | 
					 | 
				
			||||||
				ImgPrimary = collection.ImgPrimary;
 | 
					 | 
				
			||||||
			Shows = Utility.MergeLists(Shows, collection.Shows, (x, y) => x.Slug == y.Slug);
 | 
					 | 
				
			||||||
			return this;
 | 
								return this;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -28,13 +28,13 @@ namespace Kyoo.Models
 | 
				
			|||||||
		[JsonIgnore] public virtual IEnumerable<Track> Tracks { get; set; }
 | 
							[JsonIgnore] public virtual IEnumerable<Track> Tracks { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public string ShowTitle => Show.Title; // Used in the API response only
 | 
							public string ShowTitle => Show.Title; // Used in the API response only
 | 
				
			||||||
		public string Link => GetSlug(Show.Slug, SeasonNumber, EpisodeNumber);
 | 
							public string Slug => GetSlug(Show.Slug, SeasonNumber, EpisodeNumber);
 | 
				
			||||||
		public string Thumb
 | 
							public string Thumb
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			get
 | 
								get
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				if (Show != null)
 | 
									if (Show != null)
 | 
				
			||||||
					return "thumb/" + Link;
 | 
										return "thumb/" + Slug;
 | 
				
			||||||
				return ImgPrimary;
 | 
									return ImgPrimary;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,8 @@ namespace Kyoo.Models
 | 
				
			|||||||
		public string Name { get; set; }
 | 
							public string Name { get; set; }
 | 
				
			||||||
		public string[] Paths { get; set; }
 | 
							public string[] Paths { get; set; }
 | 
				
			||||||
		public virtual IEnumerable<ProviderLink> Providers { get; set; }
 | 
							public virtual IEnumerable<ProviderLink> Providers { get; set; }
 | 
				
			||||||
 | 
							[JsonIgnore] public virtual IEnumerable<Show> Shows { get; set; }
 | 
				
			||||||
 | 
							[JsonIgnore] public virtual IEnumerable<Collection> Collections { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Library()  { }
 | 
							public Library()  { }
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ namespace Kyoo.Models
 | 
				
			|||||||
	public class PeopleLink
 | 
						public class PeopleLink
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		[JsonIgnore] public long ID { get; set; }
 | 
							[JsonIgnore] public long ID { get; set; }
 | 
				
			||||||
		[JsonIgnore] public string PeopleID { get; set; }
 | 
							[JsonIgnore] public long PeopleID { get; set; }
 | 
				
			||||||
		[JsonIgnore] public virtual People People { get; set; }
 | 
							[JsonIgnore] public virtual People People { get; set; }
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public string Slug
 | 
							public string Slug
 | 
				
			||||||
 | 
				
			|||||||
@ -93,7 +93,7 @@ namespace Kyoo.Models
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				if (Type != StreamType.Subtitle)
 | 
									if (Type != StreamType.Subtitle)
 | 
				
			||||||
					return null;
 | 
										return null;
 | 
				
			||||||
				string link = "/subtitle/" + Episode.Link + "." + Language;
 | 
									string link = "/subtitle/" + Episode.Slug + "." + Language;
 | 
				
			||||||
				if (IsForced)
 | 
									if (IsForced)
 | 
				
			||||||
					link += "-forced";
 | 
										link += "-forced";
 | 
				
			||||||
				switch (Codec)
 | 
									switch (Codec)
 | 
				
			||||||
 | 
				
			|||||||
@ -80,7 +80,9 @@ namespace Kyoo
 | 
				
			|||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				object value = property.GetValue(second);
 | 
									object value = property.GetValue(second);
 | 
				
			||||||
				object defaultValue = property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null;
 | 
									object defaultValue = property.PropertyType.IsValueType
 | 
				
			||||||
 | 
										? Activator.CreateInstance(property.PropertyType) 
 | 
				
			||||||
 | 
										: null;
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				if (value?.Equals(defaultValue) == false)
 | 
									if (value?.Equals(defaultValue) == false)
 | 
				
			||||||
					property.SetValue(first, value);
 | 
										property.SetValue(first, value);
 | 
				
			||||||
@ -88,5 +90,22 @@ namespace Kyoo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			return first;
 | 
								return first;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public static T Nullify<T>(T obj)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Type type = typeof(T);
 | 
				
			||||||
 | 
								foreach (PropertyInfo property in type.GetProperties())
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									if (!property.CanWrite)
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									object defaultValue = property.PropertyType.IsValueType 
 | 
				
			||||||
 | 
										? Activator.CreateInstance(property.PropertyType) 
 | 
				
			||||||
 | 
										: null;
 | 
				
			||||||
 | 
									property.SetValue(obj, defaultValue);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								return obj;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,8 +1,8 @@
 | 
				
			|||||||
using System;
 | 
					using System;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Kyoo.Models.Watch;
 | 
					 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using System.Linq;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
using Kyoo.Models.Exceptions;
 | 
					using Kyoo.Models.Exceptions;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -18,114 +18,22 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			_database = database;
 | 
								_database = database;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region Read the database
 | 
							#region GetBySlug
 | 
				
			||||||
		public IEnumerable<Library> GetLibraries()
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Libraries;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Library GetLibraryForShow(string showSlug)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.LibraryLinks.FirstOrDefault(x => x.Show.Slug == showSlug)?.Library;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<string> GetLibrariesPath()
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			IEnumerable<string> paths = new List<string>();
 | 
					 | 
				
			||||||
			return Enumerable.Aggregate(_database.Libraries, paths, (current, lib) => current.Concat(lib.Paths));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public (Track video, IEnumerable<Track> audios, IEnumerable<Track> subtitles) GetStreams(long episodeID, string episodeSlug)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			IEnumerable<Track> tracks = _database.Tracks.Where(track => track.EpisodeID == episodeID);
 | 
					 | 
				
			||||||
			return (tracks.FirstOrDefault(x => x.Type == StreamType.Video),
 | 
					 | 
				
			||||||
				tracks.Where(x => x.Type == StreamType.Audio),
 | 
					 | 
				
			||||||
				tracks.Where(track => track.Type == StreamType.Subtitle));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Track GetSubtitle(string showSlug, long seasonNumber, long episodeNumber, string languageTag, bool forced)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			long? showID = _database.Shows.FirstOrDefault(x => x.Slug == showSlug)?.ID;
 | 
					 | 
				
			||||||
			if (showID == null)
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
			return (from track in _database.Tracks where track.Episode.ShowID == showID 
 | 
					 | 
				
			||||||
													  && track.Episode.SeasonNumber == seasonNumber 
 | 
					 | 
				
			||||||
													  && track.Episode.EpisodeNumber == episodeNumber
 | 
					 | 
				
			||||||
													  && track.Language == languageTag select track).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Track GetSubtitleById(long id)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from track in _database.Tracks where track.ID == id select track).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Library GetLibrary(string librarySlug)
 | 
							public Library GetLibrary(string librarySlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from library in _database.Libraries where library.Slug == librarySlug select library).FirstOrDefault();
 | 
								return _database.Libraries.FirstOrDefault(library => library.Slug == librarySlug);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<Show> GetShows()
 | 
							public Collection GetCollection(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow())
 | 
								return _database.Collections.FirstOrDefault(col => col.Slug == slug);
 | 
				
			||||||
				.OrderBy(x => x.Title);
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public IEnumerable<Show> SearchShows(string searchQuery)
 | 
							public Show GetShow(string slug)
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Shows.FromSqlInterpolated($"SELECT * FROM Shows WHERE Shows.Title LIKE {"%" + searchQuery + "%"} OR Shows.Aliases LIKE {"%" + searchQuery + "%"}")
 | 
					 | 
				
			||||||
				.OrderBy(x => x.Title).Take(20);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Show GetShowBySlug(string slug)
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return _database.Shows.FirstOrDefault(show => show.Slug == slug);
 | 
								return _database.Shows.FirstOrDefault(show => show.Slug == slug);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public Show GetShow(string path)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from show in _database.Shows where show.Path == path select show).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Season> GetSeasons(long showID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from season in _database.Seasons where season.ShowID == showID select season)
 | 
					 | 
				
			||||||
				.OrderBy(x => x.SeasonNumber);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Season GetSeason(string showSlug, long seasonNumber)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from season in _database.Seasons
 | 
					 | 
				
			||||||
				where season.SeasonNumber == seasonNumber
 | 
					 | 
				
			||||||
					  && season.Show.Slug == showSlug
 | 
					 | 
				
			||||||
				select season).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public int GetSeasonCount(string showSlug, long seasonNumber)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from season in _database.Seasons
 | 
					 | 
				
			||||||
				where season.SeasonNumber == seasonNumber
 | 
					 | 
				
			||||||
					  && season.Show.Slug == showSlug
 | 
					 | 
				
			||||||
				select season).FirstOrDefault()?.Episodes.Count() ?? 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Episode> GetEpisodes(string showSlug)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Episodes.Where(episode => episode.Show.Slug == showSlug);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Episode> GetEpisodes(string showSlug, long seasonNumber)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Episodes.Where(x => x.SeasonNumber == seasonNumber
 | 
					 | 
				
			||||||
			                                           && x.Show.Slug == showSlug)
 | 
					 | 
				
			||||||
				.OrderBy(x => x.EpisodeNumber);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Episode> GetEpisodes(long showID, long seasonNumber)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Episodes.Where(x => x.ShowID == showID
 | 
					 | 
				
			||||||
			                                           && x.SeasonNumber == seasonNumber);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
 | 
							public Episode GetEpisode(string showSlug, long seasonNumber, long episodeNumber)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return _database.Episodes.FirstOrDefault(x => x.EpisodeNumber == episodeNumber
 | 
								return _database.Episodes.FirstOrDefault(x => x.EpisodeNumber == episodeNumber
 | 
				
			||||||
@ -133,61 +41,41 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			                                              && x.Show.Slug == showSlug);
 | 
								                                              && x.Show.Slug == showSlug);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public WatchItem GetWatchItem(string showSlug, long seasonNumber, long episodeNumber, bool complete = true)
 | 
							public Episode GetMovieEpisode(string movieSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem item = _database.Episodes.Where(x => x.SeasonNumber == seasonNumber
 | 
								return _database.Episodes.FirstOrDefault(x => x.Show.Slug == movieSlug);	
 | 
				
			||||||
			                                               && x.EpisodeNumber == episodeNumber
 | 
					 | 
				
			||||||
			                                               && x.Show.Slug == showSlug)
 | 
					 | 
				
			||||||
				.Select(x => new WatchItem(x)).FirstOrDefault();
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (item == null)
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			(item.Video, item.Audios, item.Subtitles) = GetStreams(item.EpisodeID, item.Link);
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (episodeNumber > 1)
 | 
					 | 
				
			||||||
				item.PreviousEpisode = Episode.GetSlug(showSlug, seasonNumber, episodeNumber - 1);
 | 
					 | 
				
			||||||
			else if (seasonNumber > 1)
 | 
					 | 
				
			||||||
				item.PreviousEpisode = Episode.GetSlug(showSlug, seasonNumber - 1, GetSeasonCount(showSlug, seasonNumber - 1));
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			if (episodeNumber >= GetSeasonCount(showSlug, seasonNumber))
 | 
					 | 
				
			||||||
				item.NextEpisode = GetEpisode(showSlug, seasonNumber + 1, 1);
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
				item.NextEpisode = GetEpisode(showSlug, seasonNumber, episodeNumber + 1);
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			return item;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public WatchItem GetMovieWatchItem(string movieSlug)
 | 
							public Genre GetGenre(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Show movie = _database.Shows.FirstOrDefault(x => x.Slug == movieSlug);
 | 
								return _database.Genres.FirstOrDefault(genre => genre.Slug == slug);
 | 
				
			||||||
			if (movie == null)
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
			Episode episode = _database.Episodes.FirstOrDefault(x => x.ShowID == movie.ID);
 | 
					 | 
				
			||||||
			if (episode == null)
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
			WatchItem item = new WatchItem(movie.ID, 
 | 
					 | 
				
			||||||
				movie.Title,
 | 
					 | 
				
			||||||
				movie.Slug,
 | 
					 | 
				
			||||||
				-1, 
 | 
					 | 
				
			||||||
				-1, 
 | 
					 | 
				
			||||||
				movie.Title,
 | 
					 | 
				
			||||||
				null,
 | 
					 | 
				
			||||||
				episode.Path);
 | 
					 | 
				
			||||||
			item.Link = movie.Slug;
 | 
					 | 
				
			||||||
			item.IsMovie = true;
 | 
					 | 
				
			||||||
			(item.Video, item.Audios, item.Subtitles) = GetStreams(item.EpisodeID, item.Link);
 | 
					 | 
				
			||||||
			return item;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public IEnumerable<PeopleLink> GetPeople(long showID)
 | 
							public Studio GetStudio(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return from link in _database.PeopleLinks where link.ShowID == showID orderby link.People.ImgPrimary == null, link.Name select link;
 | 
								return _database.Studios.FirstOrDefault(studio => studio.Slug == slug);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public People GetPeopleBySlug(string slug)
 | 
							public People GetPeople(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from people in _database.Peoples where people.Slug == slug select people).FirstOrDefault();
 | 
								return _database.Peoples.FirstOrDefault(people => people.Slug == slug);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							#endregion
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							#region GetAll
 | 
				
			||||||
 | 
							public IEnumerable<Library> GetLibraries()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.Libraries;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public IEnumerable<Show> GetShows()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.LibraryLinks.AsEnumerable().Select(x => x.Show ?? x.Collection.AsShow());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public IEnumerable<Episode> GetEpisodes()
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.Episodes;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<Genre> GetGenres()
 | 
							public IEnumerable<Genre> GetGenres()
 | 
				
			||||||
@ -195,60 +83,36 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return _database.Genres;
 | 
								return _database.Genres;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<Genre> GetGenreForShow(long showID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from show in _database.Shows where show.ID == showID select show.Genres).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public Genre GetGenreBySlug(string slug)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from genre in _database.Genres where genre.Slug == slug select genre).FirstOrDefault();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Studio> GetStudios()
 | 
							public IEnumerable<Studio> GetStudios()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return _database.Studios;
 | 
								return _database.Studios;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							#endregion
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public Studio GetStudio(long showID)
 | 
							#region GetHelper
 | 
				
			||||||
 | 
							public IEnumerable<string> GetLibrariesPath()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from show in _database.Shows where show.ID == showID select show.Studio).FirstOrDefault();
 | 
								IEnumerable<string> paths = new List<string>();
 | 
				
			||||||
 | 
								return Enumerable.Aggregate(_database.Libraries, paths, (current, lib) => current.Concat(lib.Paths));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public Studio GetStudioBySlug(string slug)
 | 
							public Show GetShowByPath(string path)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from studio in _database.Studios where studio.Slug == slug select studio).FirstOrDefault();
 | 
								return _database.Shows.FirstOrDefault(show => show.Path == path);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							#region Search
 | 
				
			||||||
 | 
							public IEnumerable<Collection> SearchCollections(string searchQuery)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.Collections.Where(collection => EF.Functions.Like(collection.Name, $"%{searchQuery}%"))
 | 
				
			||||||
 | 
									.Take(20);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public Collection GetCollection(string slug)
 | 
							public IEnumerable<Show> SearchShows(string searchQuery)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Collection collection = _database.Collections.FirstOrDefault(col => col.Slug == slug);
 | 
								return _database.Shows.FromSqlInterpolated($@"SELECT * FROM Shows WHERE Shows.Title LIKE {$"%{searchQuery}%"}
 | 
				
			||||||
			if (collection != null)
 | 
								                                           OR Shows.Aliases LIKE {$"%{searchQuery}%"}").Take(20);
 | 
				
			||||||
				collection.Shows = GetShowsInCollection(collection.ID);
 | 
					 | 
				
			||||||
			return collection;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Show> GetShowsInCollection(long collectionID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return from link in _database.CollectionLinks where link.CollectionID == collectionID select link.Show;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Show> GetShowsInLibrary(long libraryID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from link in _database.LibraryLinks where link.LibraryID == libraryID select link)
 | 
					 | 
				
			||||||
				.AsEnumerable()
 | 
					 | 
				
			||||||
				.Select(link => link.Show ?? link.Collection.AsShow())
 | 
					 | 
				
			||||||
				.OrderBy(x => x.Title);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Show> GetShowsByPeople(string peopleSlug)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from link in _database.PeopleLinks where link.PeopleID == peopleSlug select link.Show).OrderBy(x => x.Title);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public IEnumerable<Episode> GetAllEpisodes()
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return _database.Episodes;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<Episode> SearchEpisodes(string searchQuery)
 | 
							public IEnumerable<Episode> SearchEpisodes(string searchQuery)
 | 
				
			||||||
@ -256,102 +120,256 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return _database.Episodes.Where(x => EF.Functions.Like(x.Title, $"%{searchQuery}%")).Take(20);
 | 
								return _database.Episodes.Where(x => EF.Functions.Like(x.Title, $"%{searchQuery}%")).Take(20);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public IEnumerable<Collection> SearchCollections(string searchQuery)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from collection in _database.Collections where EF.Functions.Like(collection.Name, $"%{searchQuery}%") select collection)
 | 
					 | 
				
			||||||
				.OrderBy(x => x.Name).Take(20);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		public IEnumerable<People> SearchPeople(string searchQuery)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return (from people in _database.Peoples where EF.Functions.Like(people.Name, $"%{searchQuery}%") select people)
 | 
					 | 
				
			||||||
				.OrderBy(x => x.ImgPrimary == null)
 | 
					 | 
				
			||||||
				.ThenBy(x => x.Name)
 | 
					 | 
				
			||||||
				.Take(20);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		public IEnumerable<Genre> SearchGenres(string searchQuery)
 | 
							public IEnumerable<Genre> SearchGenres(string searchQuery)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from genre in _database.Genres where EF.Functions.Like(genre.Name, $"%{searchQuery}%") select genre)
 | 
								return _database.Genres.Where(genre => EF.Functions.Like(genre.Name, $"%{searchQuery}%"))
 | 
				
			||||||
				.Take(20);
 | 
									.Take(20);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<Studio> SearchStudios(string searchQuery)
 | 
							public IEnumerable<Studio> SearchStudios(string searchQuery)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return (from studio in _database.Studios where EF.Functions.Like(studio.Name, $"%{searchQuery}%") select studio)
 | 
								return _database.Studios.Where(studio => EF.Functions.Like(studio.Name, $"%{searchQuery}%"))
 | 
				
			||||||
 | 
									.Take(20);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public IEnumerable<People> SearchPeople(string searchQuery)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return _database.Peoples.Where(people => EF.Functions.Like(people.Name, $"%{searchQuery}%"))
 | 
				
			||||||
 | 
									.OrderBy(x => x.ImgPrimary == null)
 | 
				
			||||||
 | 
									.ThenBy(x => x.Name)
 | 
				
			||||||
				.Take(20);
 | 
									.Take(20);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		#endregion
 | 
							#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region Check if items exists
 | 
							#region Register
 | 
				
			||||||
		public bool IsCollectionRegistered(string collectionSlug, out long collectionID)
 | 
							public void Register(object obj)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Collection col = (from collection in _database.Collections where collection.Slug == collectionSlug select collection).FirstOrDefault();
 | 
								if (obj == null)
 | 
				
			||||||
			collectionID = col?.ID ?? -1;
 | 
									return;
 | 
				
			||||||
			return collectionID != -1;
 | 
								_database.Entry(obj).State = EntityState.Added;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public bool IsShowRegistered(string showPath, out long showID)
 | 
							public void RegisterShowLinks(Library library, Collection collection, Show show)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Show tmp = (from show in _database.Shows where show.Path == showPath select show).FirstOrDefault();
 | 
								if (collection != null)
 | 
				
			||||||
			showID = tmp?.ID ?? -1;
 | 
								{
 | 
				
			||||||
			return showID != -1;
 | 
									_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID}, x => x.LibraryID == library.ID && x.CollectionID == collection.ID && x.ShowID == null);
 | 
				
			||||||
 | 
									_database.CollectionLinks.AddIfNotExist(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID}, x => x.CollectionID == collection.ID && x.ShowID == show.ID);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, ShowID = show.ID}, x => x.LibraryID == library.ID && x.CollectionID == null && x.ShowID == show.ID);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public bool IsSeasonRegistered(long showID, long seasonNumber, out long seasonID)
 | 
							public Task SaveChanges()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Season tmp = (from season in _database.Seasons where season.SeasonNumber == seasonNumber && season.ShowID == showID select season).FirstOrDefault();
 | 
								return _database.SaveChangesAsync();
 | 
				
			||||||
			seasonID = tmp?.ID ?? -1;
 | 
					 | 
				
			||||||
			return seasonID != -1;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public bool IsEpisodeRegistered(string episodePath, out long episodeID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Episode tmp = (from episode in _database.Episodes where episode.Path == episodePath select episode).FirstOrDefault();
 | 
					 | 
				
			||||||
			episodeID = tmp?.ID ?? -1;
 | 
					 | 
				
			||||||
			return episodeID != -1;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public long GetOrCreateGenre(Genre genre)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Genre existingGenre = GetGenreBySlug(genre.Slug);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (existingGenre != null)
 | 
					 | 
				
			||||||
				return existingGenre.ID;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			_database.Genres.Add(genre);
 | 
					 | 
				
			||||||
			_database.SaveChanges();
 | 
					 | 
				
			||||||
			return genre.ID;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public long GetOrCreateStudio(Studio studio)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			Studio existingStudio = GetStudioBySlug(studio.Slug);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (existingStudio != null)
 | 
					 | 
				
			||||||
				return existingStudio.ID;
 | 
					 | 
				
			||||||
			
 | 
					 | 
				
			||||||
			_database.Studios.Add(studio);
 | 
					 | 
				
			||||||
			_database.SaveChanges();
 | 
					 | 
				
			||||||
			return studio.ID;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		#endregion
 | 
							#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#region Write Into The Database
 | 
							#region Edit
 | 
				
			||||||
		public long RegisterCollection(Collection collection)
 | 
					
 | 
				
			||||||
 | 
							public void Edit(Library edited, bool resetOld)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (collection == null)
 | 
								Edit(() =>
 | 
				
			||||||
				return 0;
 | 
								{
 | 
				
			||||||
			if (_database.Entry(collection).State == EntityState.Detached)
 | 
									var query = _database.Libraries
 | 
				
			||||||
				_database.Collections.Add(collection);
 | 
										.Include(x => x.Providers);
 | 
				
			||||||
			_database.SaveChanges();
 | 
									Library old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
			return collection.ID;
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No library could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public long RegisterLibrary(Library library)
 | 
							public void Edit(Collection edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Collections;
 | 
				
			||||||
 | 
									Collection old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No collection could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void Edit(Show edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Shows
 | 
				
			||||||
 | 
										.Include(x => x.GenreLinks)
 | 
				
			||||||
 | 
										.Include(x => x.People)
 | 
				
			||||||
 | 
										.Include(x => x.ExternalIDs);
 | 
				
			||||||
 | 
									Show old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No show could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void Edit(Season edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Seasons
 | 
				
			||||||
 | 
										.Include(x => x.ExternalIDs)
 | 
				
			||||||
 | 
										.Include(x => x.Episodes);
 | 
				
			||||||
 | 
									Season old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No season could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public void Edit(Episode edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Episodes
 | 
				
			||||||
 | 
										.Include(x => x.ExternalIDs)
 | 
				
			||||||
 | 
										.Include(x => x.Season)
 | 
				
			||||||
 | 
										.Include(x => x.Tracks);
 | 
				
			||||||
 | 
									Episode old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No episode could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public void Edit(Track edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									Track old = _database.Tracks.FirstOrDefault(x => x.ID == edited.ID);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No library track could be found with the id {edited.ID}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public void Edit(People edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Peoples
 | 
				
			||||||
 | 
										.Include(x => x.ExternalIDs);
 | 
				
			||||||
 | 
									People old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No people could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public void Edit(Studio edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Studios;
 | 
				
			||||||
 | 
									Studio old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No studio could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public void Edit(Genre edited, bool resetOld)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Edit(() =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									var query = _database.Genres;
 | 
				
			||||||
 | 
									Genre old = _database.Entry(edited).IsKeySet
 | 
				
			||||||
 | 
										? query.FirstOrDefault(x => x.ID == edited.ID)
 | 
				
			||||||
 | 
										: query.FirstOrDefault(x => x.Slug == edited.Slug);
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (old == null)
 | 
				
			||||||
 | 
										throw new ItemNotFound($"No genre could be found with the id {edited.ID} or the slug {edited.Slug}");
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									if (resetOld)
 | 
				
			||||||
 | 
										Utility.Nullify(old);
 | 
				
			||||||
 | 
									Utility.Complete(old, edited);
 | 
				
			||||||
 | 
									Validate(old);
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							private void Edit(Action applyFunction)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								_database.ChangeTracker.LazyLoadingEnabled = false;
 | 
				
			||||||
 | 
								_database.ChangeTracker.AutoDetectChangesEnabled = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								try
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									applyFunction.Invoke();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									_database.ChangeTracker.DetectChanges();
 | 
				
			||||||
 | 
									_database.SaveChanges();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								finally
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									_database.ChangeTracker.LazyLoadingEnabled = true;
 | 
				
			||||||
 | 
									_database.ChangeTracker.AutoDetectChangesEnabled = true;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							#endregion
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							#region ValidateValue
 | 
				
			||||||
 | 
							public Library Validate(Library library)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (library == null)
 | 
								if (library == null)
 | 
				
			||||||
				return 0;
 | 
									return null;
 | 
				
			||||||
			library.Providers = library.Providers.Select(x =>
 | 
								library.Providers = library.Providers.Select(x =>
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				x.Provider = _database.Providers.FirstOrDefault(y => y.Name == x.Name);
 | 
									x.Provider = _database.Providers.FirstOrDefault(y => y.Name == x.Name);
 | 
				
			||||||
@ -359,22 +377,125 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
					x.ProviderID = x.Provider.ID;
 | 
										x.ProviderID = x.Provider.ID;
 | 
				
			||||||
				return x;
 | 
									return x;
 | 
				
			||||||
			}).Where(x => x.Provider != null).ToList();
 | 
								}).Where(x => x.Provider != null).ToList();
 | 
				
			||||||
			if (_database.Entry(library).State == EntityState.Detached)
 | 
								return library;
 | 
				
			||||||
				_database.Libraries.Add(library);
 | 
					 | 
				
			||||||
			_database.SaveChanges();
 | 
					 | 
				
			||||||
			return library.ID;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public long RegisterShow(Show show)
 | 
							public Collection Validate(Collection collection)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (collection == null)
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								if (collection.Slug == null)
 | 
				
			||||||
 | 
									collection.Slug = Utility.ToSlug(collection.Name);
 | 
				
			||||||
 | 
								return collection;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Show Validate(Show show)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (show == null)
 | 
								if (show == null)
 | 
				
			||||||
				return 0;
 | 
									return null;
 | 
				
			||||||
			if (_database.Entry(show).State == EntityState.Detached)
 | 
								
 | 
				
			||||||
				_database.Shows.Add(show);
 | 
								show.Studio = Validate(show.Studio);
 | 
				
			||||||
			_database.SaveChanges();
 | 
					
 | 
				
			||||||
			return show.ID;
 | 
								show.GenreLinks = show.GenreLinks?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									x.Genre = Validate(x.Genre);
 | 
				
			||||||
 | 
									x.GenreID = x.Genre.ID;
 | 
				
			||||||
 | 
									return x;
 | 
				
			||||||
 | 
								}).ToList();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								show.People = show.People?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									x.People = Validate(x.People);
 | 
				
			||||||
 | 
									x.PeopleID = x.People.ID;
 | 
				
			||||||
 | 
									return x;
 | 
				
			||||||
 | 
								}).ToList();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								show.Seasons = show.Seasons?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return _database.Seasons.FirstOrDefault(y => y.ShowID == x.ShowID
 | 
				
			||||||
 | 
									                                             && y.SeasonNumber == x.SeasonNumber) ?? Validate(x);
 | 
				
			||||||
 | 
								}).ToList();
 | 
				
			||||||
 | 
								show.Episodes = show.Episodes?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return _database.Episodes.FirstOrDefault(y => y.ShowID == x.ShowID 
 | 
				
			||||||
 | 
									                                              && y.SeasonNumber == x.SeasonNumber
 | 
				
			||||||
 | 
									                                              && y.EpisodeNumber == x.EpisodeNumber) ?? Validate(x);
 | 
				
			||||||
 | 
								}).ToList();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								show.ExternalIDs = Validate(show.ExternalIDs);
 | 
				
			||||||
 | 
								return show;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Season Validate(Season season)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (season == null)
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								season.Episodes = season.Episodes?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return _database.Episodes.FirstOrDefault(y => y.ShowID == x.ShowID 
 | 
				
			||||||
 | 
									                                              && y.SeasonNumber == x.SeasonNumber
 | 
				
			||||||
 | 
									                                              && y.EpisodeNumber == x.EpisodeNumber) ?? Validate(x);
 | 
				
			||||||
 | 
								}).ToList();
 | 
				
			||||||
 | 
								season.ExternalIDs = Validate(season.ExternalIDs);
 | 
				
			||||||
 | 
								return season;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Episode Validate(Episode episode)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (episode == null)
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								Season old = _database.Seasons.FirstOrDefault(x => x.ShowID == episode.ShowID 
 | 
				
			||||||
 | 
								                                                       && x.SeasonNumber == episode.SeasonNumber);
 | 
				
			||||||
 | 
								if (old != null)
 | 
				
			||||||
 | 
									episode.Season = old;
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
									episode.Season.ExternalIDs = Validate(episode.Season.ExternalIDs);
 | 
				
			||||||
 | 
								episode.ExternalIDs = Validate(episode.ExternalIDs);
 | 
				
			||||||
 | 
								return episode;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Studio Validate(Studio studio)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (studio == null)
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								if (studio.Slug == null)
 | 
				
			||||||
 | 
									studio.Slug = Utility.ToSlug(studio.Name);
 | 
				
			||||||
 | 
								return _database.Studios.FirstOrDefault(x => x.Slug == studio.Slug) ?? studio;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public People Validate(People people)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (people == null)
 | 
				
			||||||
 | 
									return null;
 | 
				
			||||||
 | 
								if (people.Slug == null)
 | 
				
			||||||
 | 
									people.Slug = Utility.ToSlug(people.Name);
 | 
				
			||||||
 | 
								People old = _database.Peoples.FirstOrDefault(y => y.Slug == people.Slug);
 | 
				
			||||||
 | 
								if (old != null)
 | 
				
			||||||
 | 
									return old;
 | 
				
			||||||
 | 
								people.ExternalIDs = Validate(people.ExternalIDs);
 | 
				
			||||||
 | 
								return people;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							public Genre Validate(Genre genre)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								if (genre.Slug == null)
 | 
				
			||||||
 | 
									genre.Slug = Utility.ToSlug(genre.Name);
 | 
				
			||||||
 | 
								return _database.Genres.FirstOrDefault(y => y.Slug == genre.Slug) ?? genre;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							public IEnumerable<MetadataID> Validate(IEnumerable<MetadataID> ids)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return ids?.Select(x =>
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									x.Provider = _database.Providers.FirstOrDefault(y => y.Name == x.Provider.Name) ?? x.Provider;
 | 
				
			||||||
 | 
									x.ProviderID = x.Provider.ID;
 | 
				
			||||||
 | 
									return x;
 | 
				
			||||||
 | 
								}).GroupBy(x => x.Provider.Name).Select(x => x.First()).ToList();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public long EditShow(Show edited)
 | 
							public long EditShow(Show edited)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (edited == null)
 | 
								if (edited == null)
 | 
				
			||||||
@ -397,45 +518,6 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
				
 | 
									
 | 
				
			||||||
				Utility.Complete(show, edited);
 | 
									Utility.Complete(show, edited);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (edited.Studio != null)
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					if (edited.Studio.Slug == null)
 | 
					 | 
				
			||||||
						edited.Studio.Slug = Utility.ToSlug(edited.Studio.Name);
 | 
					 | 
				
			||||||
					Studio tmp = _database.Studios.FirstOrDefault(x => x.Slug == edited.Studio.Slug);
 | 
					 | 
				
			||||||
					if (tmp != null)
 | 
					 | 
				
			||||||
						show.Studio = tmp;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				show.GenreLinks = edited.GenreLinks?.Select(x =>
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					if (x.Genre.Slug == null)
 | 
					 | 
				
			||||||
						x.Genre.Slug = Utility.ToSlug(x.Genre.Name);
 | 
					 | 
				
			||||||
					x.Genre = _database.Genres.FirstOrDefault(y => y.Slug == x.Genre.Slug) ?? x.Genre;
 | 
					 | 
				
			||||||
					x.GenreID = x.Genre.ID;
 | 
					 | 
				
			||||||
					return x;
 | 
					 | 
				
			||||||
				}).ToList();
 | 
					 | 
				
			||||||
				show.People = edited.People?.Select(x =>
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					People people = _database.Peoples.FirstOrDefault(y => y.Slug == x.People.Slug);
 | 
					 | 
				
			||||||
					if (people != null)
 | 
					 | 
				
			||||||
						x.People = people;
 | 
					 | 
				
			||||||
					else
 | 
					 | 
				
			||||||
						x.People.ExternalIDs = ValidateExternalIDs(x.People.ExternalIDs);
 | 
					 | 
				
			||||||
					return x;
 | 
					 | 
				
			||||||
				}).ToList();
 | 
					 | 
				
			||||||
				show.Seasons = edited.Seasons?.Select(x =>
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					return _database.Seasons.FirstOrDefault(y => y.ShowID == x.ShowID
 | 
					 | 
				
			||||||
					                                             && y.SeasonNumber == x.SeasonNumber) ?? x;
 | 
					 | 
				
			||||||
				}).ToList();
 | 
					 | 
				
			||||||
				show.Episodes = edited.Episodes?.Select(x =>
 | 
					 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					return _database.Episodes.FirstOrDefault(y => y.ShowID == x.ShowID 
 | 
					 | 
				
			||||||
					                                              && y.SeasonNumber == x.SeasonNumber
 | 
					 | 
				
			||||||
					                                              && y.EpisodeNumber == x.EpisodeNumber) ?? x;
 | 
					 | 
				
			||||||
				}).ToList();
 | 
					 | 
				
			||||||
				show.ExternalIDs = ValidateExternalIDs(show.ExternalIDs);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				_database.ChangeTracker.DetectChanges();
 | 
									_database.ChangeTracker.DetectChanges();
 | 
				
			||||||
				_database.SaveChanges();
 | 
									_database.SaveChanges();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -448,16 +530,6 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return edited.ID;
 | 
								return edited.ID;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		public IEnumerable<MetadataID> ValidateExternalIDs(IEnumerable<MetadataID> ids)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			return ids?.Select(x =>
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				x.Provider = _database.Providers.FirstOrDefault(y => y.Name == x.Provider.Name) ?? x.Provider;
 | 
					 | 
				
			||||||
				x.ProviderID = x.Provider.ID;
 | 
					 | 
				
			||||||
				return x;
 | 
					 | 
				
			||||||
			}).GroupBy(x => x.Provider.Name).Select(x => x.First()).ToList();
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public long RegisterMovie(Episode movie)
 | 
							public long RegisterMovie(Episode movie)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (movie == null)
 | 
								if (movie == null)
 | 
				
			||||||
@ -500,13 +572,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
				
 | 
									
 | 
				
			||||||
				Utility.Complete(season, edited);
 | 
									Utility.Complete(season, edited);
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				season.Episodes = edited.Episodes?.Select(x =>
 | 
									
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					return _database.Episodes.FirstOrDefault(y => y.ShowID == x.ShowID 
 | 
					 | 
				
			||||||
					                                              && y.SeasonNumber == x.SeasonNumber
 | 
					 | 
				
			||||||
					                                              && y.EpisodeNumber == x.EpisodeNumber) ?? x;
 | 
					 | 
				
			||||||
				}).ToList();
 | 
					 | 
				
			||||||
				season.ExternalIDs = ValidateExternalIDs(season.ExternalIDs);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				_database.ChangeTracker.DetectChanges();
 | 
									_database.ChangeTracker.DetectChanges();
 | 
				
			||||||
				_database.SaveChanges();
 | 
									_database.SaveChanges();
 | 
				
			||||||
@ -551,13 +617,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
				
 | 
									
 | 
				
			||||||
				Utility.Complete(episode, edited);
 | 
									Utility.Complete(episode, edited);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (episode.SeasonNumber != -1)
 | 
									
 | 
				
			||||||
				{
 | 
					 | 
				
			||||||
					episode.Season = _database.Seasons.FirstOrDefault(x => x.ShowID == episode.ShowID
 | 
					 | 
				
			||||||
					                                                       && x.SeasonNumber == edited.SeasonNumber) ?? episode.Season;
 | 
					 | 
				
			||||||
					episode.Season.ExternalIDs = ValidateExternalIDs(episode.Season.ExternalIDs);
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				episode.ExternalIDs = ValidateExternalIDs(episode.ExternalIDs);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				_database.ChangeTracker.DetectChanges();
 | 
									_database.ChangeTracker.DetectChanges();
 | 
				
			||||||
				_database.SaveChanges();
 | 
									_database.SaveChanges();
 | 
				
			||||||
@ -571,43 +631,26 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return edited.ID;
 | 
								return edited.ID;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public long RegisterTrack(Track track)
 | 
							#region Remove
 | 
				
			||||||
 | 
							public void RemoveShow(Show show)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			_database.Tracks.Add(track);
 | 
								if (_database.Entry(show).State == EntityState.Detached)
 | 
				
			||||||
			_database.SaveChanges();
 | 
									_database.Shows.Attach(show);
 | 
				
			||||||
			return track.ID;
 | 
								_database.Shows.Remove(show);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void RegisterShowLinks(Library library, Collection collection, Show show)
 | 
							public void RemoveSeason(Season season)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (collection != null)
 | 
								if (_database.Entry(season).State == EntityState.Detached)
 | 
				
			||||||
			{
 | 
									_database.Seasons.Attach(season);
 | 
				
			||||||
				_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, CollectionID = collection.ID}, x => x.LibraryID == library.ID && x.CollectionID == collection.ID && x.ShowID == null);
 | 
								_database.Seasons.Remove(season);
 | 
				
			||||||
				_database.CollectionLinks.AddIfNotExist(new CollectionLink { CollectionID = collection.ID, ShowID = show.ID}, x => x.CollectionID == collection.ID && x.ShowID == show.ID);
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
				_database.LibraryLinks.AddIfNotExist(new LibraryLink {LibraryID = library.ID, ShowID = show.ID}, x => x.LibraryID == library.ID && x.CollectionID == null && x.ShowID == show.ID);
 | 
					 | 
				
			||||||
			_database.SaveChanges();
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public void RemoveShow(long showID)
 | 
							public void RemoveEpisode(Episode episode)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			_database.Shows.Remove(new Show {ID = showID});
 | 
								if (_database.Entry(episode).State == EntityState.Detached)
 | 
				
			||||||
		}
 | 
									_database.Episodes.Attach(episode);
 | 
				
			||||||
 | 
								_database.Episodes.Remove(episode);
 | 
				
			||||||
		public void RemoveSeason(long seasonID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			_database.Seasons.Remove(new Season {ID = seasonID});
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public void RemoveEpisode(long episodeID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			_database.Episodes.Remove(new Episode {ID = episodeID});
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		public void ClearSubtitles(long episodeID)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			_database.Tracks.RemoveRange(_database.Tracks.Where(x => x.EpisodeID == episodeID));
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		#endregion
 | 
							#endregion
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -47,24 +47,22 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			});
 | 
								});
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public async Task<string> Transmux(WatchItem episode)
 | 
							public async Task<string> Transmux(Episode episode)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string folder = Path.Combine(_transmuxPath, episode.Link);
 | 
								string folder = Path.Combine(_transmuxPath, episode.Slug);
 | 
				
			||||||
			string manifest = Path.Combine(folder, episode.Link + ".m3u8");
 | 
								string manifest = Path.Combine(folder, episode.Slug + ".m3u8");
 | 
				
			||||||
			float playableDuration = 0;
 | 
								float playableDuration = 0;
 | 
				
			||||||
			bool transmuxFailed = false;
 | 
								bool transmuxFailed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			try
 | 
								try
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Directory.CreateDirectory(folder);
 | 
									Directory.CreateDirectory(folder);
 | 
				
			||||||
				Debug.WriteLine("&Transmuxing " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (File.Exists(manifest))
 | 
									if (File.Exists(manifest))
 | 
				
			||||||
					return manifest;
 | 
										return manifest;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			catch (UnauthorizedAccessException)
 | 
								catch (UnauthorizedAccessException)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Console.Error.WriteLine($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
 | 
									await Console.Error.WriteLineAsync($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
 | 
				
			||||||
				return null;
 | 
									return null;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Task.Run(() => 
 | 
								Task.Run(() => 
 | 
				
			||||||
@ -76,35 +74,9 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			return transmuxFailed ? null : manifest;
 | 
								return transmuxFailed ? null : manifest;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public async Task<string> Transcode(WatchItem episode)
 | 
							public Task<string> Transcode(Episode episode)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return null; // Not implemented yet.
 | 
								return null; // Not implemented yet.
 | 
				
			||||||
			string folder = Path.Combine(_transcodePath, episode.Link);
 | 
					 | 
				
			||||||
			string manifest = Path.Combine(folder, episode.Link + ".m3u8");
 | 
					 | 
				
			||||||
			float playableDuration = 0;
 | 
					 | 
				
			||||||
			bool transcodeFailed = false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			try
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				Directory.CreateDirectory(folder);
 | 
					 | 
				
			||||||
				Debug.WriteLine("&Transcoding " + episode.Link + " at " + episode.Path + ", outputPath: " + folder);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
				if (File.Exists(manifest))
 | 
					 | 
				
			||||||
					return manifest;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			catch (UnauthorizedAccessException)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				Console.Error.WriteLine($"Access to the path {manifest} is denied. Please change your transmux path in the config.");
 | 
					 | 
				
			||||||
				return null;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			Task.Run(() =>
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				transcodeFailed = TranscoderAPI.transcode(episode.Path, manifest.Replace('\\', '/'), out playableDuration) != 0;
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
			while (playableDuration < 10 || (!File.Exists(manifest) && !transcodeFailed))
 | 
					 | 
				
			||||||
				await Task.Delay(10);
 | 
					 | 
				
			||||||
			return transcodeFailed ? null : manifest;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			try
 | 
								try
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				IEnumerable<Episode> episodes = _libraryManager.GetAllEpisodes();
 | 
									IEnumerable<Episode> episodes = _libraryManager.GetEpisodes();
 | 
				
			||||||
				IEnumerable<Library> libraries = argument == null 
 | 
									IEnumerable<Library> libraries = argument == null 
 | 
				
			||||||
					? _libraryManager.GetLibraries()
 | 
										? _libraryManager.GetLibraries()
 | 
				
			||||||
					: new [] {_libraryManager.GetLibrary(argument)};
 | 
										: new [] {_libraryManager.GetLibrary(argument)};
 | 
				
			||||||
@ -127,7 +127,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
		
 | 
							
 | 
				
			||||||
		private async Task<Show> GetShow(string showTitle, string showPath, bool isMovie, Library library)
 | 
							private async Task<Show> GetShow(string showTitle, string showPath, bool isMovie, Library library)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Show show = _libraryManager.GetShow(showPath);
 | 
								Show show = _libraryManager.GetShowByPath(showPath);
 | 
				
			||||||
			if (show != null)
 | 
								if (show != null)
 | 
				
			||||||
				return show;
 | 
									return show;
 | 
				
			||||||
			show = await _metadataProvider.SearchShow(showTitle, isMovie, library);
 | 
								show = await _metadataProvider.SearchShow(showTitle, isMovie, library);
 | 
				
			||||||
@ -135,7 +135,7 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			show.People = (await _metadataProvider.GetPeople(show, library)).GroupBy(x => x.Slug).Select(x => x.First())
 | 
								show.People = (await _metadataProvider.GetPeople(show, library)).GroupBy(x => x.Slug).Select(x => x.First())
 | 
				
			||||||
				.Select(x =>
 | 
									.Select(x =>
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					People existing = _libraryManager.GetPeopleBySlug(x.Slug);
 | 
										People existing = _libraryManager.GetPeople(x.Slug);
 | 
				
			||||||
					if (existing != null)
 | 
										if (existing != null)
 | 
				
			||||||
						return new PeopleLink(existing, show, x.Role, x.Type);
 | 
											return new PeopleLink(existing, show, x.Role, x.Type);
 | 
				
			||||||
					x.People.ExternalIDs = _libraryManager.ValidateExternalIDs(x.People.ExternalIDs);
 | 
										x.People.ExternalIDs = _libraryManager.ValidateExternalIDs(x.People.ExternalIDs);
 | 
				
			||||||
@ -144,12 +144,12 @@ namespace Kyoo.Controllers
 | 
				
			|||||||
			show.People = await _thumbnailsManager.Validate(show.People);
 | 
								show.People = await _thumbnailsManager.Validate(show.People);
 | 
				
			||||||
			show.Genres = show.Genres?.Select(x =>
 | 
								show.Genres = show.Genres?.Select(x =>
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Genre existing = _libraryManager.GetGenreBySlug(x.Slug);
 | 
									Genre existing = _libraryManager.GetGenre(x.Slug);
 | 
				
			||||||
				return existing ?? x;
 | 
									return existing ?? x;
 | 
				
			||||||
			});
 | 
								});
 | 
				
			||||||
			show.ExternalIDs = _libraryManager.ValidateExternalIDs(show.ExternalIDs);
 | 
								show.ExternalIDs = _libraryManager.ValidateExternalIDs(show.ExternalIDs);
 | 
				
			||||||
			if (show.Studio != null)
 | 
								if (show.Studio != null)
 | 
				
			||||||
				show.Studio = _libraryManager.GetStudioBySlug(show.Studio.Slug) ?? show.Studio;
 | 
									show.Studio = _libraryManager.GetStudio(show.Studio.Slug) ?? show.Studio;
 | 
				
			||||||
			await _thumbnailsManager.Validate(show);
 | 
								await _thumbnailsManager.Validate(show);
 | 
				
			||||||
			return show;
 | 
								return show;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -56,7 +56,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
			if (library == null)
 | 
								if (library == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return _libraryManager.GetShowsInLibrary(library.ID).ToList();
 | 
								return library.Shows.Concat(library.Collections.Select(x => x.AsShow())).ToList();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
using Kyoo.Controllers;
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using Kyoo.Controllers;
 | 
				
			||||||
using Kyoo.Models;
 | 
					using Kyoo.Models;
 | 
				
			||||||
using Microsoft.AspNetCore.Authorization;
 | 
					using Microsoft.AspNetCore.Authorization;
 | 
				
			||||||
using Microsoft.AspNetCore.Mvc;
 | 
					using Microsoft.AspNetCore.Mvc;
 | 
				
			||||||
@ -20,13 +21,13 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Read")]
 | 
							[Authorize(Policy="Read")]
 | 
				
			||||||
		public ActionResult<Collection> GetPeople(string peopleSlug)
 | 
							public ActionResult<Collection> GetPeople(string peopleSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			People people = _libraryManager.GetPeopleBySlug(peopleSlug);
 | 
								People people = _libraryManager.GetPeople(peopleSlug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (people == null)
 | 
								if (people == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
			Collection collection = new Collection(people.Slug, people.Name, null, null)
 | 
								Collection collection = new Collection(people.Slug, people.Name, null, null)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				Shows = _libraryManager.GetShowsByPeople(people.Slug),
 | 
									Shows = people.Roles.Select(x => x.Show),
 | 
				
			||||||
				Poster = "peopleimg/" + people.Slug
 | 
									Poster = "peopleimg/" + people.Slug
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
			return collection;
 | 
								return collection;
 | 
				
			||||||
 | 
				
			|||||||
@ -45,7 +45,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[JsonDetailed]
 | 
							[JsonDetailed]
 | 
				
			||||||
		public ActionResult<Show> GetShow(string slug)
 | 
							public ActionResult<Show> GetShow(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Show show = _libraryManager.GetShowBySlug(slug);
 | 
								Show show = _libraryManager.GetShow(slug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (show == null)
 | 
								if (show == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
@ -96,7 +96,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy = "Write")]
 | 
							[Authorize(Policy = "Write")]
 | 
				
			||||||
		public async Task<IActionResult> DownloadImages(string slug)
 | 
							public async Task<IActionResult> DownloadImages(string slug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			Show show = _libraryManager.GetShowBySlug(slug);
 | 
								Show show = _libraryManager.GetShow(slug);
 | 
				
			||||||
			if (show == null)
 | 
								if (show == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
			await _thumbnailsManager.Validate(show, true);
 | 
								await _thumbnailsManager.Validate(show, true);
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Read")]
 | 
							[Authorize(Policy="Read")]
 | 
				
			||||||
		public IActionResult GetShowThumb(string showSlug)
 | 
							public IActionResult GetShowThumb(string showSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string path = _libraryManager.GetShowBySlug(showSlug)?.Path;
 | 
								string path = _libraryManager.GetShow(showSlug)?.Path;
 | 
				
			||||||
			if (path == null)
 | 
								if (path == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -37,7 +37,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Read")]
 | 
							[Authorize(Policy="Read")]
 | 
				
			||||||
		public IActionResult GetShowLogo(string showSlug)
 | 
							public IActionResult GetShowLogo(string showSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string path = _libraryManager.GetShowBySlug(showSlug)?.Path;
 | 
								string path = _libraryManager.GetShow(showSlug)?.Path;
 | 
				
			||||||
			if (path == null)
 | 
								if (path == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,7 +52,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Read")]
 | 
							[Authorize(Policy="Read")]
 | 
				
			||||||
		public IActionResult GetShowBackdrop(string showSlug)
 | 
							public IActionResult GetShowBackdrop(string showSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			string path = _libraryManager.GetShowBySlug(showSlug)?.Path;
 | 
								string path = _libraryManager.GetShow(showSlug)?.Path;
 | 
				
			||||||
			if (path == null)
 | 
								if (path == null)
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Play")]
 | 
							[Authorize(Policy="Play")]
 | 
				
			||||||
		public IActionResult Index(string showSlug, long seasonNumber, long episodeNumber)
 | 
							public IActionResult Index(string showSlug, long seasonNumber, long episodeNumber)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem episode = _libraryManager.GetWatchItem(showSlug, seasonNumber, episodeNumber);
 | 
								Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (episode != null && System.IO.File.Exists(episode.Path))
 | 
								if (episode != null && System.IO.File.Exists(episode.Path))
 | 
				
			||||||
				return PhysicalFile(episode.Path, "video/x-matroska", true);
 | 
									return PhysicalFile(episode.Path, "video/x-matroska", true);
 | 
				
			||||||
@ -40,7 +40,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Play")]
 | 
							[Authorize(Policy="Play")]
 | 
				
			||||||
		public async Task<IActionResult> Transmux(string showSlug, long seasonNumber, long episodeNumber)
 | 
							public async Task<IActionResult> Transmux(string showSlug, long seasonNumber, long episodeNumber)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem episode = _libraryManager.GetWatchItem(showSlug, seasonNumber, episodeNumber);
 | 
								Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
								if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
@ -63,7 +63,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Play")]
 | 
							[Authorize(Policy="Play")]
 | 
				
			||||||
		public async Task<IActionResult> Transcode(string showSlug, long seasonNumber, long episodeNumber)
 | 
							public async Task<IActionResult> Transcode(string showSlug, long seasonNumber, long episodeNumber)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem episode = _libraryManager.GetWatchItem(showSlug, seasonNumber, episodeNumber);
 | 
								Episode episode = _libraryManager.GetEpisode(showSlug, seasonNumber, episodeNumber);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
								if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
@ -98,7 +98,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Play")]
 | 
							[Authorize(Policy="Play")]
 | 
				
			||||||
		public async Task<IActionResult> Transmux(string movieSlug)
 | 
							public async Task<IActionResult> Transmux(string movieSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem episode = _libraryManager.GetMovieWatchItem(movieSlug);
 | 
								Episode episode = _libraryManager.GetMovieEpisode(movieSlug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
								if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
@ -112,7 +112,7 @@ namespace Kyoo.Api
 | 
				
			|||||||
		[Authorize(Policy="Play")]
 | 
							[Authorize(Policy="Play")]
 | 
				
			||||||
		public async Task<IActionResult> Transcode(string movieSlug)
 | 
							public async Task<IActionResult> Transcode(string movieSlug)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			WatchItem episode = _libraryManager.GetMovieWatchItem(movieSlug);
 | 
								Episode episode = _libraryManager.GetMovieEpisode(movieSlug);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
								if (episode == null || !System.IO.File.Exists(episode.Path))
 | 
				
			||||||
				return NotFound();
 | 
									return NotFound();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user