mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-10-31 10:37:13 -04:00 
			
		
		
		
	Finishing the rework of external ids
This commit is contained in:
		
							parent
							
								
									49618ccd03
								
							
						
					
					
						commit
						8b6e24c575
					
				| @ -11,7 +11,7 @@ | ||||
| 		<Company>SDG</Company> | ||||
| 		<PackageLicenseExpression>GPL-3.0-or-later</PackageLicenseExpression> | ||||
| 		<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance> | ||||
| 		<PackageVersion>1.0.18</PackageVersion> | ||||
| 		<PackageVersion>1.0.19</PackageVersion> | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
|  | ||||
| @ -1,22 +1,24 @@ | ||||
| using Newtonsoft.Json; | ||||
| 
 | ||||
| namespace Kyoo.Models | ||||
| { | ||||
| 	public class MetadataID | ||||
| 	{ | ||||
| 		public long ID { get; set; } | ||||
| 		public long ProviderID { get; set; } | ||||
| 		[JsonIgnore] public long ID { get; set; } | ||||
| 		[JsonIgnore] public long ProviderID { get; set; } | ||||
| 		public virtual ProviderID Provider {get; set; } | ||||
| 		 | ||||
| 		public long? ShowID { get; set; }  | ||||
| 		public virtual Show Show { get; set; } | ||||
| 		[JsonIgnore] public long? ShowID { get; set; }  | ||||
| 		[JsonIgnore] public virtual Show Show { get; set; } | ||||
| 		 | ||||
| 		public long? EpisodeID { get; set; }  | ||||
| 		public virtual Episode Episode { get; set; } | ||||
| 		[JsonIgnore] public long? EpisodeID { get; set; }  | ||||
| 		[JsonIgnore] public virtual Episode Episode { get; set; } | ||||
| 		 | ||||
| 		public long? SeasonID { get; set; }  | ||||
| 		public virtual Season Season { get; set; } | ||||
| 		[JsonIgnore] public long? SeasonID { get; set; }  | ||||
| 		[JsonIgnore] public virtual Season Season { get; set; } | ||||
| 		 | ||||
| 		public long? PeopleID { get; set; }  | ||||
| 		public virtual People People { get; set; } | ||||
| 		[JsonIgnore] public long? PeopleID { get; set; }  | ||||
| 		[JsonIgnore] public virtual People People { get; set; } | ||||
| 		 | ||||
| 		public string DataID { get; set; } | ||||
| 		public string Link { get; set; } | ||||
|  | ||||
| @ -1,8 +1,10 @@ | ||||
| using Newtonsoft.Json; | ||||
| 
 | ||||
| namespace Kyoo.Models | ||||
| { | ||||
| 	public class ProviderID | ||||
| 	{ | ||||
| 		public long ID { get; set; } | ||||
| 		[JsonIgnore] public long ID { get; set; } | ||||
| 		public string Name { get; set; } | ||||
| 		public string Logo { get; set; } | ||||
| 
 | ||||
|  | ||||
| @ -1,16 +1,19 @@ | ||||
| using Newtonsoft.Json; | ||||
| 
 | ||||
| namespace Kyoo.Models | ||||
| { | ||||
| 	public class ProviderLink | ||||
| 	{ | ||||
| 		public long ID { get; set; } | ||||
| 		public long ProviderID { get; set; } | ||||
| 		public virtual ProviderID Provider { get; set; } | ||||
| 		public long? ShowID { get; set; } | ||||
| 		public virtual Show Show { get; set; } | ||||
| 		public long? LibraryID { get; set; } | ||||
| 		public virtual Library Library { get; set; } | ||||
| 		[JsonIgnore] public long ID { get; set; } | ||||
| 		[JsonIgnore] public long ProviderID { get; set; } | ||||
| 		[JsonIgnore] public virtual ProviderID Provider { get; set; } | ||||
| 		[JsonIgnore] public long? ShowID { get; set; } | ||||
| 		[JsonIgnore] public virtual Show Show { get; set; } | ||||
| 		[JsonIgnore] public long? LibraryID { get; set; } | ||||
| 		[JsonIgnore] public virtual Library Library { get; set; } | ||||
| 
 | ||||
| 		public string Name => Provider.Name; | ||||
| 		public string Logo => Provider.Logo; | ||||
| 		 | ||||
| 		public ProviderLink() { } | ||||
| 	} | ||||
|  | ||||
| @ -102,7 +102,7 @@ namespace Kyoo.Models | ||||
| 
 | ||||
| 		public string GetID(string provider) | ||||
| 		{ | ||||
| 			return ExternalIDs.FirstOrDefault(x => x.Provider.Name == provider)?.DataID; | ||||
| 			return ExternalIDs?.FirstOrDefault(x => x.Provider.Name == provider)?.DataID; | ||||
| 		} | ||||
| 		 | ||||
| 		public Show Merge(Show other) | ||||
|  | ||||
| @ -144,6 +144,9 @@ namespace Kyoo | ||||
| 			modelBuilder.Entity<Studio>() | ||||
| 				.HasIndex(x => x.Slug) | ||||
| 				.IsUnique(); | ||||
| 			modelBuilder.Entity<ProviderID>() | ||||
| 				.HasIndex(x => x.Name) | ||||
| 				.IsUnique(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -9,7 +9,8 @@ namespace Kyoo.Tasks | ||||
| 		{ | ||||
| 			new CreateDatabase(), | ||||
| 			new PluginLoader(), | ||||
| 			new Crawler() | ||||
| 			new Crawler(), | ||||
| 			new MetadataLoader() | ||||
| 		}; | ||||
| 	} | ||||
| } | ||||
| @ -140,7 +140,7 @@ namespace Kyoo.Controllers | ||||
| 					return existing != null ? new PeopleLink(existing, show, x.Role, x.Type) : x; | ||||
| 				}).ToList(); | ||||
| 			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); | ||||
| 				return existing ?? x; | ||||
|  | ||||
							
								
								
									
										41
									
								
								Kyoo/Tasks/MetadataLoader.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								Kyoo/Tasks/MetadataLoader.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Threading; | ||||
| using System.Threading.Tasks; | ||||
| using Kyoo.Controllers; | ||||
| using Kyoo.Models; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| 
 | ||||
| namespace Kyoo.Tasks | ||||
| { | ||||
| 	public class MetadataLoader : ITask | ||||
| 	{ | ||||
| 		public string Slug => "reload-metdata"; | ||||
| 		public string Name => "Reload Metadata Providers"; | ||||
| 		public string Description => "Add every loaded metadata provider to the database."; | ||||
| 		public string HelpMessage => null; | ||||
| 		public bool RunOnStartup => true; | ||||
| 		public int Priority => 1000; | ||||
| 		 | ||||
| 		public Task Run(IServiceProvider serviceProvider, CancellationToken cancellationToken, string arguments = null) | ||||
| 		{ | ||||
| 			using IServiceScope serviceScope = serviceProvider.CreateScope(); | ||||
| 			DatabaseContext database = serviceScope.ServiceProvider.GetService<DatabaseContext>(); | ||||
| 			IPluginManager pluginManager = serviceScope.ServiceProvider.GetService<IPluginManager>(); | ||||
| 			foreach (IMetadataProvider provider in pluginManager.GetPlugins<IMetadataProvider>()) | ||||
| 				database.ProviderIds.AddIfNotExist(provider.Provider, x => x.Name == provider.Provider.Name); | ||||
| 			database.SaveChanges(); | ||||
| 			return Task.CompletedTask; | ||||
| 		} | ||||
| 
 | ||||
| 		public IEnumerable<string> GetPossibleParameters() | ||||
| 		{ | ||||
| 			return null; | ||||
| 		} | ||||
| 
 | ||||
| 		public int? Progress() | ||||
| 		{ | ||||
| 			return null; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user