From 25736b259a56ff11ca3b7298be023b87eb3fda99 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 31 May 2015 14:22:51 -0400 Subject: [PATCH] normalize tv recording objects --- MediaBrowser.Api/ItemUpdateService.cs | 2 +- MediaBrowser.Api/LiveTv/LiveTvService.cs | 8 +- .../Entities/Audio/MusicAlbum.cs | 9 + .../LiveTv/ILiveTvManager.cs | 14 +- .../MediaBrowser.LocalMetadata.csproj | 2 - .../Providers/AlbumXmlProvider.cs | 30 -- .../Providers/ArtistXmlProvider.cs | 30 -- .../Savers/SeasonXmlSaver.cs | 2 +- .../MediaBrowser.Model.Portable.csproj | 6 - .../MediaBrowser.Model.net35.csproj | 6 - MediaBrowser.Model/ApiClient/IApiClient.cs | 16 +- MediaBrowser.Model/Dto/BaseItemDto.cs | 160 ++++++++- MediaBrowser.Model/LiveTv/BaseTimerInfoDto.cs | 6 +- .../LiveTv/RecordingGroupDto.cs | 40 --- MediaBrowser.Model/LiveTv/RecordingInfoDto.cs | 313 ------------------ MediaBrowser.Model/MediaBrowser.Model.csproj | 2 - MediaBrowser.Model/Net/MimeTypes.cs | 154 +++++---- .../Movies/MovieDbSearch.cs | 11 +- .../Omdb/OmdbItemProvider.cs | 112 +++---- .../Dto/DtoService.cs | 11 +- .../LiveTv/LiveTvDtoService.cs | 118 +------ .../LiveTv/LiveTvManager.cs | 170 +++++++--- .../Localization/JavaScript/javascript.json | 3 +- .../ApplicationHost.cs | 5 +- 24 files changed, 467 insertions(+), 763 deletions(-) delete mode 100644 MediaBrowser.LocalMetadata/Providers/AlbumXmlProvider.cs delete mode 100644 MediaBrowser.LocalMetadata/Providers/ArtistXmlProvider.cs delete mode 100644 MediaBrowser.Model/LiveTv/RecordingGroupDto.cs delete mode 100644 MediaBrowser.Model/LiveTv/RecordingInfoDto.cs diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index bab02de356..8f7edabbbd 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -428,7 +428,7 @@ namespace MediaBrowser.Api var series = item as Series; if (series != null) { - series.Status = request.Status; + series.Status = request.SeriesStatus; series.AirDays = request.AirDays; series.AirTime = request.AirTime; diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index b8b74369ce..86d8b9f99a 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -78,7 +78,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Recordings", "GET", Summary = "Gets live tv recordings")] [Authenticated] - public class GetRecordings : IReturn> + public class GetRecordings : IReturn> { [ApiMember(Name = "ChannelId", Description = "Optional filter by channel id.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string ChannelId { get; set; } @@ -107,7 +107,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Recordings/Groups", "GET", Summary = "Gets live tv recording groups")] [Authenticated] - public class GetRecordingGroups : IReturn> + public class GetRecordingGroups : IReturn> { [ApiMember(Name = "UserId", Description = "Optional filter by user and attach user data.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string UserId { get; set; } @@ -115,7 +115,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Recordings/{Id}", "GET", Summary = "Gets a live tv recording")] [Authenticated] - public class GetRecording : IReturn + public class GetRecording : IReturn { [ApiMember(Name = "Id", Description = "Recording Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } @@ -310,7 +310,7 @@ namespace MediaBrowser.Api.LiveTv [Route("/LiveTv/Recordings/Groups/{Id}", "GET", Summary = "Gets a recording group")] [Authenticated] - public class GetRecordingGroup : IReturn + public class GetRecordingGroup : IReturn { [ApiMember(Name = "Id", Description = "Recording group Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index c060f53a69..8a77d76165 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -121,6 +121,15 @@ namespace MediaBrowser.Controller.Entities.Audio .Select(i => i.GetLookupInfo()) .ToList(); + var album = id.SongInfos + .Select(i => i.Album) + .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); + + if (!string.IsNullOrWhiteSpace(album)) + { + id.Name = album; + } + return id; } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index 53eb18e7a8..e84fe902d6 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -79,7 +79,7 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// The user. /// Task{RecordingInfoDto}. - Task GetRecording(string id, DtoOptions options, CancellationToken cancellationToken, User user = null); + Task GetRecording(string id, DtoOptions options, CancellationToken cancellationToken, User user = null); /// /// Gets the channel. @@ -113,7 +113,7 @@ namespace MediaBrowser.Controller.LiveTv /// The options. /// The cancellation token. /// QueryResult{RecordingInfoDto}. - Task> GetRecordings(RecordingQuery query, DtoOptions options, CancellationToken cancellationToken); + Task> GetRecordings(RecordingQuery query, DtoOptions options, CancellationToken cancellationToken); /// /// Gets the timers. @@ -218,7 +218,7 @@ namespace MediaBrowser.Controller.LiveTv /// The query. /// The cancellation token. /// Task{QueryResult{RecordingGroupDto}}. - Task> GetRecordingGroups(RecordingGroupQuery query, CancellationToken cancellationToken); + Task> GetRecordingGroups(RecordingGroupQuery query, CancellationToken cancellationToken); /// /// Closes the live stream. @@ -321,5 +321,13 @@ namespace MediaBrowser.Controller.LiveTv /// The cancellation token. /// Task<IEnumerable<MediaSourceInfo>>. Task> GetChannelMediaSources(string id, CancellationToken cancellationToken); + + /// + /// Adds the information to recording dto. + /// + /// The item. + /// The dto. + /// The user. + void AddInfoToRecordingDto(BaseItem item, BaseItemDto dto, User user = null); } } diff --git a/MediaBrowser.LocalMetadata/MediaBrowser.LocalMetadata.csproj b/MediaBrowser.LocalMetadata/MediaBrowser.LocalMetadata.csproj index 894be87994..57174d63ad 100644 --- a/MediaBrowser.LocalMetadata/MediaBrowser.LocalMetadata.csproj +++ b/MediaBrowser.LocalMetadata/MediaBrowser.LocalMetadata.csproj @@ -58,8 +58,6 @@ - - diff --git a/MediaBrowser.LocalMetadata/Providers/AlbumXmlProvider.cs b/MediaBrowser.LocalMetadata/Providers/AlbumXmlProvider.cs deleted file mode 100644 index 6469227698..0000000000 --- a/MediaBrowser.LocalMetadata/Providers/AlbumXmlProvider.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.IO; -using System.Threading; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.LocalMetadata.Providers -{ - public class AlbumXmlProvider : BaseXmlProvider - { - private readonly ILogger _logger; - - public AlbumXmlProvider(IFileSystem fileSystem, ILogger logger) - : base(fileSystem) - { - _logger = logger; - } - - protected override void Fetch(LocalMetadataResult result, string path, CancellationToken cancellationToken) - { - new BaseItemXmlParser(_logger).Fetch(result.Item, path, cancellationToken); - } - - protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService) - { - return directoryService.GetFile(Path.Combine(info.Path, "album.xml")); - } - } -} diff --git a/MediaBrowser.LocalMetadata/Providers/ArtistXmlProvider.cs b/MediaBrowser.LocalMetadata/Providers/ArtistXmlProvider.cs deleted file mode 100644 index 0b5ebfb11a..0000000000 --- a/MediaBrowser.LocalMetadata/Providers/ArtistXmlProvider.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.IO; -using System.Threading; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Entities.Audio; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Logging; - -namespace MediaBrowser.LocalMetadata.Providers -{ - class ArtistXmlProvider : BaseXmlProvider - { - private readonly ILogger _logger; - - public ArtistXmlProvider(IFileSystem fileSystem, ILogger logger) - : base(fileSystem) - { - _logger = logger; - } - - protected override void Fetch(LocalMetadataResult result, string path, CancellationToken cancellationToken) - { - new BaseItemXmlParser(_logger).Fetch(result.Item, path, cancellationToken); - } - - protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService) - { - return directoryService.GetFile(Path.Combine(info.Path, "artist.xml")); - } - } -} diff --git a/MediaBrowser.LocalMetadata/Savers/SeasonXmlSaver.cs b/MediaBrowser.LocalMetadata/Savers/SeasonXmlSaver.cs index a112f22fa9..30f3e0ca10 100644 --- a/MediaBrowser.LocalMetadata/Savers/SeasonXmlSaver.cs +++ b/MediaBrowser.LocalMetadata/Savers/SeasonXmlSaver.cs @@ -11,7 +11,7 @@ using System.Threading; namespace MediaBrowser.LocalMetadata.Savers { - public class SeasonXmlSaver : IMetadataFileSaver + public class SeasonXmlSaver { public string Name { diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index f70fe628eb..a63b0a7c6f 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -752,15 +752,9 @@ LiveTv\RecommendedProgramQuery.cs - - LiveTv\RecordingGroupDto.cs - LiveTv\RecordingGroupQuery.cs - - LiveTv\RecordingInfoDto.cs - LiveTv\RecordingQuery.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index bb8b096827..036064238c 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -708,15 +708,9 @@ LiveTv\RecommendedProgramQuery.cs - - LiveTv\RecordingGroupDto.cs - LiveTv\RecordingGroupQuery.cs - - LiveTv\RecordingInfoDto.cs - LiveTv\RecordingQuery.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 026e65ec45..71ac0b14eb 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -929,14 +929,6 @@ namespace MediaBrowser.Model.ApiClient /// System.String. string GetImageUrl(ChannelInfoDto item, ImageOptions options); - /// - /// Gets the image URL. - /// - /// The item. - /// The options. - /// System.String. - string GetImageUrl(RecordingInfoDto item, ImageOptions options); - /// /// Gets the image URL. /// @@ -1077,7 +1069,7 @@ namespace MediaBrowser.Model.ApiClient /// The query. /// The cancellation token. /// Task{QueryResult{RecordingInfoDto}}. - Task> GetLiveTvRecordingsAsync(RecordingQuery query, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetLiveTvRecordingsAsync(RecordingQuery query, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the live tv recording asynchronous. @@ -1086,7 +1078,7 @@ namespace MediaBrowser.Model.ApiClient /// The user identifier. /// The cancellation token. /// Task{RecordingInfoDto}. - Task GetLiveTvRecordingAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); + Task GetLiveTvRecordingAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the live tv recording groups asynchronous. @@ -1094,7 +1086,7 @@ namespace MediaBrowser.Model.ApiClient /// The query. /// The cancellation token. /// Task{QueryResult{RecordingGroupDto}}. - Task> GetLiveTvRecordingGroupsAsync(RecordingGroupQuery query, CancellationToken cancellationToken = default(CancellationToken)); + Task> GetLiveTvRecordingGroupsAsync(RecordingGroupQuery query, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the live tv recording group asynchronous. @@ -1103,7 +1095,7 @@ namespace MediaBrowser.Model.ApiClient /// The user identifier. /// The cancellation token. /// Task{RecordingGroupDto}. - Task GetLiveTvRecordingGroupAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); + Task GetLiveTvRecordingGroupAsync(string id, string userId, CancellationToken cancellationToken = default(CancellationToken)); /// /// Gets the live tv timers asynchronous. diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index c772692a2f..0f6ce43348 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -2,6 +2,7 @@ using MediaBrowser.Model.Entities; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.Library; +using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Providers; using MediaBrowser.Model.Sync; using System; @@ -442,7 +443,57 @@ namespace MediaBrowser.Model.Dto /// Gets or sets the status. /// /// The status. - public SeriesStatus? Status { get; set; } + public string Status { get; set; } + + [IgnoreDataMember] + public SeriesStatus? SeriesStatus + { + get + { + if (string.IsNullOrEmpty(Status)) + { + return null; + } + + return (SeriesStatus)Enum.Parse(typeof(SeriesStatus), Status, true); + } + set + { + if (value == null) + { + Status = null; + } + else + { + Status = value.Value.ToString(); + } + } + } + + [IgnoreDataMember] + public RecordingStatus? RecordingStatus + { + get + { + if (string.IsNullOrEmpty(Status)) + { + return null; + } + + return (RecordingStatus)Enum.Parse(typeof(RecordingStatus), Status, true); + } + set + { + if (value == null) + { + Status = null; + } + else + { + Status = value.Value.ToString(); + } + } + } /// /// Gets or sets the air time. @@ -797,6 +848,17 @@ namespace MediaBrowser.Model.Dto public double? Altitude { get; set; } public int? IsoSpeedRating { get; set; } + /// + /// Used by RecordingGroup + /// + public int? RecordingCount { get; set; } + + /// + /// Gets or sets the series timer identifier. + /// + /// The series timer identifier. + public string SeriesTimerId { get; set; } + /// /// Gets a value indicating whether this instance can resume. /// @@ -1017,5 +1079,101 @@ namespace MediaBrowser.Model.Dto /// Occurs when [property changed]. /// public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Gets or sets the program identifier. + /// + /// The program identifier. + public string ProgramId { get; set; } + + /// + /// Gets or sets the channel primary image tag. + /// + /// The channel primary image tag. + public string ChannelPrimaryImageTag { get; set; } + + /// + /// The start date of the recording, in UTC. + /// + public DateTime? StartDate { get; set; } + + /// + /// Gets or sets the original air date. + /// + /// The original air date. + public DateTime? OriginalAirDate { get; set; } + + /// + /// Gets or sets the completion percentage. + /// + /// The completion percentage. + public double? CompletionPercentage { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is repeat. + /// + /// true if this instance is repeat; otherwise, false. + public bool? IsRepeat { get; set; } + + /// + /// Gets or sets the episode title. + /// + /// The episode title. + public string EpisodeTitle { get; set; } + + /// + /// Gets or sets the type of the channel. + /// + /// The type of the channel. + public ChannelType? ChannelType { get; set; } + + /// + /// Gets or sets the audio. + /// + /// The audio. + public ProgramAudio? Audio { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is movie. + /// + /// true if this instance is movie; otherwise, false. + public bool? IsMovie { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is sports. + /// + /// true if this instance is sports; otherwise, false. + public bool? IsSports { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is series. + /// + /// true if this instance is series; otherwise, false. + public bool? IsSeries { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is live. + /// + /// true if this instance is live; otherwise, false. + public bool? IsLive { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is news. + /// + /// true if this instance is news; otherwise, false. + public bool? IsNews { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is kids. + /// + /// true if this instance is kids; otherwise, false. + public bool? IsKids { get; set; } + + /// + /// Gets or sets a value indicating whether this instance is premiere. + /// + /// true if this instance is premiere; otherwise, false. + public bool? IsPremiere { get; set; } + } } diff --git a/MediaBrowser.Model/LiveTv/BaseTimerInfoDto.cs b/MediaBrowser.Model/LiveTv/BaseTimerInfoDto.cs index 49e5724181..296ead5c2a 100644 --- a/MediaBrowser.Model/LiveTv/BaseTimerInfoDto.cs +++ b/MediaBrowser.Model/LiveTv/BaseTimerInfoDto.cs @@ -1,7 +1,7 @@ -using System; -using System.ComponentModel; -using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Extensions; +using System; +using System.ComponentModel; namespace MediaBrowser.Model.LiveTv { diff --git a/MediaBrowser.Model/LiveTv/RecordingGroupDto.cs b/MediaBrowser.Model/LiveTv/RecordingGroupDto.cs deleted file mode 100644 index 8a0b488cc5..0000000000 --- a/MediaBrowser.Model/LiveTv/RecordingGroupDto.cs +++ /dev/null @@ -1,40 +0,0 @@ -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Extensions; -using System.ComponentModel; -using System.Diagnostics; - -namespace MediaBrowser.Model.LiveTv -{ - /// - /// Class RecordingGroupDto. - /// - [DebuggerDisplay("Name = {Name}, Count = {RecordingCount}")] - public class RecordingGroupDto : IHasPropertyChangedEvent, IHasServerId - { - /// - /// Gets or sets the server identifier. - /// - /// The server identifier. - public string ServerId { get; set; } - - /// - /// Gets or sets the name. - /// - /// The name. - public string Name { get; set; } - - /// - /// Gets or sets the identifier. - /// - /// The identifier. - public string Id { get; set; } - - /// - /// Gets or sets the recording count. - /// - /// The recording count. - public int RecordingCount { get; set; } - - public event PropertyChangedEventHandler PropertyChanged; - } -} diff --git a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs deleted file mode 100644 index 0988b11a6e..0000000000 --- a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs +++ /dev/null @@ -1,313 +0,0 @@ -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Extensions; -using MediaBrowser.Model.Library; -using MediaBrowser.Model.Sync; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.Serialization; - -namespace MediaBrowser.Model.LiveTv -{ - [DebuggerDisplay("Name = {Name}, ChannelName = {ChannelName}")] - public class RecordingInfoDto : IHasPropertyChangedEvent, IItemDto, IHasServerId, IHasSyncInfo - { - /// - /// Id of the recording. - /// - public string Id { get; set; } - - /// - /// Gets or sets the primary image aspect ratio. - /// - /// The primary image aspect ratio. - public double? PrimaryImageAspectRatio { get; set; } - - /// - /// Gets or sets the server identifier. - /// - /// The server identifier. - public string ServerId { get; set; } - - /// - /// Gets or sets the original primary image aspect ratio. - /// - /// The original primary image aspect ratio. - public double? OriginalPrimaryImageAspectRatio { get; set; } - - /// - /// Gets or sets a value indicating whether [supports synchronize]. - /// - /// null if [supports synchronize] contains no value, true if [supports synchronize]; otherwise, false. - public bool? SupportsSync { get; set; } - /// - /// Gets or sets a value indicating whether this instance has synchronize job. - /// - /// null if [has synchronize job] contains no value, true if [has synchronize job]; otherwise, false. - public bool? HasSyncJob { get; set; } - /// - /// Gets or sets a value indicating whether this instance is synced. - /// - /// null if [is synced] contains no value, true if [is synced]; otherwise, false. - public bool? IsSynced { get; set; } - /// - /// Gets or sets the synchronize status. - /// - /// The synchronize status. - public SyncJobItemStatus? SyncStatus { get; set; } - - /// - /// Gets or sets the series timer identifier. - /// - /// The series timer identifier. - public string SeriesTimerId { get; set; } - - /// - /// Gets or sets the external identifier. - /// - /// The external identifier. - public string ExternalId { get; set; } - - /// - /// Gets or sets the program identifier. - /// - /// The program identifier. - public string ProgramId { get; set; } - - /// - /// ChannelId of the recording. - /// - public string ChannelId { get; set; } - - /// - /// Gets or sets the play access. - /// - /// The play access. - public PlayAccess PlayAccess { get; set; } - - /// - /// Gets or sets the channel primary image tag. - /// - /// The channel primary image tag. - public string ChannelPrimaryImageTag { get; set; } - - /// - /// ChannelName of the recording. - /// - public string ChannelName { get; set; } - - /// - /// Gets or sets the name of the service. - /// - /// The name of the service. - public string ServiceName { get; set; } - - /// - /// Name of the recording. - /// - public string Name { get; set; } - - /// - /// Gets or sets the media streams. - /// - /// The media streams. - public List MediaStreams { get; set; } - - /// - /// Gets or sets the path. - /// - /// The path. - public string Path { get; set; } - - /// - /// Gets or sets a value indicating whether this instance can delete. - /// - /// null if [can delete] contains no value, true if [can delete]; otherwise, false. - public bool? CanDelete { get; set; } - - /// - /// Overview of the recording. - /// - public string Overview { get; set; } - - /// - /// The start date of the recording, in UTC. - /// - public DateTime StartDate { get; set; } - - /// - /// The end date of the recording, in UTC. - /// - public DateTime EndDate { get; set; } - - /// - /// Gets or sets the original air date. - /// - /// The original air date. - public DateTime? OriginalAirDate { get; set; } - - /// - /// Gets or sets the status. - /// - /// The status. - public RecordingStatus Status { get; set; } - - /// - /// Gets or sets the name of the status. - /// - /// The name of the status. - public string StatusName { get; set; } - - /// - /// Gets or sets the completion percentage. - /// - /// The completion percentage. - public double? CompletionPercentage { get; set; } - - /// - /// Genre of the program. - /// - public List Genres { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is repeat. - /// - /// true if this instance is repeat; otherwise, false. - public bool IsRepeat { get; set; } - - /// - /// Gets or sets the episode title. - /// - /// The episode title. - public string EpisodeTitle { get; set; } - - /// - /// Gets or sets the run time ticks. - /// - /// The run time ticks. - public long? RunTimeTicks { get; set; } - - /// - /// Gets or sets the type of the media. - /// - /// The type of the media. - public string MediaType { get; set; } - - /// - /// Gets or sets the type of the channel. - /// - /// The type of the channel. - public ChannelType ChannelType { get; set; } - - /// - /// Gets or sets the official rating. - /// - /// The official rating. - public string OfficialRating { get; set; } - - /// - /// Gets or sets the community rating. - /// - /// The community rating. - public float? CommunityRating { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is hd. - /// - /// true if this instance is hd; otherwise, false. - public bool? IsHD { get; set; } - - /// - /// Gets or sets the audio. - /// - /// The audio. - public ProgramAudio? Audio { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is movie. - /// - /// true if this instance is movie; otherwise, false. - public bool IsMovie { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is sports. - /// - /// true if this instance is sports; otherwise, false. - public bool IsSports { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is series. - /// - /// true if this instance is series; otherwise, false. - public bool IsSeries { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is live. - /// - /// true if this instance is live; otherwise, false. - public bool IsLive { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is news. - /// - /// true if this instance is news; otherwise, false. - public bool IsNews { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is kids. - /// - /// true if this instance is kids; otherwise, false. - public bool IsKids { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is premiere. - /// - /// true if this instance is premiere; otherwise, false. - public bool IsPremiere { get; set; } - - /// - /// Gets or sets the image tags. - /// - /// The image tags. - public Dictionary ImageTags { get; set; } - - /// - /// Gets or sets the user data. - /// - /// The user data. - public UserItemDataDto UserData { get; set; } - - /// - /// Gets a value indicating whether this instance has primary image. - /// - /// true if this instance has primary image; otherwise, false. - [IgnoreDataMember] - public bool HasPrimaryImage - { - get { return ImageTags != null && ImageTags.ContainsKey(ImageType.Primary); } - } - - /// - /// Gets or sets the type. - /// - /// The type. - public string Type { get; set; } - - /// - /// Gets or sets the media sources. - /// - /// The media sources. - public List MediaSources { get; set; } - - public RecordingInfoDto() - { - Genres = new List(); - ImageTags = new Dictionary(); - MediaSources = new List(); - } - - public event PropertyChangedEventHandler PropertyChanged; - } -} \ No newline at end of file diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 340bd94623..c567c1f6af 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -262,7 +262,6 @@ - @@ -299,7 +298,6 @@ - diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index 56cfff7335..efa5a5217a 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -1,4 +1,5 @@ -using System; +using MediaBrowser.Model.Extensions; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -45,33 +46,50 @@ namespace MediaBrowser.Model.Net ".rec" }; - private static readonly Dictionary VideoFileExtensionsDictionary = VideoFileExtensions.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase); + private static Dictionary GetVideoFileExtensionsDictionary() + { + Dictionary dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (string ext in VideoFileExtensions) + { + dict[ext] = ext; + } + + return dict; + } + + private static readonly Dictionary VideoFileExtensionsDictionary = GetVideoFileExtensionsDictionary(); // http://en.wikipedia.org/wiki/Internet_media_type // Add more as needed - private static readonly Dictionary MimeTypeLookup = - new Dictionary(StringComparer.OrdinalIgnoreCase) - { - {".jpg", "image/jpeg"}, - {".jpeg", "image/jpeg"}, - {".tbn", "image/jpeg"}, - {".png", "image/png"}, - {".gif", "image/gif"}, - {".webp", "image/webp"}, - {".ico", "image/vnd.microsoft.icon"}, - {".mpg", "video/mpeg"}, - {".mpeg", "video/mpeg"}, - {".ogv", "video/ogg"}, - {".mov", "video/quicktime"}, - {".webm", "video/webm"}, - {".mkv", "video/x-matroska"}, - {".wmv", "video/x-ms-wmv"}, - {".flv", "video/x-flv"}, - {".avi", "video/x-msvideo"}, - {".asf", "video/x-ms-asf"}, - {".m4v", "video/x-m4v"} - }; + private static Dictionary GetMimeTypeLookup() + { + Dictionary dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + + dict.Add(".jpg", "image/jpeg"); + dict.Add(".jpeg", "image/jpeg"); + dict.Add(".tbn", "image/jpeg"); + dict.Add(".png", "image/png"); + dict.Add(".gif", "image/gif"); + dict.Add(".webp", "image/webp"); + dict.Add(".ico", "image/vnd.microsoft.icon"); + dict.Add(".mpg", "video/mpeg"); + dict.Add(".mpeg", "video/mpeg"); + dict.Add(".ogv", "video/ogg"); + dict.Add(".mov", "video/quicktime"); + dict.Add(".webm", "video/webm"); + dict.Add(".mkv", "video/x-matroska"); + dict.Add(".wmv", "video/x-ms-wmv"); + dict.Add(".flv", "video/x-flv"); + dict.Add(".avi", "video/x-msvideo"); + dict.Add(".asf", "video/x-ms-asf"); + dict.Add(".m4v", "video/x-m4v"); + + return dict; + } + + private static readonly Dictionary MimeTypeLookup = GetMimeTypeLookup(); private static readonly Dictionary ExtensionLookup = CreateExtensionLookup(); @@ -109,19 +127,19 @@ namespace MediaBrowser.Model.Net } // Type video - if (ext.Equals(".3gp", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".3gp")) { return "video/3gpp"; } - if (ext.Equals(".3g2", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".3g2")) { return "video/3gpp2"; } - if (ext.Equals(".ts", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".ts")) { return "video/mp2t"; } - if (ext.Equals(".mpd", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".mpd")) { return "video/vnd.mpeg.dash.mpd"; } @@ -133,134 +151,154 @@ namespace MediaBrowser.Model.Net } // Type text - if (ext.Equals(".css", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".css")) { return "text/css"; } - if (ext.Equals(".csv", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".csv")) { return "text/csv"; } - if (ext.Equals(".html", StringComparison.OrdinalIgnoreCase) || ext.Equals(".htm", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".html")) + { + return "text/html; charset=UTF-8"; + } + if (StringHelper.EqualsIgnoreCase(ext, ".htm")) { return "text/html; charset=UTF-8"; } - if (ext.Equals(".txt", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".txt")) { return "text/plain"; } - if (ext.Equals(".xml", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".xml")) { return "application/xml"; } // Type document - if (ext.Equals(".pdf", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".pdf")) { return "application/pdf"; } - if (ext.Equals(".mobi", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".mobi")) { return "application/x-mobipocket-ebook"; } - if (ext.Equals(".epub", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".epub")) + { + return "application/epub+zip"; + } + if (StringHelper.EqualsIgnoreCase(ext, ".cbz")) { return "application/epub+zip"; } - if (ext.Equals(".cbz", StringComparison.OrdinalIgnoreCase) || ext.Equals(".cbr", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".cbr")) { - return "application/x-cdisplay"; + return "application/epub+zip"; } // Type audio - if (ext.Equals(".mp3", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".mp3")) { return "audio/mpeg"; } - if (ext.Equals(".m4a", StringComparison.OrdinalIgnoreCase) || ext.Equals(".aac", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".m4a")) { return "audio/mp4"; } - if (ext.Equals(".webma", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".aac")) + { + return "audio/mp4"; + } + if (StringHelper.EqualsIgnoreCase(ext, ".webma")) { return "audio/webm"; } - if (ext.Equals(".wav", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".wav")) { return "audio/wav"; } - if (ext.Equals(".wma", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".wma")) { return "audio/x-ms-wma"; } - if (ext.Equals(".flac", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".flac")) { return "audio/flac"; } - if (ext.Equals(".aac", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".aac")) { return "audio/x-aac"; } - if (ext.Equals(".ogg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".oga", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".ogg")) + { + return "audio/ogg"; + } + if (StringHelper.EqualsIgnoreCase(ext, ".oga")) { return "audio/ogg"; } // Playlists - if (ext.Equals(".m3u8", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".m3u8")) { return "application/x-mpegURL"; } // Misc - if (ext.Equals(".dll", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".dll")) { return "application/octet-stream"; } // Web - if (ext.Equals(".js", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".js")) { return "application/x-javascript"; } - if (ext.Equals(".json", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".json")) { return "application/json"; } - if (ext.Equals(".map", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".map")) { return "application/x-javascript"; } - if (ext.Equals(".woff", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".woff")) { return "font/woff"; } - if (ext.Equals(".ttf", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".ttf")) { return "font/ttf"; } - if (ext.Equals(".eot", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".eot")) { return "application/vnd.ms-fontobject"; } - if (ext.Equals(".svg", StringComparison.OrdinalIgnoreCase) || ext.Equals(".svgz", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".svg")) + { + return "image/svg+xml"; + } + if (StringHelper.EqualsIgnoreCase(ext, ".svgz")) { return "image/svg+xml"; } - if (ext.Equals(".srt", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".srt")) { return "text/plain"; } - if (ext.Equals(".vtt", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".vtt")) { return "text/vtt"; } - if (ext.Equals(".ttml", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(ext, ".ttml")) { return "application/ttml+xml"; } diff --git a/MediaBrowser.Providers/Movies/MovieDbSearch.cs b/MediaBrowser.Providers/Movies/MovieDbSearch.cs index 8a59d7a1b2..6fb7954119 100644 --- a/MediaBrowser.Providers/Movies/MovieDbSearch.cs +++ b/MediaBrowser.Providers/Movies/MovieDbSearch.cs @@ -58,10 +58,13 @@ namespace MediaBrowser.Providers.Movies var tmdbImageUrl = tmdbSettings.images.base_url + "original"; - var parsedName = _libraryManager.ParseName(name); - var yearInName = parsedName.Year; - name = parsedName.Name; - year = year ?? yearInName; + if (!string.IsNullOrWhiteSpace(name)) + { + var parsedName = _libraryManager.ParseName(name); + var yearInName = parsedName.Year; + name = parsedName.Name; + year = year ?? yearInName; + } _logger.Info("MovieDbProvider: Finding id for item: " + name); var language = idInfo.MetadataLanguage.ToLower(); diff --git a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs index 1ee2d86de7..c79d04b4f0 100644 --- a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Net; +using System.Linq; +using MediaBrowser.Common.Net; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; @@ -52,28 +53,34 @@ namespace MediaBrowser.Providers.Omdb var list = new List(); var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb); - if (!string.IsNullOrWhiteSpace(imdbId)) - { - return list; - } var url = "http://www.omdbapi.com/?plot=short&r=json"; var name = searchInfo.Name; var year = searchInfo.Year; - var parsedName = _libraryManager.ParseName(name); - var yearInName = parsedName.Year; - name = parsedName.Name; - year = year ?? yearInName; - - if (year.HasValue) + if (!string.IsNullOrWhiteSpace(name)) { - url += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture); + var parsedName = _libraryManager.ParseName(name); + var yearInName = parsedName.Year; + name = parsedName.Name; + year = year ?? yearInName; } + + if (string.IsNullOrWhiteSpace(imdbId)) + { + if (year.HasValue) + { + url += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture); + } - url += "&t=" + WebUtility.UrlEncode(name); - url += "&type=" + type; + url += "&t=" + WebUtility.UrlEncode(name); + url += "&type=" + type; + } + else + { + url += "&i=" + imdbId; + } using (var stream = await _httpClient.Get(new HttpRequestOptions { @@ -81,7 +88,7 @@ namespace MediaBrowser.Providers.Omdb ResourcePool = OmdbProvider.ResourcePool, CancellationToken = cancellationToken, CacheMode = CacheMode.Unconditional, - CacheLength = TimeSpan.FromDays(7) + CacheLength = TimeSpan.FromDays(2) }).ConfigureAwait(false)) { @@ -145,33 +152,18 @@ namespace MediaBrowser.Providers.Omdb Item = new Series() }; - var searchResult = await GetSeriesImdbId(info, cancellationToken).ConfigureAwait(false); - result.Item.Name = searchResult.Item4; - - if (!string.IsNullOrEmpty(searchResult.Item1)) - { - result.Item.SetProviderId(MetadataProviders.Imdb, searchResult.Item1); - } - - if (!string.IsNullOrEmpty(searchResult.Item2)) - { - result.Item.SetProviderId(MetadataProviders.Tmdb, searchResult.Item2); - } - - if (!string.IsNullOrEmpty(searchResult.Item3)) + var imdbId = info.GetProviderId(MetadataProviders.Imdb); + if (string.IsNullOrWhiteSpace(imdbId)) { - result.Item.SetProviderId(MetadataProviders.Tvdb, searchResult.Item3); + imdbId = await GetSeriesImdbId(info, cancellationToken).ConfigureAwait(false); } - var imdbId = result.Item.GetProviderId(MetadataProviders.Imdb); - if (!string.IsNullOrEmpty(imdbId)) { result.Item.SetProviderId(MetadataProviders.Imdb, imdbId); result.HasMetadata = true; - await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken) - .ConfigureAwait(false); + await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken).ConfigureAwait(false); } return result; @@ -191,64 +183,34 @@ namespace MediaBrowser.Providers.Omdb }; var imdbId = info.GetProviderId(MetadataProviders.Imdb); - - var searchResult = await GetMovieImdbId(info, cancellationToken).ConfigureAwait(false); - result.Item.Name = searchResult.Item3; - if (string.IsNullOrWhiteSpace(imdbId)) { - imdbId = searchResult.Item1; - - if (!string.IsNullOrEmpty(searchResult.Item2)) - { - result.Item.SetProviderId(MetadataProviders.Tmdb, searchResult.Item2); - } + imdbId = await GetMovieImdbId(info, cancellationToken).ConfigureAwait(false); } - if (!string.IsNullOrWhiteSpace(imdbId)) + if (!string.IsNullOrEmpty(imdbId)) { result.Item.SetProviderId(MetadataProviders.Imdb, imdbId); result.HasMetadata = true; - await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken) - .ConfigureAwait(false); + await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, cancellationToken).ConfigureAwait(false); } return result; } - private async Task> GetMovieImdbId(ItemLookupInfo info, CancellationToken cancellationToken) + private async Task GetMovieImdbId(ItemLookupInfo info, CancellationToken cancellationToken) { - var result = await new GenericMovieDbInfo(_logger, _jsonSerializer, _libraryManager).GetMetadata(info, cancellationToken) - .ConfigureAwait(false); - - var imdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Imdb) : null; - var tmdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tmdb) : null; - var name = result.HasMetadata ? result.Item.Name : null; - - return new Tuple(imdb, tmdb, name); + var results = await GetSearchResults(info, "movie", cancellationToken).ConfigureAwait(false); + var first = results.FirstOrDefault(); + return first == null ? null : first.GetProviderId(MetadataProviders.Imdb); } - private async Task> GetSeriesImdbId(SeriesInfo info, CancellationToken cancellationToken) + private async Task GetSeriesImdbId(SeriesInfo info, CancellationToken cancellationToken) { - //var result = await TvdbSeriesProvider.Current.GetMetadata(info, cancellationToken) - // .ConfigureAwait(false); - - //var imdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Imdb) : null; - //var tvdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tvdb) : null; - //var name = result.HasMetadata ? result.Item.Name : null; - - //return new Tuple(imdb, tvdb, name); - - var result = await MovieDbSeriesProvider.Current.GetMetadata(info, cancellationToken) - .ConfigureAwait(false); - - var imdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Imdb) : null; - var tmdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tmdb) : null; - var tvdb = result.HasMetadata ? result.Item.GetProviderId(MetadataProviders.Tvdb) : null; - var name = result.HasMetadata ? result.Item.Name : null; - - return new Tuple(imdb, tmdb, tvdb, name); + var results = await GetSearchResults(info, cancellationToken).ConfigureAwait(false); + var first = results.FirstOrDefault(); + return first == null ? null : first.GetProviderId(MetadataProviders.Imdb); } public Task GetImageResponse(string url, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 1b55f47d5e..cf56fc9ced 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -46,8 +46,9 @@ namespace MediaBrowser.Server.Implementations.Dto private readonly IApplicationHost _appHost; private readonly Func _deviceManager; private readonly Func _mediaSourceManager; + private readonly Func _livetvManager; - public DtoService(ILogger logger, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem, IProviderManager providerManager, Func channelManagerFactory, ISyncManager syncManager, IApplicationHost appHost, Func deviceManager, Func mediaSourceManager) + public DtoService(ILogger logger, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IImageProcessor imageProcessor, IServerConfigurationManager config, IFileSystem fileSystem, IProviderManager providerManager, Func channelManagerFactory, ISyncManager syncManager, IApplicationHost appHost, Func deviceManager, Func mediaSourceManager, Func livetvManager) { _logger = logger; _libraryManager = libraryManager; @@ -62,6 +63,7 @@ namespace MediaBrowser.Server.Implementations.Dto _appHost = appHost; _deviceManager = deviceManager; _mediaSourceManager = mediaSourceManager; + _livetvManager = livetvManager; } /// @@ -350,6 +352,11 @@ namespace MediaBrowser.Server.Implementations.Dto dto.Etag = item.GetEtag(user); } + if (item is ILiveTvRecording) + { + _livetvManager().AddInfoToRecordingDto(item, dto, user); + } + return dto; } @@ -1384,7 +1391,7 @@ namespace MediaBrowser.Server.Implementations.Dto { dto.AirDays = series.AirDays; dto.AirTime = series.AirTime; - dto.Status = series.Status; + dto.SeriesStatus = series.Status; dto.SeasonCount = series.SeasonCount; diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index 00c15fdfcc..939d057cb3 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -167,122 +167,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv return val.Value; } - public string GetStatusName(RecordingStatus status) - { - if (status == RecordingStatus.InProgress) - { - return "In Progress"; - } - - if (status == RecordingStatus.ConflictedNotOk) - { - return "Conflicted"; - } - - if (status == RecordingStatus.ConflictedOk) - { - return "Scheduled"; - } - - return status.ToString(); - } - - public RecordingInfoDto GetRecordingInfoDto(ILiveTvRecording recording, LiveTvChannel channel, ILiveTvService service, User user = null) - { - var info = recording.RecordingInfo; - - var dto = new RecordingInfoDto - { - Id = GetInternalRecordingId(service.Name, info.Id).ToString("N"), - SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"), - Type = recording.GetClientTypeName(), - Overview = info.Overview, - EndDate = info.EndDate, - Name = info.Name, - StartDate = info.StartDate, - ExternalId = info.Id, - ChannelId = GetInternalChannelId(service.Name, info.ChannelId).ToString("N"), - Status = info.Status, - StatusName = GetStatusName(info.Status), - Path = info.Path, - Genres = info.Genres, - IsRepeat = info.IsRepeat, - EpisodeTitle = info.EpisodeTitle, - ChannelType = info.ChannelType, - MediaType = info.ChannelType == ChannelType.Radio ? MediaType.Audio : MediaType.Video, - CommunityRating = GetClientCommunityRating(info.CommunityRating), - OfficialRating = info.OfficialRating, - Audio = info.Audio, - IsHD = info.IsHD, - ServiceName = service.Name, - IsMovie = info.IsMovie, - IsSeries = info.IsSeries, - IsSports = info.IsSports, - IsLive = info.IsLive, - IsNews = info.IsNews, - IsKids = info.IsKids, - IsPremiere = info.IsPremiere, - RunTimeTicks = (info.EndDate - info.StartDate).Ticks, - OriginalAirDate = info.OriginalAirDate, - - MediaSources = recording.GetMediaSources(true).ToList(), - ServerId = _appHost.SystemId - }; - - dto.CanDelete = user == null - ? recording.CanDelete() - : recording.CanDelete(user); - - dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToList(); - - if (info.Status == RecordingStatus.InProgress) - { - var now = DateTime.UtcNow.Ticks; - var start = info.StartDate.Ticks; - var end = info.EndDate.Ticks; - - var pct = now - start; - pct /= end; - pct *= 100; - dto.CompletionPercentage = pct; - } - - var imageTag = GetImageTag(recording); - - if (imageTag != null) - { - dto.ImageTags[ImageType.Primary] = imageTag; - _dtoService.AttachPrimaryImageAspectRatio(dto, recording, new List - { - ItemFields.PrimaryImageAspectRatio - }); - } - - if (user != null) - { - dto.UserData = _userDataManager.GetUserDataDto(recording, user); - - dto.PlayAccess = recording.GetPlayAccess(user); - } - - if (!string.IsNullOrEmpty(info.ProgramId)) - { - dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N"); - } - - if (channel != null) - { - dto.ChannelName = channel.Name; - - if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) - { - dto.ChannelPrimaryImageTag = GetImageTag(channel); - } - } - - return dto; - } - public LiveTvTunerInfoDto GetTunerInfoDto(string serviceName, LiveTvTunerInfo info, string channelName) { var dto = new LiveTvTunerInfoDto @@ -430,7 +314,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return dto; } - private string GetImageTag(IHasImages info) + internal string GetImageTag(IHasImages info) { try { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index a82775de70..52c96bca69 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -119,11 +119,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv { var dict = new Dictionary(); - foreach (var item in _itemRepo.GetItemsOfType(typeof (LiveTvProgram)) + foreach (var item in _itemRepo.GetItemsOfType(typeof(LiveTvProgram)) .Cast() .ToList()) { - dict[item.Id] = item; + dict[item.Id] = item; } _programs = dict; @@ -658,7 +658,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var id = _tvDtoService.GetInternalRecordingId(serviceName, info.Id); - var item = _itemRepo.RetrieveItem(id) as ILiveTvRecording; + var item = _itemRepo.RetrieveItem(id); if (item == null) { @@ -687,8 +687,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv isNew = true; } - item.RecordingInfo = info; - item.ServiceName = serviceName; + item.CommunityRating = info.CommunityRating; + item.OfficialRating = info.OfficialRating; + item.Overview = info.Overview; + item.EndDate = info.EndDate; + + var recording = (ILiveTvRecording)item; + + recording.RecordingInfo = info; + recording.ServiceName = serviceName; var originalPath = item.Path; @@ -709,9 +716,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv }, cancellationToken); - _libraryManager.RegisterItem((BaseItem)item); + _libraryManager.RegisterItem(item); - return item; + return recording; } private LiveTvChannel GetChannel(LiveTvProgram program) @@ -1355,20 +1362,89 @@ namespace MediaBrowser.Server.Implementations.LiveTv }; } - public async Task> GetRecordings(RecordingQuery query, DtoOptions options, CancellationToken cancellationToken) + public void AddInfoToRecordingDto(BaseItem item, BaseItemDto dto, User user = null) { - var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); + var recording = (ILiveTvRecording)item; + var service = GetService(recording); - var internalResult = await GetInternalRecordings(query, cancellationToken).ConfigureAwait(false); + var channel = string.IsNullOrEmpty(recording.RecordingInfo.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, recording.RecordingInfo.ChannelId)); - var returnArray = internalResult.Items.Cast() - .Select(i => + var info = recording.RecordingInfo; + + dto.Id = _tvDtoService.GetInternalRecordingId(service.Name, info.Id).ToString("N"); + dto.SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) + ? null + : _tvDtoService.GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"); + + dto.ChannelId = _tvDtoService.GetInternalChannelId(service.Name, info.ChannelId).ToString("N"); + + dto.StartDate = info.StartDate; + dto.RecordingStatus = info.Status; + dto.IsRepeat = info.IsRepeat; + dto.EpisodeTitle = info.EpisodeTitle; + dto.ChannelType = info.ChannelType; + dto.Audio = info.Audio; + dto.IsHD = info.IsHD; + dto.IsMovie = info.IsMovie; + dto.IsSeries = info.IsSeries; + dto.IsSports = info.IsSports; + dto.IsLive = info.IsLive; + dto.IsNews = info.IsNews; + dto.IsKids = info.IsKids; + dto.IsPremiere = info.IsPremiere; + dto.RunTimeTicks = (info.EndDate - info.StartDate).Ticks; + dto.OriginalAirDate = info.OriginalAirDate; + + dto.CanDelete = user == null + ? recording.CanDelete() + : recording.CanDelete(user); + + if (dto.MediaSources == null) + { + dto.MediaSources = recording.GetMediaSources(true).ToList(); + } + + if (dto.MediaStreams == null) + { + dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToList(); + } + + if (info.Status == RecordingStatus.InProgress) + { + var now = DateTime.UtcNow.Ticks; + var start = info.StartDate.Ticks; + var end = info.EndDate.Ticks; + + var pct = now - start; + pct /= end; + pct *= 100; + dto.CompletionPercentage = pct; + } + + if (!string.IsNullOrEmpty(info.ProgramId)) + { + dto.ProgramId = _tvDtoService.GetInternalProgramId(service.Name, info.ProgramId).ToString("N"); + } + + if (channel != null) + { + dto.ChannelName = channel.Name; + + if (!string.IsNullOrEmpty(channel.PrimaryImagePath)) { - var service = GetService(i); + dto.ChannelPrimaryImageTag = _tvDtoService.GetImageTag(channel); + } + } + } - var channel = string.IsNullOrEmpty(i.RecordingInfo.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, i.RecordingInfo.ChannelId)); - return _tvDtoService.GetRecordingInfoDto(i, channel, service, user); - }) + public async Task> GetRecordings(RecordingQuery query, DtoOptions options, CancellationToken cancellationToken) + { + var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); + + var internalResult = await GetInternalRecordings(query, cancellationToken).ConfigureAwait(false); + + var returnArray = internalResult.Items + .Select(i => _dtoService.GetBaseItemDto(i, options, user)) .ToArray(); if (user != null) @@ -1376,7 +1452,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _dtoService.FillSyncInfo(returnArray, new DtoOptions(), user); } - return new QueryResult + return new QueryResult { Items = returnArray, TotalRecordCount = internalResult.TotalRecordCount @@ -1448,10 +1524,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public async Task DeleteRecording(string recordingId) { - var dtoOptions = new DtoOptions(); - dtoOptions.Fields.Remove(ItemFields.SyncInfo); - - var recording = await GetRecording(recordingId, dtoOptions, CancellationToken.None).ConfigureAwait(false); + var recording = await GetInternalRecording(recordingId, CancellationToken.None).ConfigureAwait(false); if (recording == null) { @@ -1460,7 +1533,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(recording.ServiceName); - await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false); + await service.DeleteRecordingAsync(recording.RecordingInfo.Id, CancellationToken.None).ConfigureAwait(false); } public async Task CancelTimer(string id) @@ -1491,16 +1564,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv await service.CancelSeriesTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); } - public async Task GetRecording(string id, DtoOptions options, CancellationToken cancellationToken, User user = null) + public async Task GetRecording(string id, DtoOptions options, CancellationToken cancellationToken, User user = null) { - var results = await GetRecordings(new RecordingQuery - { - UserId = user == null ? null : user.Id.ToString("N"), - Id = id + var item = await GetInternalRecording(id, cancellationToken).ConfigureAwait(false); - }, options, cancellationToken).ConfigureAwait(false); + if (item == null) + { + return null; + } - return results.Items.FirstOrDefault(); + return _dtoService.GetBaseItemDto((BaseItem)item, options, user); } public async Task GetTimer(string id, CancellationToken cancellationToken) @@ -1776,60 +1849,57 @@ namespace MediaBrowser.Server.Implementations.LiveTv .ToList(); } - public async Task> GetRecordingGroups(RecordingGroupQuery query, CancellationToken cancellationToken) + public async Task> GetRecordingGroups(RecordingGroupQuery query, CancellationToken cancellationToken) { - var dtoOptions = new DtoOptions(); - dtoOptions.Fields.Remove(ItemFields.SyncInfo); - - var recordingResult = await GetRecordings(new RecordingQuery + var recordingResult = await GetInternalRecordings(new RecordingQuery { UserId = query.UserId - }, dtoOptions, cancellationToken).ConfigureAwait(false); + }, cancellationToken).ConfigureAwait(false); - var recordings = recordingResult.Items; + var recordings = recordingResult.Items.Cast().ToList(); - var groups = new List(); + var groups = new List(); var series = recordings - .Where(i => i.IsSeries) + .Where(i => i.RecordingInfo.IsSeries) .ToLookup(i => i.Name, StringComparer.OrdinalIgnoreCase) .ToList(); - groups.AddRange(series.OrderByString(i => i.Key).Select(i => new RecordingGroupDto + groups.AddRange(series.OrderByString(i => i.Key).Select(i => new BaseItemDto { Name = i.Key, RecordingCount = i.Count() })); - groups.Add(new RecordingGroupDto + groups.Add(new BaseItemDto { Name = "Kids", - RecordingCount = recordings.Count(i => i.IsKids) + RecordingCount = recordings.Count(i => i.RecordingInfo.IsKids) }); - groups.Add(new RecordingGroupDto + groups.Add(new BaseItemDto { Name = "Movies", - RecordingCount = recordings.Count(i => i.IsMovie) + RecordingCount = recordings.Count(i => i.RecordingInfo.IsMovie) }); - groups.Add(new RecordingGroupDto + groups.Add(new BaseItemDto { Name = "News", - RecordingCount = recordings.Count(i => i.IsNews) + RecordingCount = recordings.Count(i => i.RecordingInfo.IsNews) }); - groups.Add(new RecordingGroupDto + groups.Add(new BaseItemDto { Name = "Sports", - RecordingCount = recordings.Count(i => i.IsSports) + RecordingCount = recordings.Count(i => i.RecordingInfo.IsSports) }); - groups.Add(new RecordingGroupDto + groups.Add(new BaseItemDto { Name = "Others", - RecordingCount = recordings.Count(i => !i.IsSports && !i.IsNews && !i.IsMovie && !i.IsKids && !i.IsSeries) + RecordingCount = recordings.Count(i => !i.RecordingInfo.IsSports && !i.RecordingInfo.IsNews && !i.RecordingInfo.IsMovie && !i.RecordingInfo.IsKids && !i.RecordingInfo.IsSeries) }); groups = groups @@ -1841,7 +1911,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv group.Id = group.Name.ToLower().GetMD5().ToString("N"); } - return new QueryResult + return new QueryResult { Items = groups.ToArray(), TotalRecordCount = groups.Count diff --git a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json index c48de87973..286c7cd04d 100644 --- a/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json +++ b/MediaBrowser.Server.Implementations/Localization/JavaScript/javascript.json @@ -790,5 +790,6 @@ "OptionEnableFullscreen": "Enable Fullscreen", "ButtonServer": "Server", "HeaderAdmin": "Admin", - "HeaderLibrary": "Library" + "HeaderLibrary": "Library", + "HeaderMedia": "Media" } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 0c14520270..5625ef3beb 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -50,6 +50,7 @@ using MediaBrowser.Dlna.Main; using MediaBrowser.Dlna.MediaReceiverRegistrar; using MediaBrowser.Dlna.Ssdp; using MediaBrowser.LocalMetadata.Providers; +using MediaBrowser.LocalMetadata.Savers; using MediaBrowser.MediaEncoding.BdInfo; using MediaBrowser.MediaEncoding.Encoder; using MediaBrowser.MediaEncoding.Subtitles; @@ -449,7 +450,7 @@ namespace MediaBrowser.Server.Startup.Common SyncManager = new SyncManager(LibraryManager, SyncRepository, ImageProcessor, LogManager.GetLogger("SyncManager"), UserManager, () => DtoService, this, TVSeriesManager, () => MediaEncoder, FileSystemManager, () => SubtitleEncoder, ServerConfigurationManager, UserDataManager, () => MediaSourceManager, JsonSerializer); RegisterSingleInstance(SyncManager); - DtoService = new DtoService(LogManager.GetLogger("DtoService"), LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this, () => DeviceManager, () => MediaSourceManager); + DtoService = new DtoService(LogManager.GetLogger("DtoService"), LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ServerConfigurationManager, FileSystemManager, ProviderManager, () => ChannelManager, SyncManager, this, () => DeviceManager, () => MediaSourceManager, () => LiveTvManager); RegisterSingleInstance(DtoService); var encryptionManager = new EncryptionManager(); @@ -989,7 +990,7 @@ namespace MediaBrowser.Server.Startup.Common list.Add(typeof(DlnaEntryPoint).Assembly); // Local metadata - list.Add(typeof(AlbumXmlProvider).Assembly); + list.Add(typeof(BoxSetXmlSaver).Assembly); // Xbmc list.Add(typeof(ArtistNfoProvider).Assembly);