From a3c3fff39f64c5966cb18616dcb444ee0135df87 Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Tue, 31 May 2016 23:00:20 +0100 Subject: [PATCH 01/13] Added first stab at a XmlTvListingsProvider --- .../LiveTv/Listings/XmlTv.cs | 44 --------- .../LiveTv/Listings/XmlTvListingsProvider.cs | 95 +++++++++++++++++++ ...MediaBrowser.Server.Implementations.csproj | 2 +- 3 files changed, 96 insertions(+), 45 deletions(-) delete mode 100644 MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs create mode 100644 MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs deleted file mode 100644 index ac316f9a12..0000000000 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTv.cs +++ /dev/null @@ -1,44 +0,0 @@ -using MediaBrowser.Controller.LiveTv; -using MediaBrowser.Model.Dto; -using MediaBrowser.Model.LiveTv; -using System; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace MediaBrowser.Server.Implementations.LiveTv.Listings -{ - public class XmlTv : IListingsProvider - { - public string Name - { - get { return "XmlTV"; } - } - - public string Type - { - get { return "xmltv"; } - } - - public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) - { - throw new NotImplementedException(); - } - - public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) - { - // Might not be needed - } - - 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 - } - - public Task> GetLineups(ListingsProviderInfo info, string country, string location) - { - // In theory this should never be called because there is always only one lineup - throw new NotImplementedException(); - } - } -} diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs new file mode 100644 index 0000000000..ef596e5337 --- /dev/null +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -0,0 +1,95 @@ +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.LiveTv; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +using Emby.XmlTv.Classes; +using System.IO; + +namespace MediaBrowser.Server.Implementations.LiveTv.Listings +{ + public class XmlTvListingsProvider : IListingsProvider + { + private string _filePath = "C:\\Temp\\"; + private string _language = null; + + public string Name + { + get { return "XmlTV"; } + } + + public string Type + { + get { return "xmltv"; } + } + + // TODO: Should this method be async? + public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) + { + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken); + return Task.FromResult(results.Select(p => new ProgramInfo() + { + ChannelId = p.ChannelId, + //CommunityRating = p.Rating., + EndDate = p.EndDate, + EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, + EpisodeTitle = p.Episode == null ? null : p.Episode.Title, + Genres = p.Categories, + Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date, + StartDate = p.StartDate, + Name = p.Title, + Overview = p.Description, + // OfficialRating = p.OfficialRating, + ShortOverview = p.Description, + ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year, + SeasonNumber = p.Episode == null ? null : p.Episode.Series, + IsSeries = p.IsSeries, + IsRepeat = p.IsRepeat, + IsPremiere = !p.PreviouslyShown.HasValue, + })); + } + + public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) + { + // Add the channel image url + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetChannels().ToList(); + + if (channels != null && channels.Count > 0) + { + channels.ForEach(c => { + var match = results.FirstOrDefault(r => r.Id == c.Id); + if (match != null) + { + // c.ImageUrl = match.Url; + // TODO: Add support for the channel logo to the XMLTv Component + } + }); + } + } + + 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 + if (!File.Exists(_filePath)) + { + throw new FileNotFoundException("Could not find the XmlTv file specified", _filePath); + } + } + + public Task> GetLineups(ListingsProviderInfo info, string country, string location) + { + // In theory this should never be called because there is always only one lineup + var reader = new XmlTvReader(_filePath, _language, null); + var results = reader.GetChannels(); + + // Should this method be async? + return Task.FromResult(results.Select(c => new NameIdPair() { Id = c.Id, Name = c.DisplayName }).ToList()); + } + } +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 385a94aa5c..a27b12a893 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -232,7 +232,7 @@ - + From bd001d8c6ae58fce073db4822c706e058730d9ff Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Wed, 1 Jun 2016 19:44:19 +0100 Subject: [PATCH 02/13] Added Channel and Program Images and Category Mapping --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index ef596e5337..2c56b9a997 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -2,13 +2,13 @@ using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; using System; -using System.Linq; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; -using System.IO; namespace MediaBrowser.Server.Implementations.LiveTv.Listings { @@ -16,6 +16,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { private string _filePath = "C:\\Temp\\"; private string _language = null; + private Dictionary> _categoryMappings = new Dictionary>(){ + { "Movie", new List() { "Movie", "Film" } }, + { "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, + { "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, + { "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + }; public string Name { @@ -51,6 +57,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings IsSeries = p.IsSeries, IsRepeat = p.IsRepeat, IsPremiere = !p.PreviouslyShown.HasValue, + IsKids = p.Categories.Any(_categoryMappings["Kids"].Contains), + IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains), + IsNews = p.Categories.Any(_categoryMappings["News"].Contains), + IsSports = p.Categories.Any(_categoryMappings["Sports"].Contains), + ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null, + HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source), })); } @@ -64,10 +76,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { channels.ForEach(c => { var match = results.FirstOrDefault(r => r.Id == c.Id); - if (match != null) + if (match != null && match.Icon != null && !String.IsNullOrEmpty(match.Icon.Source)) { - // c.ImageUrl = match.Url; - // TODO: Add support for the channel logo to the XMLTv Component + c.ImageUrl = match.Icon.Source; } }); } From 2e040f9c0c3d8cca834687a7c729f14097f7a83b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 15:44:55 -0400 Subject: [PATCH 03/13] update collection grouping setting --- MediaBrowser.Controller/Entities/Folder.cs | 4 +- MediaBrowser.Controller/Entities/UserView.cs | 2 +- .../Entities/UserViewBuilder.cs | 31 +++++++------ .../Configuration/ServerConfiguration.cs | 1 + .../Connect/Responses.cs | 1 - .../MediaBrowser.Server.Startup.Common.csproj | 1 + .../Migrations/CollectionGroupingMigration.cs | 44 +++++++++++++++++++ 7 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 2e4cf3745e..6868418d3b 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -875,7 +875,7 @@ namespace MediaBrowser.Controller.Entities return true; } - if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User)) + if (UserViewBuilder.CollapseBoxSetItems(query, this, query.User, ConfigurationManager)) { Logger.Debug("Query requires post-filtering due to CollapseBoxSetItems"); return true; @@ -983,7 +983,7 @@ namespace MediaBrowser.Controller.Entities protected QueryResult PostFilterAndSort(IEnumerable items, InternalItemsQuery query) { - return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager); + return UserViewBuilder.PostFilterAndSort(items, this, null, query, LibraryManager, ConfigurationManager); } public virtual IEnumerable GetChildren(User user, bool includeLinkedChildren) diff --git a/MediaBrowser.Controller/Entities/UserView.cs b/MediaBrowser.Controller/Entities/UserView.cs index e40d9ca381..6ec719e875 100644 --- a/MediaBrowser.Controller/Entities/UserView.cs +++ b/MediaBrowser.Controller/Entities/UserView.cs @@ -58,7 +58,7 @@ namespace MediaBrowser.Controller.Entities parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent; } - return new UserViewBuilder(UserViewManager, LiveTvManager, ChannelManager, LibraryManager, Logger, UserDataManager, TVSeriesManager, CollectionManager, PlaylistManager) + return new UserViewBuilder(UserViewManager, LiveTvManager, ChannelManager, LibraryManager, Logger, UserDataManager, TVSeriesManager, ConfigurationManager, PlaylistManager) .GetUserItems(parent, this, ViewType, query); } diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index a7b23112e6..3c1c086ef8 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -18,6 +18,8 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Entities { @@ -30,10 +32,10 @@ namespace MediaBrowser.Controller.Entities private readonly ILogger _logger; private readonly IUserDataManager _userDataManager; private readonly ITVSeriesManager _tvSeriesManager; - private readonly ICollectionManager _collectionManager; + private readonly IServerConfigurationManager _config; private readonly IPlaylistManager _playlistManager; - public UserViewBuilder(IUserViewManager userViewManager, ILiveTvManager liveTvManager, IChannelManager channelManager, ILibraryManager libraryManager, ILogger logger, IUserDataManager userDataManager, ITVSeriesManager tvSeriesManager, ICollectionManager collectionManager, IPlaylistManager playlistManager) + public UserViewBuilder(IUserViewManager userViewManager, ILiveTvManager liveTvManager, IChannelManager channelManager, ILibraryManager libraryManager, ILogger logger, IUserDataManager userDataManager, ITVSeriesManager tvSeriesManager, IServerConfigurationManager config, IPlaylistManager playlistManager) { _userViewManager = userViewManager; _liveTvManager = liveTvManager; @@ -42,7 +44,7 @@ namespace MediaBrowser.Controller.Entities _logger = logger; _userDataManager = userDataManager; _tvSeriesManager = tvSeriesManager; - _collectionManager = collectionManager; + _config = config; _playlistManager = playlistManager; } @@ -159,7 +161,7 @@ namespace MediaBrowser.Controller.Entities return await GetTvGenres(queryParent, user, query).ConfigureAwait(false); case SpecialFolder.TvGenre: - return await GetTvGenreItems(queryParent, displayParent, user, query).ConfigureAwait(false); + return GetTvGenreItems(queryParent, displayParent, user, query); case SpecialFolder.TvResume: return GetTvResume(queryParent, user, query); @@ -740,7 +742,7 @@ namespace MediaBrowser.Controller.Entities return GetResult(genres, parent, query); } - private async Task> GetTvGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query) + private QueryResult GetTvGenreItems(Folder queryParent, Folder displayParent, User user, InternalItemsQuery query) { query.Recursive = true; query.ParentId = queryParent.Id; @@ -769,7 +771,7 @@ namespace MediaBrowser.Controller.Entities { items = items.Where(i => Filter(i, query.User, query, _userDataManager, _libraryManager)); - return PostFilterAndSort(items, queryParent, null, query, _libraryManager); + return PostFilterAndSort(items, queryParent, null, query, _libraryManager, _config); } public static bool FilterItem(BaseItem item, InternalItemsQuery query) @@ -782,14 +784,15 @@ namespace MediaBrowser.Controller.Entities int? totalRecordLimit, InternalItemsQuery query) { - return PostFilterAndSort(items, queryParent, totalRecordLimit, query, _libraryManager); + return PostFilterAndSort(items, queryParent, totalRecordLimit, query, _libraryManager, _config); } public static QueryResult PostFilterAndSort(IEnumerable items, BaseItem queryParent, int? totalRecordLimit, InternalItemsQuery query, - ILibraryManager libraryManager) + ILibraryManager libraryManager, + IServerConfigurationManager configurationManager) { var user = query.User; @@ -798,7 +801,7 @@ namespace MediaBrowser.Controller.Entities query.IsVirtualUnaired, query.IsUnaired); - items = CollapseBoxSetItemsIfNeeded(items, query, queryParent, user); + items = CollapseBoxSetItemsIfNeeded(items, query, queryParent, user, configurationManager); // This must be the last filter if (!string.IsNullOrEmpty(query.AdjacentTo)) @@ -812,14 +815,15 @@ namespace MediaBrowser.Controller.Entities public static IEnumerable CollapseBoxSetItemsIfNeeded(IEnumerable items, InternalItemsQuery query, BaseItem queryParent, - User user) + User user, + IServerConfigurationManager configurationManager) { if (items == null) { throw new ArgumentNullException("items"); } - if (CollapseBoxSetItems(query, queryParent, user)) + if (CollapseBoxSetItems(query, queryParent, user, configurationManager)) { items = BaseItem.CollectionManager.CollapseItemsWithinBoxSets(items, user); } @@ -852,7 +856,8 @@ namespace MediaBrowser.Controller.Entities public static bool CollapseBoxSetItems(InternalItemsQuery query, BaseItem queryParent, - User user) + User user, + IServerConfigurationManager configurationManager) { // Could end up stuck in a loop like this if (queryParent is BoxSet) @@ -864,7 +869,7 @@ namespace MediaBrowser.Controller.Entities if (!param.HasValue) { - if (user != null && !user.Configuration.GroupMoviesIntoBoxSets) + if (user != null && !configurationManager.Configuration.EnableGroupingIntoCollections) { return false; } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index e89aafacaa..993799f658 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -199,6 +199,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableStandaloneMusicKeys { get; set; } public bool EnableLocalizedGuids { get; set; } public bool EnableFolderView { get; set; } + public bool EnableGroupingIntoCollections { get; set; } /// /// Initializes a new instance of the class. diff --git a/MediaBrowser.Server.Implementations/Connect/Responses.cs b/MediaBrowser.Server.Implementations/Connect/Responses.cs index e7c3f81542..f865278294 100644 --- a/MediaBrowser.Server.Implementations/Connect/Responses.cs +++ b/MediaBrowser.Server.Implementations/Connect/Responses.cs @@ -60,7 +60,6 @@ namespace MediaBrowser.Server.Implementations.Connect { return new ConnectUserPreferences { - GroupMoviesIntoBoxSets = config.GroupMoviesIntoBoxSets, PlayDefaultAudioTrack = config.PlayDefaultAudioTrack, SubtitleMode = config.SubtitleMode, PreferredAudioLanguages = string.IsNullOrWhiteSpace(config.AudioLanguagePreference) ? new string[] { } : new[] { config.AudioLanguagePreference }, diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index a6d09d343a..e9fd14353b 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -71,6 +71,7 @@ + diff --git a/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs new file mode 100644 index 0000000000..b497eeb424 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/CollectionGroupingMigration.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Controller.Library; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class CollectionGroupingMigration : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly IUserManager _userManager; + + public CollectionGroupingMigration(IServerConfigurationManager config, IUserManager userManager) + { + _config = config; + _userManager = userManager; + } + + public void Run() + { + var migrationKey = this.GetType().Name; + var migrationKeyList = _config.Configuration.Migrations.ToList(); + + if (!migrationKeyList.Contains(migrationKey)) + { + if (_config.Configuration.IsStartupWizardCompleted) + { + if (_userManager.Users.Any(i => i.Configuration.GroupMoviesIntoBoxSets)) + { + _config.Configuration.EnableGroupingIntoCollections = true; + } + } + + migrationKeyList.Add(migrationKey); + _config.Configuration.Migrations = migrationKeyList.ToArray(); + _config.SaveConfiguration(); + } + + } + } +} From 9fc028b3d784a79fa7b4a7de8c28847e08f47167 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 16:39:37 -0400 Subject: [PATCH 04/13] revoke access tokens on password change --- MediaBrowser.Api/UserService.cs | 9 +++++++-- MediaBrowser.Controller/Session/ISessionManager.cs | 3 +-- .../Session/SessionManager.cs | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 9b611c3971..07ff36c41f 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -385,7 +385,7 @@ namespace MediaBrowser.Api throw new ResourceNotFoundException("User not found"); } - await _sessionMananger.RevokeUserTokens(user.Id.ToString("N")).ConfigureAwait(false); + await _sessionMananger.RevokeUserTokens(user.Id.ToString("N"), null).ConfigureAwait(false); await _userManager.DeleteUser(user).ConfigureAwait(false); } @@ -465,6 +465,10 @@ namespace MediaBrowser.Api } await _userManager.ChangePassword(user, request.NewPassword).ConfigureAwait(false); + + var currentToken = AuthorizationContext.GetAuthorizationInfo(Request).Token; + + await _sessionMananger.RevokeUserTokens(user.Id.ToString("N"), currentToken).ConfigureAwait(false); } } @@ -602,7 +606,8 @@ namespace MediaBrowser.Api throw new ArgumentException("There must be at least one enabled user in the system."); } - await _sessionMananger.RevokeUserTokens(user.Id.ToString("N")).ConfigureAwait(false); + var currentToken = AuthorizationContext.GetAuthorizationInfo(Request).Token; + await _sessionMananger.RevokeUserTokens(user.Id.ToString("N"), currentToken).ConfigureAwait(false); } await _userManager.UpdateUserPolicy(request.Id, request).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Session/ISessionManager.cs b/MediaBrowser.Controller/Session/ISessionManager.cs index fa74c57499..6659d15530 100644 --- a/MediaBrowser.Controller/Session/ISessionManager.cs +++ b/MediaBrowser.Controller/Session/ISessionManager.cs @@ -315,9 +315,8 @@ namespace MediaBrowser.Controller.Session /// /// Revokes the user tokens. /// - /// The user identifier. /// Task. - Task RevokeUserTokens(string userId); + Task RevokeUserTokens(string userId, string currentAccessToken); /// /// Revokes the token. diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 4386b785ad..098fe0b4d5 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1451,7 +1451,7 @@ namespace MediaBrowser.Server.Implementations.Session } } - public async Task RevokeUserTokens(string userId) + public async Task RevokeUserTokens(string userId, string currentAccessToken) { var existing = _authRepo.Get(new AuthenticationInfoQuery { @@ -1461,7 +1461,10 @@ namespace MediaBrowser.Server.Implementations.Session foreach (var info in existing.Items) { - await Logout(info.AccessToken).ConfigureAwait(false); + if (!string.Equals(currentAccessToken, info.AccessToken, StringComparison.OrdinalIgnoreCase)) + { + await Logout(info.AccessToken).ConfigureAwait(false); + } } } From d10a5042f68c7f9f72a48af05225b72284a28a6c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 16:41:44 -0400 Subject: [PATCH 05/13] update LiveTvOptions --- MediaBrowser.Model/LiveTv/LiveTvOptions.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs index 9e34ff0426..bcc957df29 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs @@ -73,15 +73,17 @@ namespace MediaBrowser.Model.LiveTv public string[] EnabledTuners { get; set; } public bool EnableAllTuners { get; set; } - public string[] NewsGenres { get; set; } - public string[] SportsGenres { get; set; } - public string[] KidsGenres { get; set; } + public string[] NewsCategories { get; set; } + public string[] SportsCategories { get; set; } + public string[] KidsCategories { get; set; } + public string[] MovieCategories { get; set; } public ListingsProviderInfo() { - NewsGenres = new string[] { "news" }; - SportsGenres = new string[] { "sports", "basketball", "baseball", "football" }; - KidsGenres = new string[] { "kids", "family", "children" }; + NewsCategories = new string[] { "news" }; + SportsCategories = new string[] { "sports", "basketball", "baseball", "football" }; + KidsCategories = new string[] { "kids", "family", "children" }; + MovieCategories = new string[] { "movie" }; EnabledTuners = new string[] { }; EnableAllTuners = true; } From c0e9d72bafe0dcea396b99e09942ee5a4de1bc8f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 16:46:19 -0400 Subject: [PATCH 06/13] update icon buttons --- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 3 --- 1 file changed, 3 deletions(-) diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 36693ad8e7..d6c1ad6bcb 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -152,9 +152,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest From 767de9aa1e8da5a7cecc7f72259559751c317c4f Mon Sep 17 00:00:00 2001 From: Alex Stevens Date: Sun, 5 Jun 2016 21:53:21 +0100 Subject: [PATCH 07/13] More updates to the XmlTVListingsProvider --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 2c56b9a997..c5060944d2 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -14,13 +14,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { public class XmlTvListingsProvider : IListingsProvider { - private string _filePath = "C:\\Temp\\"; private string _language = null; private Dictionary> _categoryMappings = new Dictionary>(){ { "Movie", new List() { "Movie", "Film" } }, - { "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, - { "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, - { "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + //{ "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, + //{ "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, + //{ "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, + }; + + private Dictionary _channelMappings = new Dictionary(){ + { "1", "UK_RT_2667" }, + { "2", "UK_RT_116" }, + { "3", "UK_RT_2118" }, + { "4", "UK_RT_2056" }, + { "5", "UK_RT_134" } }; public string Name @@ -36,12 +43,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings // TODO: Should this method be async? public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { - var reader = new XmlTvReader(_filePath, _language, null); - var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken); + var reader = new XmlTvReader(info.Path, _language, null); + string mappedChannel = channelNumber; + + if (_channelMappings.ContainsKey(channelNumber)) + { + mappedChannel = _channelMappings[channelNumber]; + } + + var results = reader.GetProgrammes(mappedChannel, startDateUtc, endDateUtc, cancellationToken); return Task.FromResult(results.Select(p => new ProgramInfo() { ChannelId = p.ChannelId, - //CommunityRating = p.Rating., EndDate = p.EndDate, EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeTitle = p.Episode == null ? null : p.Episode.Title, @@ -50,26 +63,27 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings StartDate = p.StartDate, Name = p.Title, Overview = p.Description, - // OfficialRating = p.OfficialRating, ShortOverview = p.Description, ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year, SeasonNumber = p.Episode == null ? null : p.Episode.Series, IsSeries = p.IsSeries, IsRepeat = p.IsRepeat, - IsPremiere = !p.PreviouslyShown.HasValue, - IsKids = p.Categories.Any(_categoryMappings["Kids"].Contains), + // IsPremiere = !p.PreviouslyShown.HasValue, + IsKids = p.Categories.Any(info.KidsGenres.Contains), IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains), - IsNews = p.Categories.Any(_categoryMappings["News"].Contains), - IsSports = p.Categories.Any(_categoryMappings["Sports"].Contains), + IsNews = p.Categories.Any(info.NewsGenres.Contains), + IsSports = p.Categories.Any(info.SportsGenres.Contains), ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null, HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source), + OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null, + CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null })); } public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) { // Add the channel image url - var reader = new XmlTvReader(_filePath, _language, null); + var reader = new XmlTvReader(info.Path, _language, null); var results = reader.GetChannels().ToList(); if (channels != null && channels.Count > 0) @@ -87,16 +101,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings 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 - if (!File.Exists(_filePath)) + if (!File.Exists(info.Path)) { - throw new FileNotFoundException("Could not find the XmlTv file specified", _filePath); + throw new FileNotFoundException("Could not find the XmlTv file specified:", info.Path); } } public Task> GetLineups(ListingsProviderInfo info, string country, string location) { // In theory this should never be called because there is always only one lineup - var reader = new XmlTvReader(_filePath, _language, null); + var reader = new XmlTvReader(info.Path, _language, null); var results = reader.GetChannels(); // Should this method be async? From fa76620eb75dcf194ce02a2c1fe2b6178e5acaa3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 17:07:23 -0400 Subject: [PATCH 08/13] update xmltv categories --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index c5060944d2..ac741a7d2d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -69,10 +69,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings IsSeries = p.IsSeries, IsRepeat = p.IsRepeat, // IsPremiere = !p.PreviouslyShown.HasValue, - IsKids = p.Categories.Any(info.KidsGenres.Contains), - IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains), - IsNews = p.Categories.Any(info.NewsGenres.Contains), - IsSports = p.Categories.Any(info.SportsGenres.Contains), + IsKids = p.Categories.Any(info.KidsCategories.Contains), + IsMovie = p.Categories.Any(info.MovieCategories.Contains), + IsNews = p.Categories.Any(info.NewsCategories.Contains), + IsSports = p.Categories.Any(info.SportsCategories.Contains), ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null, HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source), OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null, From 7388320d96a12044f367bf3f1e5e6e31c1904608 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 17:08:55 -0400 Subject: [PATCH 09/13] update xmltv --- MediaBrowser.Model/LiveTv/LiveTvOptions.cs | 4 ++-- .../LiveTv/Listings/XmlTvListingsProvider.cs | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs index bcc957df29..33f63e3eb2 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs @@ -80,9 +80,9 @@ namespace MediaBrowser.Model.LiveTv public ListingsProviderInfo() { - NewsCategories = new string[] { "news" }; + NewsCategories = new string[] { "news", "journalism", "documentary", "current affairs" }; SportsCategories = new string[] { "sports", "basketball", "baseball", "football" }; - KidsCategories = new string[] { "kids", "family", "children" }; + KidsCategories = new string[] { "kids", "family", "children", "childrens", "disney" }; MovieCategories = new string[] { "movie" }; EnabledTuners = new string[] { }; EnableAllTuners = true; diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index ac741a7d2d..a713ff0ef0 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -15,12 +15,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings public class XmlTvListingsProvider : IListingsProvider { private string _language = null; - private Dictionary> _categoryMappings = new Dictionary>(){ - { "Movie", new List() { "Movie", "Film" } }, - //{ "Sports", new List() { "Sports", "Football", "Rugby", "Soccer" } }, - //{ "Kids", new List() { "Childrens", "Children", "Kids", "Disney" } }, - //{ "News", new List() { "News", "Journalism", "Documentary", "Current Affairs" } }, - }; private Dictionary _channelMappings = new Dictionary(){ { "1", "UK_RT_2667" }, From 73ab3edeec59b5db3b630574a4796973eddc636b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 Jun 2016 17:27:14 -0400 Subject: [PATCH 10/13] update xmltv language --- .../LiveTv/Listings/XmlTvListingsProvider.cs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index a713ff0ef0..4f43d93b70 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -9,12 +9,13 @@ using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; +using MediaBrowser.Controller.Configuration; namespace MediaBrowser.Server.Implementations.LiveTv.Listings { public class XmlTvListingsProvider : IListingsProvider { - private string _language = null; + private readonly IServerConfigurationManager _config; private Dictionary _channelMappings = new Dictionary(){ { "1", "UK_RT_2667" }, @@ -24,6 +25,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { "5", "UK_RT_134" } }; + public XmlTvListingsProvider(IServerConfigurationManager config) + { + _config = config; + } + public string Name { get { return "XmlTV"; } @@ -34,10 +40,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings get { return "xmltv"; } } + private string GetLanguage() + { + return _config.Configuration.PreferredMetadataLanguage; + } + // TODO: Should this method be async? public Task> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) { - var reader = new XmlTvReader(info.Path, _language, null); + var reader = new XmlTvReader(info.Path, GetLanguage(), null); string mappedChannel = channelNumber; if (_channelMappings.ContainsKey(channelNumber)) @@ -77,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) { // Add the channel image url - var reader = new XmlTvReader(info.Path, _language, null); + var reader = new XmlTvReader(info.Path, GetLanguage(), null); var results = reader.GetChannels().ToList(); if (channels != null && channels.Count > 0) @@ -104,7 +115,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings public Task> GetLineups(ListingsProviderInfo info, string country, string location) { // In theory this should never be called because there is always only one lineup - var reader = new XmlTvReader(info.Path, _language, null); + var reader = new XmlTvReader(info.Path, GetLanguage(), null); var results = reader.GetChannels(); // Should this method be async? From 3e066ab9f5e0d21637ce2fb3779eb9d9438578b1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 6 Jun 2016 13:33:39 -0400 Subject: [PATCH 11/13] don't replace tv channel images --- .../LiveTv/ChannelImageProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs index dccc7aa932..23560b1aa1 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/ChannelImageProvider.cs @@ -41,7 +41,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase)); - if (service != null) + if (service != null && !item.HasImage(ImageType.Primary)) { try { From faefbf36cc761f6b488f9ad3dfdd3ebdf7022c8a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 6 Jun 2016 13:33:55 -0400 Subject: [PATCH 12/13] adjust bitrate in h264/h265 conversions --- .../Playback/BaseStreamingService.cs | 10 ++++++++-- MediaBrowser.Api/Subtitles/SubtitleService.cs | 2 +- .../Encoder/EncodingJobFactory.cs | 10 ++++++++-- .../Dlna/ResolutionNormalizer.cs | 20 +++++++++++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index c655110740..f2357ba8ab 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1207,7 +1207,7 @@ namespace MediaBrowser.Api.Playback } } - private int? GetVideoBitrateParamValue(VideoStreamRequest request, MediaStream videoStream) + private int? GetVideoBitrateParamValue(VideoStreamRequest request, MediaStream videoStream, string outputVideoCodec) { var bitrate = request.VideoBitRate; @@ -1232,6 +1232,12 @@ namespace MediaBrowser.Api.Playback } } + if (bitrate.HasValue) + { + var inputVideoCodec = videoStream == null ? null : videoStream.Codec; + bitrate = ResolutionNormalizer.ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec); + } + return bitrate; } @@ -1692,7 +1698,7 @@ namespace MediaBrowser.Api.Playback if (videoRequest != null) { state.OutputVideoCodec = state.VideoRequest.VideoCodec; - state.OutputVideoBitrate = GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream); + state.OutputVideoBitrate = GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec); if (state.OutputVideoBitrate.HasValue) { diff --git a/MediaBrowser.Api/Subtitles/SubtitleService.cs b/MediaBrowser.Api/Subtitles/SubtitleService.cs index 160fda065f..0500f33055 100644 --- a/MediaBrowser.Api/Subtitles/SubtitleService.cs +++ b/MediaBrowser.Api/Subtitles/SubtitleService.cs @@ -221,7 +221,7 @@ namespace MediaBrowser.Api.Subtitles if (string.Equals(request.Format, "vtt", StringComparison.OrdinalIgnoreCase) && request.AddVttTimeMap) { - text = text.Replace("WEBVTT", "WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000"); + //text = text.Replace("WEBVTT", "WEBVTT\nX-TIMESTAMP-MAP=MPEGTS:900000,LOCAL:00:00:00.000"); } return ResultFactory.GetResult(text, MimeTypes.GetMimeType("file." + request.Format)); diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index 1544a78b66..f858fab322 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -99,7 +99,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (videoRequest != null) { state.OutputVideoCodec = state.Options.VideoCodec; - state.OutputVideoBitrate = GetVideoBitrateParamValue(state.Options, state.VideoStream); + state.OutputVideoBitrate = GetVideoBitrateParamValue(state.Options, state.VideoStream, state.OutputVideoCodec); if (state.OutputVideoBitrate.HasValue) { @@ -396,7 +396,7 @@ namespace MediaBrowser.MediaEncoding.Encoder return request.AudioChannels; } - private int? GetVideoBitrateParamValue(EncodingJobOptions request, MediaStream videoStream) + private int? GetVideoBitrateParamValue(EncodingJobOptions request, MediaStream videoStream, string outputVideoCodec) { var bitrate = request.VideoBitRate; @@ -421,6 +421,12 @@ namespace MediaBrowser.MediaEncoding.Encoder } } + if (bitrate.HasValue) + { + var inputVideoCodec = videoStream == null ? null : videoStream.Codec; + bitrate = ResolutionNormalizer.ScaleBitrate(bitrate.Value, inputVideoCodec, outputVideoCodec); + } + return bitrate; } diff --git a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs index 8a412ac2c6..ed18fed655 100644 --- a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs +++ b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs @@ -56,5 +56,25 @@ namespace MediaBrowser.Model.Dlna MaxHeight = maxHeight }; } + + private static double GetVideoBitrateScaleFactor(string codec) + { + if (string.Equals(codec, "h265", StringComparison.OrdinalIgnoreCase) || + string.Equals(codec, "hevc", StringComparison.OrdinalIgnoreCase)) + { + return .5; + } + return 1; + } + + public static int ScaleBitrate(int bitrate, string inputVideoCodec, string outputVideoCodec) + { + var inputScaleFactor = GetVideoBitrateScaleFactor(inputVideoCodec); + var outputScaleFactor = GetVideoBitrateScaleFactor(outputVideoCodec); + var scaleFactor = outputScaleFactor/inputScaleFactor; + var newBitrate = scaleFactor*bitrate; + + return Convert.ToInt32(newBitrate); + } } } From 83105f5aaeea7af09154f6c765b414393740f00d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 6 Jun 2016 14:22:42 -0400 Subject: [PATCH 13/13] stubbed out channel mappings --- MediaBrowser.Model/LiveTv/LiveTvOptions.cs | 3 +++ .../LiveTv/EmbyTV/EmbyTV.cs | 23 ++++++++++++++++++- .../LiveTv/Listings/XmlTvListingsProvider.cs | 13 ----------- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs index 33f63e3eb2..0e44980df2 100644 --- a/MediaBrowser.Model/LiveTv/LiveTvOptions.cs +++ b/MediaBrowser.Model/LiveTv/LiveTvOptions.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using MediaBrowser.Model.Dto; namespace MediaBrowser.Model.LiveTv { @@ -77,6 +78,7 @@ namespace MediaBrowser.Model.LiveTv public string[] SportsCategories { get; set; } public string[] KidsCategories { get; set; } public string[] MovieCategories { get; set; } + public NameValuePair[] ChannelMappings { get; set; } public ListingsProviderInfo() { @@ -86,6 +88,7 @@ namespace MediaBrowser.Model.LiveTv MovieCategories = new string[] { "movie" }; EnabledTuners = new string[] { }; EnableAllTuners = true; + ChannelMappings = new NameValuePair[] {}; } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 6e5e8298f9..41c137c295 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -625,7 +625,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV _logger.Debug("Getting programs for channel {0}-{1} from {2}-{3}", channel.Number, channel.Name, provider.Item1.Name, provider.Item2.ListingsId ?? string.Empty); - var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channel.Number, channel.Name, startDateUtc, endDateUtc, cancellationToken) + var channelMappings = GetChannelMappings(provider.Item2); + var channelNumber = channel.Number; + string mappedChannelNumber; + if (channelMappings.TryGetValue(channelNumber, out mappedChannelNumber)) + { + _logger.Debug("Found mapped channel on provider {0}. Tuner channel number: {1}, Mapped channel number: {2}", provider.Item1.Name, channelNumber, mappedChannelNumber); + channelNumber = mappedChannelNumber; + } + + var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channelNumber, channel.Name, startDateUtc, endDateUtc, cancellationToken) .ConfigureAwait(false); var list = programs.ToList(); @@ -647,6 +656,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV return new List(); } + private Dictionary GetChannelMappings(ListingsProviderInfo info) + { + var dict = new Dictionary(StringComparer.OrdinalIgnoreCase); + + foreach (var mapping in info.ChannelMappings) + { + dict[mapping.Name] = mapping.Value; + } + + return dict; + } + private List> GetListingProviders() { return GetConfiguration().ListingProviders diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 4f43d93b70..5b0b2ad84b 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -17,14 +17,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings { private readonly IServerConfigurationManager _config; - private Dictionary _channelMappings = new Dictionary(){ - { "1", "UK_RT_2667" }, - { "2", "UK_RT_116" }, - { "3", "UK_RT_2118" }, - { "4", "UK_RT_2056" }, - { "5", "UK_RT_134" } - }; - public XmlTvListingsProvider(IServerConfigurationManager config) { _config = config; @@ -51,11 +43,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings var reader = new XmlTvReader(info.Path, GetLanguage(), null); string mappedChannel = channelNumber; - if (_channelMappings.ContainsKey(channelNumber)) - { - mappedChannel = _channelMappings[channelNumber]; - } - var results = reader.GetProgrammes(mappedChannel, startDateUtc, endDateUtc, cancellationToken); return Task.FromResult(results.Select(p => new ProgramInfo() {