diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index d05e0951a..6c61ef66f 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.LiveTv; @@ -10,6 +9,7 @@ using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Querying; using ServiceStack; using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading; @@ -350,6 +350,8 @@ namespace MediaBrowser.Api.LiveTv [Authenticated] public class AddListingProvider : ListingsProviderInfo, IReturn { + public bool ValidateLogin { get; set; } + public bool ValidateListings { get; set; } } [Route("/LiveTv/ListingProviders", "DELETE", Summary = "Deletes a listing provider")] @@ -402,9 +404,9 @@ namespace MediaBrowser.Api.LiveTv } } - public object Post(AddListingProvider request) + public async Task Post(AddListingProvider request) { - var result = _liveTvManager.SaveListingProvider(request).Result; + var result = await _liveTvManager.SaveListingProvider(request, request.ValidateLogin, request.ValidateListings).ConfigureAwait(false); return ToOptimizedResult(result); } diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 8505b5d3a..3cc04333a 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -819,11 +819,11 @@ namespace MediaBrowser.Api.Playback /// /// Gets the audio encoder. /// - /// The request. + /// The state. /// System.String. - protected string GetAudioEncoder(StreamRequest request) + protected string GetAudioEncoder(StreamState state) { - var codec = request.AudioCodec; + var codec = state.OutputAudioCodec; if (string.Equals(codec, "aac", StringComparison.OrdinalIgnoreCase)) { @@ -848,11 +848,11 @@ namespace MediaBrowser.Api.Playback /// /// Gets the name of the output video codec /// - /// The request. + /// The state. /// System.String. - protected string GetVideoEncoder(VideoStreamRequest request) + protected string GetVideoEncoder(StreamState state) { - var codec = request.VideoCodec; + var codec = state.OutputVideoCodec; if (!string.IsNullOrEmpty(codec)) { diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs index 47eb38b2d..c201ffd58 100644 --- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs +++ b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs @@ -378,7 +378,7 @@ namespace MediaBrowser.Api.Playback.Dash protected override string GetAudioArguments(StreamState state) { - var codec = GetAudioEncoder(state.Request); + var codec = GetAudioEncoder(state); if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) { @@ -408,7 +408,7 @@ namespace MediaBrowser.Api.Playback.Dash protected override string GetVideoArguments(StreamState state) { - var codec = GetVideoEncoder(state.VideoRequest); + var codec = GetVideoEncoder(state); var args = "-codec:v:0 " + codec; diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 0a432a580..305547e41 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -791,7 +791,7 @@ namespace MediaBrowser.Api.Playback.Hls protected override string GetAudioArguments(StreamState state) { - var codec = GetAudioEncoder(state.Request); + var codec = GetAudioEncoder(state); if (!state.IsOutputVideo) { @@ -856,7 +856,7 @@ namespace MediaBrowser.Api.Playback.Hls return string.Empty; } - var codec = GetVideoEncoder(state.VideoRequest); + var codec = GetVideoEncoder(state); var args = "-codec:v:0 " + codec; diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index d8e3423fc..dcfafee78 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -48,7 +48,7 @@ namespace MediaBrowser.Api.Playback.Hls /// System.String. protected override string GetAudioArguments(StreamState state) { - var codec = GetAudioEncoder(state.Request); + var codec = GetAudioEncoder(state); if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) { @@ -83,7 +83,7 @@ namespace MediaBrowser.Api.Playback.Hls /// System.String. protected override string GetVideoArguments(StreamState state) { - var codec = GetVideoEncoder(state.VideoRequest); + var codec = GetVideoEncoder(state); var args = "-codec:v:0 " + codec; diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index ebd72b2ce..84ae26248 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -89,7 +89,7 @@ namespace MediaBrowser.Api.Playback.Progressive protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) { // Get the output codec name - var videoCodec = GetVideoEncoder(state.VideoRequest); + var videoCodec = GetVideoEncoder(state); var format = string.Empty; var keyFrame = string.Empty; @@ -183,7 +183,7 @@ namespace MediaBrowser.Api.Playback.Progressive } // Get the output codec name - var codec = GetAudioEncoder(state.Request); + var codec = GetAudioEncoder(state); var args = "-codec:a:0 " + codec; diff --git a/MediaBrowser.Controller/LiveTv/IListingsProvider.cs b/MediaBrowser.Controller/LiveTv/IListingsProvider.cs index 5e43f1d27..e60183bd9 100644 --- a/MediaBrowser.Controller/LiveTv/IListingsProvider.cs +++ b/MediaBrowser.Controller/LiveTv/IListingsProvider.cs @@ -13,7 +13,7 @@ namespace MediaBrowser.Controller.LiveTv string Type { get; } Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken); Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken); - Task Validate(ListingsProviderInfo info); + Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings); Task> GetLineups(ListingsProviderInfo info, string country, string location); } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs index a0deb34f0..259f6925b 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvManager.cs @@ -349,8 +349,10 @@ namespace MediaBrowser.Controller.LiveTv /// Saves the listing provider. /// /// The information. + /// if set to true [validate login]. + /// if set to true [validate listings]. /// Task. - Task SaveListingProvider(ListingsProviderInfo info); + Task SaveListingProvider(ListingsProviderInfo info, bool validateLogin, bool validateListings); /// /// Gets the lineups. /// diff --git a/MediaBrowser.Dlna/Didl/DidlBuilder.cs b/MediaBrowser.Dlna/Didl/DidlBuilder.cs index 50a6f3ba6..0e4cf7392 100644 --- a/MediaBrowser.Dlna/Didl/DidlBuilder.cs +++ b/MediaBrowser.Dlna/Didl/DidlBuilder.cs @@ -120,7 +120,7 @@ namespace MediaBrowser.Dlna.Didl } } - AddCover(item, null, element); + AddCover(item, context, null, element); return element; } @@ -481,7 +481,7 @@ namespace MediaBrowser.Dlna.Didl AddCommonFields(folder, stubType, null, container, filter); - AddCover(folder, stubType, container); + AddCover(folder, context, stubType, container); return container; } @@ -764,7 +764,7 @@ namespace MediaBrowser.Dlna.Didl } } - private void AddCover(BaseItem item, StubType? stubType, XmlElement element) + private void AddCover(BaseItem item, BaseItem context, StubType? stubType, XmlElement element) { if (stubType.HasValue && stubType.Value == StubType.People) { @@ -772,7 +772,26 @@ namespace MediaBrowser.Dlna.Didl return; } - var imageInfo = GetImageInfo(item); + ImageDownloadInfo imageInfo = null; + + if (context is UserView) + { + var episode = item as Episode; + if (episode != null) + { + var parent = (BaseItem)episode.Series ?? episode.Season; + if (parent != null) + { + imageInfo = GetImageInfo(parent); + } + } + } + + // Finally, just use the image from the item + if (imageInfo == null) + { + imageInfo = GetImageInfo(item); + } if (imageInfo == null) { @@ -850,7 +869,7 @@ namespace MediaBrowser.Dlna.Didl private void AddEmbeddedImageAsCover(string name, XmlElement element) { var result = element.OwnerDocument; - + var icon = result.CreateElement("upnp", "albumArtURI", NS_UPNP); var profile = result.CreateAttribute("dlna", "profileID", NS_DLNA); profile.InnerText = _profile.AlbumArtPn; @@ -925,14 +944,11 @@ namespace MediaBrowser.Dlna.Didl } } - if (item is Audio || item is Episode) - { - item = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Primary)); + item = item.Parents.FirstOrDefault(i => i.HasImage(ImageType.Primary)); - if (item != null) - { - return GetImageInfo(item, ImageType.Primary); - } + if (item != null) + { + return GetImageInfo(item, ImageType.Primary); } return null; diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs index 65d24ee80..5fd9745a1 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs @@ -400,13 +400,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings _logger.Info("Headends on account "); - var countryParam = string.Equals("ca", country, StringComparison.OrdinalIgnoreCase) - ? "can" - : "USA"; - var options = new HttpRequestOptions() { - Url = ApiUrl + "/headends?country=" + countryParam + "&postalcode=" + location, + Url = ApiUrl + "/headends?country=" + country + "&postalcode=" + location, UserAgent = UserAgent, CancellationToken = cancellationToken }; @@ -595,18 +591,32 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings } } - public async Task Validate(ListingsProviderInfo info) + public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings) { - if (string.IsNullOrWhiteSpace(info.ListingsId)) + if (validateLogin) { - throw new ArgumentException("Listings Id required"); + if (string.IsNullOrWhiteSpace(info.Username)) + { + throw new ArgumentException("Username is required"); + } + if (string.IsNullOrWhiteSpace(info.Password)) + { + throw new ArgumentException("Password is required"); + } } - - var hasLineup = await HasLineup(info, CancellationToken.None).ConfigureAwait(false); - - if (!hasLineup) + if (validateListings) { - await AddLineupToAccount(info, CancellationToken.None).ConfigureAwait(false); + if (string.IsNullOrWhiteSpace(info.ListingsId)) + { + throw new ArgumentException("Listings Id required"); + } + + var hasLineup = await HasLineup(info, CancellationToken.None).ConfigureAwait(false); + + if (!hasLineup) + { + await AddLineupToAccount(info, CancellationToken.None).ConfigureAwait(false); + } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs index 2e6fc8277..de107ced8 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs @@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings // Might not be needed } - public Task Validate(ListingsProviderInfo info) + public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings) { // Check that the path or url is valid. If not, throw a file not found exception } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 3ca60ec51..d539562b8 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -2204,7 +2204,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _taskManager.CancelIfRunningAndQueue(); } - public async Task SaveListingProvider(ListingsProviderInfo info) + public async Task SaveListingProvider(ListingsProviderInfo info, bool validateLogin, bool validateListings) { info = (ListingsProviderInfo)_jsonSerializer.DeserializeFromString(_jsonSerializer.SerializeToString(info), typeof(ListingsProviderInfo)); @@ -2215,7 +2215,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv throw new ResourceNotFoundException(); } - await provider.Validate(info).ConfigureAwait(false); + await provider.Validate(info, validateLogin, validateListings).ConfigureAwait(false); var config = GetConfiguration();