mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Implementing the season creator.
This commit is contained in:
parent
69a8ec1c18
commit
9706c840c9
@ -54,17 +54,17 @@ namespace Kyoo.InternalAPI
|
||||
Regex regex = new Regex(patern, RegexOptions.IgnoreCase);
|
||||
Match match = regex.Match(file);
|
||||
|
||||
string ShowPath = Path.GetDirectoryName(file);
|
||||
string ShowTitle = match.Groups["ShowTitle"].Value;
|
||||
string showPath = Path.GetDirectoryName(file);
|
||||
string showName = match.Groups["ShowTitle"].Value;
|
||||
bool seasonSuccess = long.TryParse(match.Groups["Season"].Value, out long seasonNumber);
|
||||
bool episodeSucess = long.TryParse(match.Groups["Episode"].Value, out long episodeNumber);
|
||||
|
||||
Debug.WriteLine("&ShowPath: " + ShowPath + " Show: " + ShowTitle + " season: " + seasonNumber + " episode: " + episodeNumber);
|
||||
Debug.WriteLine("&ShowPath: " + showPath + " Show: " + showName + " season: " + seasonNumber + " episode: " + episodeNumber);
|
||||
|
||||
if (!libraryManager.IsShowRegistered(ShowPath, out long showID))
|
||||
if (!libraryManager.IsShowRegistered(showPath, out long showID))
|
||||
{
|
||||
Debug.WriteLine("&Should register show: " + ShowTitle);
|
||||
Show show = await metadataProvider.GetShowFromName(ShowTitle, ShowPath);
|
||||
Debug.WriteLine("&Should register show: " + showName);
|
||||
Show show = await metadataProvider.GetShowFromName(showName, showPath);
|
||||
showID = libraryManager.RegisterShow(show);
|
||||
}
|
||||
|
||||
@ -72,8 +72,9 @@ namespace Kyoo.InternalAPI
|
||||
|
||||
if(!libraryManager.IsSeasonRegistered(showID, seasonNumber, out long seasonID))
|
||||
{
|
||||
Debug.WriteLine("&Should register season: " + ShowTitle + " - " + seasonNumber);
|
||||
Season season = await metadataProvider.GetSeason(showID, seasonNumber);
|
||||
Debug.WriteLine("&Should register season: " + showName + " - " + seasonNumber);
|
||||
Season season = await metadataProvider.GetSeason(showName, seasonNumber);
|
||||
season.ShowID = showID;
|
||||
showID = libraryManager.RegisterSeason(season);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ namespace Kyoo.InternalAPI
|
||||
Task<Show> GetImages(Show show);
|
||||
|
||||
//For the seasons
|
||||
Task<Season> GetSeason(string showName, int seasonNumber);
|
||||
Task<Season> GetSeason(string showName, long seasonNumber);
|
||||
|
||||
Task<string> GetSeasonImage(string showName, long seasonNumber);
|
||||
}
|
||||
}
|
||||
|
@ -215,43 +215,55 @@ namespace Kyoo.InternalAPI.MetadataProvider
|
||||
|
||||
foreach (KeyValuePair<ImageType, string> type in imageTypes)
|
||||
{
|
||||
WebRequest request = WebRequest.Create("https://api.thetvdb.com/series/" + id + "/images/query?keyType=" + type.Value);
|
||||
request.Method = "GET";
|
||||
request.Timeout = 12000;
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
|
||||
|
||||
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
try
|
||||
{
|
||||
Stream stream = response.GetResponseStream();
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
string content = await reader.ReadToEndAsync();
|
||||
stream.Close();
|
||||
response.Close();
|
||||
WebRequest request = WebRequest.Create("https://api.thetvdb.com/series/" + id + "/images/query?keyType=" + type.Value);
|
||||
request.Method = "GET";
|
||||
request.Timeout = 12000;
|
||||
request.ContentType = "application/json";
|
||||
request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token);
|
||||
|
||||
var model = new { data = new ImageTvDb[0], error = new ErrorsTvDB() };
|
||||
//Should implement language selection here
|
||||
ImageTvDb data = JsonConvert.DeserializeAnonymousType(content, model).data.OrderByDescending(x => x.ratingsInfo.average).ThenByDescending(x => x.ratingsInfo.count).FirstOrDefault();
|
||||
IEnumerable<ImageTvDb> datas = JsonConvert.DeserializeAnonymousType(content, model).data.OrderByDescending(x => x.ratingsInfo.average).ThenByDescending(x => x.ratingsInfo.count);
|
||||
SetImage(show, "https://www.thetvdb.com/banners/" + data.fileName, type.Key);
|
||||
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
Stream stream = response.GetResponseStream();
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
string content = await reader.ReadToEndAsync();
|
||||
stream.Close();
|
||||
response.Close();
|
||||
|
||||
var model = new { data = new ImageTvDb[0], error = new ErrorsTvDB() };
|
||||
//Should implement language selection here
|
||||
ImageTvDb data = JsonConvert.DeserializeAnonymousType(content, model).data.OrderByDescending(x => x.ratingsInfo.average).ThenByDescending(x => x.ratingsInfo.count).FirstOrDefault();
|
||||
IEnumerable<ImageTvDb> datas = JsonConvert.DeserializeAnonymousType(content, model).data.OrderByDescending(x => x.ratingsInfo.average).ThenByDescending(x => x.ratingsInfo.count);
|
||||
SetImage(show, "https://www.thetvdb.com/banners/" + data.fileName, type.Key);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("&TheTvDB Provider couldn't get " + type + " for the show with the id: " + id + ".\nError Code: " + response.StatusCode + " Message: " + response.StatusDescription);
|
||||
response.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (WebException ex)
|
||||
{
|
||||
Debug.WriteLine("&TheTvDB Provider couldn't get " + type + " for the show with the id: " + id + ".\nError Code: " + response.StatusCode + " Message: " + response.StatusDescription);
|
||||
response.Close();
|
||||
Debug.WriteLine("&TheTvDB Provider couldn't get " + type + " for the show with the id: " + id + ".\nError Code: " + ex.Status);
|
||||
}
|
||||
}
|
||||
|
||||
return show;
|
||||
}
|
||||
|
||||
public Task<Season> GetSeason(string showName, int seasonNumber)
|
||||
public Task<Season> GetSeason(string showName, long seasonNumber)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return new Season(-1, -1, seasonNumber, "Season " + seasonNumber, null, null, null, null);
|
||||
}
|
||||
|
||||
public Task<string> GetSeasonImage(string showName, long seasonNumber)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using Kyoo.Models;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
@ -25,32 +26,37 @@ namespace Kyoo.InternalAPI
|
||||
providers.Clear();
|
||||
providers.Add(new ProviderTheTvDB());
|
||||
|
||||
string[] pluginsPaths = Directory.GetFiles(config.GetValue<string>("providerPlugins"));
|
||||
List<Assembly> plugins = new List<Assembly>();
|
||||
List<Type> types = new List<Type>();
|
||||
string pluginFolder = config.GetValue<string>("providerPlugins");
|
||||
|
||||
for (int i = 0; i < pluginsPaths.Length; i++)
|
||||
if (Directory.Exists(pluginFolder))
|
||||
{
|
||||
plugins.Add(Assembly.LoadFile(pluginsPaths[i]));
|
||||
types.AddRange(plugins[i].GetTypes());
|
||||
}
|
||||
string[] pluginsPaths = Directory.GetFiles(pluginFolder);
|
||||
List<Assembly> plugins = new List<Assembly>();
|
||||
List<Type> types = new List<Type>();
|
||||
|
||||
List<Type> providersPlugins = types.FindAll(x =>
|
||||
{
|
||||
object[] atr = x.GetCustomAttributes(typeof(MetaProvider), false);
|
||||
for (int i = 0; i < pluginsPaths.Length; i++)
|
||||
{
|
||||
plugins.Add(Assembly.LoadFile(pluginsPaths[i]));
|
||||
types.AddRange(plugins[i].GetTypes());
|
||||
}
|
||||
|
||||
List<Type> providersPlugins = types.FindAll(x =>
|
||||
{
|
||||
object[] atr = x.GetCustomAttributes(typeof(MetaProvider), false);
|
||||
|
||||
if (atr == null || atr.Length == 0)
|
||||
return false;
|
||||
|
||||
List<Type> interfaces = new List<Type>(x.GetInterfaces());
|
||||
|
||||
if (interfaces.Contains(typeof(IMetadataProvider)))
|
||||
return true;
|
||||
|
||||
if (atr == null || atr.Length == 0)
|
||||
return false;
|
||||
});
|
||||
|
||||
List<Type> interfaces = new List<Type>(x.GetInterfaces());
|
||||
|
||||
if (interfaces.Contains(typeof(IMetadataProvider)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
providers.AddRange(providersPlugins.ConvertAll<IMetadataProvider>(x => Activator.CreateInstance(x) as IMetadataProvider));
|
||||
providers.AddRange(providersPlugins.ConvertAll<IMetadataProvider>(x => Activator.CreateInstance(x) as IMetadataProvider));
|
||||
}
|
||||
}
|
||||
|
||||
//public Show MergeShows(Show baseShow, Show newShow)
|
||||
@ -80,5 +86,15 @@ namespace Kyoo.InternalAPI
|
||||
{
|
||||
return providers[0].GetShowFromName(showName, showPath);
|
||||
}
|
||||
|
||||
public Task<Season> GetSeason(string showName, long seasonNumber)
|
||||
{
|
||||
return providers[0].GetSeason(showName, seasonNumber);
|
||||
}
|
||||
|
||||
public Task<string> GetSeasonImage(string showName, long seasonNumber)
|
||||
{
|
||||
return providers[0].GetSeasonImage(showName, seasonNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,28 @@
|
||||
public class Season
|
||||
{
|
||||
public readonly long id;
|
||||
public readonly long ShowID;
|
||||
public long ShowID;
|
||||
|
||||
public long seasonNumber;
|
||||
public string Title;
|
||||
public string Overview;
|
||||
public long year;
|
||||
public long? year;
|
||||
|
||||
public string ImgPrimary;
|
||||
public string ExternalIDs;
|
||||
|
||||
public Season() { }
|
||||
|
||||
public Season(long id, long showID, long seasonNumber, string title, string overview, long? year, string imgPrimary, string externalIDs)
|
||||
{
|
||||
this.id = id;
|
||||
ShowID = showID;
|
||||
this.seasonNumber = seasonNumber;
|
||||
Title = title;
|
||||
Overview = overview;
|
||||
this.year = year;
|
||||
ImgPrimary = imgPrimary;
|
||||
ExternalIDs = externalIDs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user