From eb63e0d264d563b100a353c12859f226e9303910 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 7 Sep 2017 14:17:18 -0400 Subject: update image processor --- .../Services/SwaggerService.cs | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 Emby.Server.Implementations/Services/SwaggerService.cs (limited to 'Emby.Server.Implementations/Services/SwaggerService.cs') diff --git a/Emby.Server.Implementations/Services/SwaggerService.cs b/Emby.Server.Implementations/Services/SwaggerService.cs new file mode 100644 index 000000000..4590369fa --- /dev/null +++ b/Emby.Server.Implementations/Services/SwaggerService.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MediaBrowser.Model.Services; + +namespace Emby.Server.Implementations.Services +{ + [Route("/swagger", "GET", Summary = "Gets the swagger specifications")] + [Route("/swagger.json", "GET", Summary = "Gets the swagger specifications")] + public class GetSwaggerSpec : IReturn + { + } + + public class SwaggerSpec + { + public string swagger { get; set; } + public string[] schemes { get; set; } + public SwaggerInfo info { get; set; } + public string host { get; set; } + public string basePath { get; set; } + public SwaggerTag[] tags { get; set; } + public Dictionary> paths { get; set; } + public Dictionary definitions { get; set; } + } + + public class SwaggerInfo + { + public string description { get; set; } + public string version { get; set; } + public string title { get; set; } + + public SwaggerConcactInfo contact { get; set; } + } + + public class SwaggerConcactInfo + { + public string email { get; set; } + } + + public class SwaggerTag + { + public string description { get; set; } + public string name { get; set; } + } + + public class SwaggerMethod + { + public string summary { get; set; } + public string description { get; set; } + public string[] tags { get; set; } + public string operationId { get; set; } + public string[] consumes { get; set; } + public string[] produces { get; set; } + public SwaggerParam[] parameters { get; set; } + public Dictionary responses { get; set; } + } + + public class SwaggerParam + { + public string @in { get; set; } + public string name { get; set; } + public string description { get; set; } + public bool required { get; set; } + public string type { get; set; } + public string collectionFormat { get; set; } + } + + public class SwaggerResponse + { + public string description { get; set; } + + // ex. "$ref":"#/definitions/Pet" + public Dictionary schema { get; set; } + } + + public class SwaggerDefinition + { + public string type { get; set; } + public Dictionary properties { get; set; } + } + + public class SwaggerProperty + { + public string type { get; set; } + public string format { get; set; } + public string description { get; set; } + public string[] @enum { get; set; } + public string @default { get; set; } + } + + public class SwaggerService : IService + { + private SwaggerSpec _spec; + + public object Get(GetSwaggerSpec request) + { + return _spec ?? (_spec = GetSpec()); + } + + private SwaggerSpec GetSpec() + { + var spec = new SwaggerSpec + { + schemes = new[] { "http" }, + tags = GetTags(), + swagger = "2.0", + info = new SwaggerInfo + { + title = "Emby Server API", + version = "1", + description = "Explore the Emby Server API", + contact = new SwaggerConcactInfo + { + email = "api@emby.media" + } + }, + paths = GetPaths(), + definitions = GetDefinitions() + }; + + return spec; + } + + + private SwaggerTag[] GetTags() + { + return new SwaggerTag[] { }; + } + + private Dictionary GetDefinitions() + { + return new Dictionary(); + } + + private Dictionary> GetPaths() + { + var paths = new Dictionary>(); + + var all = ServiceController.Instance.RestPathMap.ToList(); + + foreach (var current in all) + { + foreach (var info in current.Value) + { + paths[info.Path] = GetPathInfo(info); + } + } + + return paths; + } + + private Dictionary GetPathInfo(RestPath info) + { + var result = new Dictionary(); + + foreach (var verb in info.Verbs) + { + result[verb] = new SwaggerMethod + { + summary = info.Summary, + produces = new[] + { + "application/json", + "application/xml" + }, + consumes = new[] + { + "application/json", + "application/xml" + }, + operationId = info.RequestType.Name, + tags = new string[] { }, + + parameters = new SwaggerParam[] { } + }; + } + + return result; + } + } +} -- cgit v1.2.3 From b6ec767ea06dba1a0a7d28aad7f69d10bb2b5720 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Sep 2017 14:20:48 -0400 Subject: update swagger --- .../Services/SwaggerService.cs | 47 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'Emby.Server.Implementations/Services/SwaggerService.cs') diff --git a/Emby.Server.Implementations/Services/SwaggerService.cs b/Emby.Server.Implementations/Services/SwaggerService.cs index 4590369fa..d684dce5d 100644 --- a/Emby.Server.Implementations/Services/SwaggerService.cs +++ b/Emby.Server.Implementations/Services/SwaggerService.cs @@ -30,6 +30,7 @@ namespace Emby.Server.Implementations.Services public string description { get; set; } public string version { get; set; } public string title { get; set; } + public string termsOfService { get; set; } public SwaggerConcactInfo contact { get; set; } } @@ -90,10 +91,12 @@ namespace Emby.Server.Implementations.Services public string @default { get; set; } } - public class SwaggerService : IService + public class SwaggerService : IService, IRequiresRequest { private SwaggerSpec _spec; + public IRequest Request { get; set; } + public object Get(GetSwaggerSpec request) { return _spec ?? (_spec = GetSpec()); @@ -101,6 +104,13 @@ namespace Emby.Server.Implementations.Services private SwaggerSpec GetSpec() { + string host = null; + Uri uri; + if (Uri.TryCreate(Request.RawUrl, UriKind.Absolute, out uri)) + { + host = uri.Host; + } + var spec = new SwaggerSpec { schemes = new[] { "http" }, @@ -109,15 +119,18 @@ namespace Emby.Server.Implementations.Services info = new SwaggerInfo { title = "Emby Server API", - version = "1", + version = "1.0.0", description = "Explore the Emby Server API", contact = new SwaggerConcactInfo { email = "api@emby.media" - } + }, + termsOfService = "https://emby.media/terms" }, paths = GetPaths(), - definitions = GetDefinitions() + definitions = GetDefinitions(), + basePath = "/emby", + host = host }; return spec; @@ -144,6 +157,15 @@ namespace Emby.Server.Implementations.Services { foreach (var info in current.Value) { + if (info.Path.StartsWith("/mediabrowser", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + if (info.Path.StartsWith("/emby", StringComparison.OrdinalIgnoreCase)) + { + continue; + } + paths[info.Path] = GetPathInfo(info); } } @@ -154,10 +176,19 @@ namespace Emby.Server.Implementations.Services private Dictionary GetPathInfo(RestPath info) { var result = new Dictionary(); - + foreach (var verb in info.Verbs) { - result[verb] = new SwaggerMethod + var responses = new Dictionary + { + }; + + responses["200"] = new SwaggerResponse + { + description = "OK" + }; + + result[verb.ToLower()] = new SwaggerMethod { summary = info.Summary, produces = new[] @@ -173,7 +204,9 @@ namespace Emby.Server.Implementations.Services operationId = info.RequestType.Name, tags = new string[] { }, - parameters = new SwaggerParam[] { } + parameters = new SwaggerParam[] { }, + + responses = responses }; } -- cgit v1.2.3 From fe10df693551ded214adc49cbbe4d5ad00de66fb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 9 Sep 2017 23:18:23 -0400 Subject: improve queries from scheduled tasks --- .../Data/SqliteItemRepository.cs | 48 ++++++++++++++++++++ .../Library/LibraryManager.cs | 25 ---------- .../LiveTv/RefreshChannelsScheduledTask.cs | 2 +- .../ScheduledTasks/ChapterImagesTask.cs | 10 +++- .../Services/SwaggerService.cs | 6 +-- .../Entities/InternalItemsQuery.cs | 5 ++ MediaBrowser.Controller/Library/ILibraryManager.cs | 2 - .../MediaInfo/SubtitleDownloader.cs | 53 ++++++++++++---------- .../MediaInfo/SubtitleScheduledTask.cs | 47 +++++++++++++++---- 9 files changed, 131 insertions(+), 67 deletions(-) (limited to 'Emby.Server.Implementations/Services/SwaggerService.cs') diff --git a/Emby.Server.Implementations/Data/SqliteItemRepository.cs b/Emby.Server.Implementations/Data/SqliteItemRepository.cs index b5bc7692e..ea3845f0c 100644 --- a/Emby.Server.Implementations/Data/SqliteItemRepository.cs +++ b/Emby.Server.Implementations/Data/SqliteItemRepository.cs @@ -4254,6 +4254,54 @@ namespace Emby.Server.Implementations.Data } } + if (!string.IsNullOrWhiteSpace(query.HasNoAudioTrackWithLanguage)) + { + whereClauses.Add("((select language from MediaStreams where MediaStreams.ItemId=A.Guid and MediaStreams.StreamType='Audio' and MediaStreams.Language=@HasNoAudioTrackWithLanguage limit 1) is null)"); + if (statement != null) + { + statement.TryBind("@HasNoAudioTrackWithLanguage", query.HasNoAudioTrackWithLanguage); + } + } + + if (!string.IsNullOrWhiteSpace(query.HasNoInternalSubtitleTrackWithLanguage)) + { + whereClauses.Add("((select language from MediaStreams where MediaStreams.ItemId=A.Guid and MediaStreams.StreamType='Subtitle' and MediaStreams.IsExternal=0 and MediaStreams.Language=@HasNoInternalSubtitleTrackWithLanguage limit 1) is null)"); + if (statement != null) + { + statement.TryBind("@HasNoInternalSubtitleTrackWithLanguage", query.HasNoInternalSubtitleTrackWithLanguage); + } + } + + if (!string.IsNullOrWhiteSpace(query.HasNoExternalSubtitleTrackWithLanguage)) + { + whereClauses.Add("((select language from MediaStreams where MediaStreams.ItemId=A.Guid and MediaStreams.StreamType='Subtitle' and MediaStreams.IsExternal=1 and MediaStreams.Language=@HasNoExternalSubtitleTrackWithLanguage limit 1) is null)"); + if (statement != null) + { + statement.TryBind("@HasNoExternalSubtitleTrackWithLanguage", query.HasNoExternalSubtitleTrackWithLanguage); + } + } + + if (!string.IsNullOrWhiteSpace(query.HasNoSubtitleTrackWithLanguage)) + { + whereClauses.Add("((select language from MediaStreams where MediaStreams.ItemId=A.Guid and MediaStreams.StreamType='Subtitle' and MediaStreams.Language=@HasNoSubtitleTrackWithLanguage limit 1) is null)"); + if (statement != null) + { + statement.TryBind("@HasNoSubtitleTrackWithLanguage", query.HasNoSubtitleTrackWithLanguage); + } + } + + if (query.HasChapterImages.HasValue) + { + if (query.HasChapterImages.Value) + { + whereClauses.Add("((select imagepath from Chapters2 where Chapters2.ItemId=A.Guid and imagepath not null limit 1) not null)"); + } + else + { + whereClauses.Add("((select imagepath from Chapters2 where Chapters2.ItemId=A.Guid and imagepath not null limit 1) is null)"); + } + } + if (query.HasDeadParentId.HasValue && query.HasDeadParentId.Value) { whereClauses.Add("ParentId NOT NULL AND ParentId NOT IN (select guid from TypedBaseItems)"); diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs index 8c5ecf782..510ecee76 100644 --- a/Emby.Server.Implementations/Library/LibraryManager.cs +++ b/Emby.Server.Implementations/Library/LibraryManager.cs @@ -620,37 +620,12 @@ namespace Emby.Server.Implementations.Library return ResolveItem(args, resolvers); } - private readonly List _ignoredPaths = new List(); - - public void RegisterIgnoredPath(string path) - { - lock (_ignoredPaths) - { - _ignoredPaths.Add(path); - } - } - public void UnRegisterIgnoredPath(string path) - { - lock (_ignoredPaths) - { - _ignoredPaths.Remove(path); - } - } - public bool IgnoreFile(FileSystemMetadata file, BaseItem parent) { if (EntityResolutionIgnoreRules.Any(r => r.ShouldIgnore(file, parent))) { return true; } - - //lock (_ignoredPaths) - { - if (_ignoredPaths.Contains(file.FullName, StringComparer.OrdinalIgnoreCase)) - { - return true; - } - } return false; } diff --git a/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs b/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs index cad28c809..225360159 100644 --- a/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs +++ b/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs @@ -51,7 +51,7 @@ namespace Emby.Server.Implementations.LiveTv return new[] { // Every so often - new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(12).Ticks} + new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks} }; } diff --git a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs index ec371c741..bf7bf9ff8 100644 --- a/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs +++ b/Emby.Server.Implementations/ScheduledTasks/ChapterImagesTask.cs @@ -58,8 +58,8 @@ namespace Emby.Server.Implementations.ScheduledTasks /// public IEnumerable GetDefaultTriggers() { - return new[] { - + return new[] { + new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, @@ -88,6 +88,12 @@ namespace Emby.Server.Implementations.ScheduledTasks IsFolder = false, Recursive = true, DtoOptions = new DtoOptions(false) + { + EnableImages = false + }, + SourceTypes = new SourceType[] { SourceType.Library }, + HasChapterImages = false, + IsVirtualItem = false }) .OfType