The Free Software Media System - Server Backend & API
added chromecast boilerplate
Luke Pulverenti2d27b10d1155
diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.csindex 29d6e4084e..ea7ecfb4a0 100644--- a/MediaBrowser.Controller/Entities/Book.cs+++ b/MediaBrowser.Controller/Entities/Book.cs@@ -1,7 +1,7 @@-using System.Linq;-using MediaBrowser.Controller.Providers;+using MediaBrowser.Controller.Providers;using MediaBrowser.Model.Configuration;using System.Collections.Generic;+using System.Linq;namespace MediaBrowser.Controller.Entities{diff --git a/MediaBrowser.Controller/Entities/IHasSoundtracks.cs b/MediaBrowser.Controller/Entities/IHasSoundtracks.csindex 31defc9f47..3ac2491fbc 100644--- a/MediaBrowser.Controller/Entities/IHasSoundtracks.cs+++ b/MediaBrowser.Controller/Entities/IHasSoundtracks.cs@@ -13,5 +13,17 @@ namespace MediaBrowser.Controller.Entities/// </summary>/// <value>The soundtrack ids.</value>List<Guid> SoundtrackIds { get; set; }++ /// <summary>+ /// Gets the name.+ /// </summary>+ /// <value>The name.</value>+ string Name { get; }++ /// <summary>+ /// Gets the identifier.+ /// </summary>+ /// <value>The identifier.</value>+ Guid Id { get; }}}diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.csindex e16683d6d0..fa85f0edce 100644--- a/MediaBrowser.Controller/Entities/Video.cs+++ b/MediaBrowser.Controller/Entities/Video.cs@@ -127,11 +127,6 @@ namespace MediaBrowser.Controller.Entities/// <returns>List{System.String}.</returns>public List<string> GetPlayableStreamFiles(string rootPath){- if (PlayableStreamFileNames == null)- {- return null;- }-var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.csindex 668c3a414b..edf86cae8d 100644--- a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs+++ b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs@@ -2,6 +2,7 @@using MediaBrowser.Controller.Providers;using System.Threading;using System.Threading.Tasks;+using MediaBrowser.Model.Library;namespace MediaBrowser.Controller.LiveTv{@@ -20,5 +21,7 @@ namespace MediaBrowser.Controller.LiveTvbool IsParentalAllowed(User user);Task RefreshMetadata(MetadataRefreshOptions options, CancellationToken cancellationToken);++ PlayAccess GetPlayAccess(User user);}}diff --git a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs b/MediaBrowser.Model/LiveTv/ChannelInfoDto.csindex 170d7eb734..d17e2a7f9a 100644--- a/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs+++ b/MediaBrowser.Model/LiveTv/ChannelInfoDto.cs@@ -5,6 +5,7 @@ using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;using System;using System.Collections.Generic;+using MediaBrowser.Model.Library;namespace MediaBrowser.Model.LiveTv{@@ -44,6 +45,12 @@ namespace MediaBrowser.Model.LiveTv/// <value>The number.</value>public string Number { get; set; }+ /// <summary>+ /// Gets or sets the play access.+ /// </summary>+ /// <value>The play access.</value>+ public PlayAccess PlayAccess { get; set; }+/// <summary>/// Gets or sets the name of the service./// </summary>diff --git a/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs b/MediaBrowser.Model/LiveTv/ProgramInfoDto.csindex d761e88e67..f6b343bdbd 100644--- a/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs+++ b/MediaBrowser.Model/LiveTv/ProgramInfoDto.cs@@ -5,6 +5,7 @@ using MediaBrowser.Model.Dto;using MediaBrowser.Model.Entities;using System;using System.Collections.Generic;+using MediaBrowser.Model.Library;namespace MediaBrowser.Model.LiveTv{@@ -46,6 +47,12 @@ namespace MediaBrowser.Model.LiveTv/// <value>The channel primary image tag.</value>public Guid? ChannelPrimaryImageTag { get; set; }+ /// <summary>+ /// Gets or sets the play access.+ /// </summary>+ /// <value>The play access.</value>+ public PlayAccess PlayAccess { get; set; }+/// <summary>/// Gets or sets the name of the channel./// </summary>diff --git a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs b/MediaBrowser.Model/LiveTv/RecordingInfoDto.csindex 6df9ef7256..40aa5710e2 100644--- a/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs+++ b/MediaBrowser.Model/LiveTv/RecordingInfoDto.cs@@ -5,6 +5,7 @@ using MediaBrowser.Model.Entities;using System;using System.Collections.Generic;using System.ComponentModel;+using MediaBrowser.Model.Library;namespace MediaBrowser.Model.LiveTv{@@ -39,6 +40,12 @@ namespace MediaBrowser.Model.LiveTv/// </summary>public string ChannelId { get; set; }+ /// <summary>+ /// Gets or sets the play access.+ /// </summary>+ /// <value>The play access.</value>+ public PlayAccess PlayAccess { get; set; }+/// <summary>/// Gets or sets the channel primary image tag./// </summary>diff --git a/MediaBrowser.Providers/Music/SoundtrackPostScanTask.cs b/MediaBrowser.Providers/Music/SoundtrackPostScanTask.csindex 1fd3fb9d9f..0e5dfdb2b6 100644--- a/MediaBrowser.Providers/Music/SoundtrackPostScanTask.cs+++ b/MediaBrowser.Providers/Music/SoundtrackPostScanTask.cs@@ -1,12 +1,12 @@-using MediaBrowser.Controller.Entities;+using MediaBrowser.Common.Extensions;+using MediaBrowser.Controller.Entities;using MediaBrowser.Controller.Entities.Audio;-using MediaBrowser.Controller.Entities.Movies;-using MediaBrowser.Controller.Entities.TV;using MediaBrowser.Controller.Library;-using MediaBrowser.Model.Entities;using System;using System.Collections.Generic;+using System.Globalization;using System.Linq;+using System.Text;using System.Threading;using System.Threading.Tasks;@@ -39,126 +39,72 @@ namespace MediaBrowser.Providers.Music.OfType<MusicAlbum>().ToList();- AttachMovieSoundtracks(allItems, musicAlbums, cancellationToken);+ var itemsWithSoundtracks = allItems.OfType<IHasSoundtracks>().ToList();- progress.Report(25);+ foreach (var item in itemsWithSoundtracks)+ {+ cancellationToken.ThrowIfCancellationRequested();- AttachTvSoundtracks(allItems, musicAlbums, cancellationToken);+ item.SoundtrackIds = GetSoundtrackIds(item, musicAlbums).ToList();+ }progress.Report(50);- AttachGameSoundtracks(allItems, musicAlbums, cancellationToken);-- progress.Report(75);+ itemsWithSoundtracks = itemsWithSoundtracks.Where(i => i.SoundtrackIds.Count > 0).ToList();- AttachAlbumLinks(allItems, musicAlbums, cancellationToken);+ foreach (var album in musicAlbums)+ {+ cancellationToken.ThrowIfCancellationRequested();++ album.SoundtrackIds = GetAlbumLinks(album.Id, itemsWithSoundtracks).ToList();+ }progress.Report(100);}- private void AttachMovieSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)+ private IEnumerable<Guid> GetSoundtrackIds(IHasSoundtracks item, IEnumerable<MusicAlbum> albums){- foreach (var movie in allItems- .Where(i => (i is Movie) || (i is Trailer)))- {- var hasSoundtracks = (IHasSoundtracks) movie;+ var itemName = GetComparableName(item.Name);- cancellationToken.ThrowIfCancellationRequested();-- var tmdbId = movie.GetProviderId(MetadataProviders.Tmdb);-- if (string.IsNullOrEmpty(tmdbId))- {- hasSoundtracks.SoundtrackIds = new List<Guid>();- continue;- }-- hasSoundtracks.SoundtrackIds = allAlbums- .Where(i => string.Equals(tmdbId, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase))- .Select(i => i.Id)- .ToList();- }+ return albums.Where(i => string.Equals(itemName, GetComparableName(i.Name), StringComparison.OrdinalIgnoreCase)).Select(i => i.Id);}- private void AttachTvSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)+ private static string GetComparableName(string name){- foreach (var series in allItems.OfType<Series>())- {- cancellationToken.ThrowIfCancellationRequested();-- var tvdbId = series.GetProviderId(MetadataProviders.Tvdb);-- if (string.IsNullOrEmpty(tvdbId))- {- series.SoundtrackIds = new List<Guid>();- continue;- }-- series.SoundtrackIds = allAlbums- .Where(i => string.Equals(tvdbId, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase))- .Select(i => i.Id)- .ToList();- }+ name = " " + name + " ";++ name = name.Replace(".", " ")+ .Replace("_", " ")+ .Replace("&", " ")+ .Replace("!", " ")+ .Replace("(", " ")+ .Replace(")", " ")+ .Replace(",", " ")+ .Replace("-", " ")+ .Replace(" a ", String.Empty, StringComparison.OrdinalIgnoreCase)+ .Replace(" the ", String.Empty, StringComparison.OrdinalIgnoreCase)+ .Replace(" ", String.Empty);++ return name.Trim();}- private void AttachGameSoundtracks(IEnumerable<BaseItem> allItems, List<MusicAlbum> allAlbums, CancellationToken cancellationToken)+ /// <summary>+ /// Removes the diacritics.+ /// </summary>+ /// <param name="text">The text.</param>+ /// <returns>System.String.</returns>+ private static string RemoveDiacritics(string text){- foreach (var game in allItems.OfType<Game>())- {- cancellationToken.ThrowIfCancellationRequested();-- var gamesdb = game.GetProviderId(MetadataProviders.Gamesdb);-- if (string.IsNullOrEmpty(gamesdb))- {- game.SoundtrackIds = new List<Guid>();- continue;- }-- game.SoundtrackIds = allAlbums- .Where(i => string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase))- .Select(i => i.Id)- .ToList();- }+ return String.Concat(+ text.Normalize(NormalizationForm.FormD)+ .Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) !=+ UnicodeCategory.NonSpacingMark)+ ).Normalize(NormalizationForm.FormC);}- private void AttachAlbumLinks(List<BaseItem> allItems, IEnumerable<MusicAlbum> allAlbums, CancellationToken cancellationToken)+ private IEnumerable<Guid> GetAlbumLinks(Guid albumId, IEnumerable<IHasSoundtracks> items){- foreach (var album in allAlbums)- {- cancellationToken.ThrowIfCancellationRequested();-- var tmdb = album.GetProviderId(MetadataProviders.Tmdb);- var tvdb = album.GetProviderId(MetadataProviders.Tvdb);- var gamesdb = album.GetProviderId(MetadataProviders.Gamesdb);-- if (string.IsNullOrEmpty(tmdb) && string.IsNullOrEmpty(tvdb) && string.IsNullOrEmpty(gamesdb))- {- album.SoundtrackIds = new List<Guid>();- continue;- }-- album.SoundtrackIds = allItems.- Where(i =>- {- if (!string.IsNullOrEmpty(tmdb) && string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) && i is Movie)- {- return true;- }- if (!string.IsNullOrEmpty(tmdb) && string.Equals(tmdb, i.GetProviderId(MetadataProviders.Tmdb), StringComparison.OrdinalIgnoreCase) && i is Trailer)- {- return true;- }- if (!string.IsNullOrEmpty(tvdb) && string.Equals(tvdb, i.GetProviderId(MetadataProviders.Tvdb), StringComparison.OrdinalIgnoreCase) && i is Series)- {- return true;- }-- return !string.IsNullOrEmpty(gamesdb) && string.Equals(gamesdb, i.GetProviderId(MetadataProviders.Gamesdb), StringComparison.OrdinalIgnoreCase) && i is Game;- })- .Select(i => i.Id)- .ToList();- }+ return items.Where(i => i.SoundtrackIds.Contains(albumId)).Select(i => i.Id);}}}diff --git a/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs b/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.csindex 75e5d92c38..23d0363cb8 100644--- a/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs+++ b/MediaBrowser.Server.Implementations/FileOrganization/NameUtils.cs@@ -1,4 +1,5 @@-using MediaBrowser.Controller.Entities;+using MediaBrowser.Common.Extensions;+using MediaBrowser.Controller.Entities;using System;using System.Globalization;using System.Linq;@@ -58,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganizationname = RemoveDiacritics(name);- name = " " + name.ToLower() + " ";+ name = " " + name + " ";name = name.Replace(".", " ").Replace("_", " ")@@ -68,8 +69,8 @@ namespace MediaBrowser.Server.Implementations.FileOrganization.Replace(")", " ").Replace(",", " ").Replace("-", " ")- .Replace(" a ", String.Empty)- .Replace(" the ", String.Empty)+ .Replace(" a ", String.Empty, StringComparison.OrdinalIgnoreCase)+ .Replace(" the ", String.Empty, StringComparison.OrdinalIgnoreCase).Replace(" ", String.Empty);return name.Trim();diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.csindex 22d683e1b6..4e1bd860ba 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs@@ -251,6 +251,8 @@ namespace MediaBrowser.Server.Implementations.LiveTvif (user != null){dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, recording.GetUserDataKey()));++ dto.PlayAccess = recording.GetPlayAccess(user);}if (!string.IsNullOrEmpty(info.ProgramId))@@ -321,6 +323,8 @@ namespace MediaBrowser.Server.Implementations.LiveTvif (user != null){dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, info.GetUserDataKey()));++ dto.PlayAccess = info.GetPlayAccess(user);}var imageTag = GetImageTag(info);@@ -394,6 +398,8 @@ namespace MediaBrowser.Server.Implementations.LiveTvif (user != null){dto.UserData = _dtoService.GetUserItemDataDto(_userDataManager.GetUserData(user.Id, item.GetUserDataKey()));++ dto.PlayAccess = item.GetPlayAccess(user);}return dto;diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.csindex db0f8eeb74..55c94a7d6f 100644--- a/MediaBrowser.WebDashboard/Api/DashboardService.cs+++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs@@ -434,15 +434,13 @@ namespace MediaBrowser.WebDashboard.Api{var builder = new StringBuilder();- builder.Append("<script type=\"text/javascript\">if (navigator.userAgent.toLowerCase().indexOf('compatible; msie 7')!=-1){alert(\"Please ensure you're running at least IE10 and that compatibility mode is disabled.\");}");- builder.Append("</script>");-var versionString = "?v=" + version;var files = new[]{"scripts/all.js" + versionString,- "thirdparty/jstree1.0/jquery.jstree.min.js"+ "thirdparty/jstree1.0/jquery.jstree.min.js",+ "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"};var tags = files.Select(s => string.Format("<script src=\"{0}\"></script>", s)).ToArray();@@ -466,8 +464,9 @@ namespace MediaBrowser.WebDashboard.Api"site.js","librarybrowser.js","editorsidebar.js",-"librarymenu.js",+ "chromecast.js",+"ratingdialog.js","aboutpage.js","allusersettings.js",@@ -547,7 +546,7 @@ namespace MediaBrowser.WebDashboard.Api"supporterpage.js","episodes.js","tvgenres.js",- "tvnextup.js",+ "tvlatest.js","tvpeople.js","tvrecommended.js","tvshows.js",diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csprojindex fd05ee7b09..6627acf6df 100644--- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj+++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj@@ -424,6 +424,9 @@<Content Include="dashboard-ui\scripts\appsplayback.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>+ <Content Include="dashboard-ui\scripts\chromecast.js">+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>+ </Content><Content Include="dashboard-ui\scripts\dashboardinfo.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>@@ -1255,7 +1258,7 @@<Content Include="dashboard-ui\scripts\search.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>- <Content Include="dashboard-ui\scripts\tvnextup.js">+ <Content Include="dashboard-ui\scripts\tvlatest.js"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content><Content Include="dashboard-ui\songs.html">@@ -1437,7 +1440,7 @@<Content Include="dashboard-ui\tvgenres.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content>- <Content Include="dashboard-ui\tvnextup.html">+ <Content Include="dashboard-ui\tvlatest.html"><CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory></Content><Content Include="dashboard-ui\tvpeople.html">