add loopback handler

This commit is contained in:
Luke Pulverenti 2016-09-03 13:16:36 -04:00
parent adeb944c61
commit 2d7c82d0dd
18 changed files with 79 additions and 144 deletions

View File

@ -70,12 +70,13 @@ namespace MediaBrowser.Api
Cultures = _localizationManager.GetCultures().ToList() Cultures = _localizationManager.GetCultures().ToList()
}; };
if (!item.IsVirtualItem && !(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName)) if (!item.IsVirtualItem && !(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName) &&
item.SourceType == SourceType.Library)
{ {
var inheritedContentType = _libraryManager.GetInheritedContentType(item); var inheritedContentType = _libraryManager.GetInheritedContentType(item);
var configuredContentType = _libraryManager.GetConfiguredContentType(item); var configuredContentType = _libraryManager.GetConfiguredContentType(item);
if (string.IsNullOrWhiteSpace(inheritedContentType) || string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || !string.IsNullOrWhiteSpace(configuredContentType)) if (string.IsNullOrWhiteSpace(inheritedContentType) || !string.IsNullOrWhiteSpace(configuredContentType))
{ {
info.ContentTypeOptions = GetContentTypeOptions(true); info.ContentTypeOptions = GetContentTypeOptions(true);
info.ContentType = configuredContentType; info.ContentType = configuredContentType;

View File

@ -89,5 +89,7 @@ namespace MediaBrowser.Controller
string GetLocalApiUrl(IPAddress ipAddress); string GetLocalApiUrl(IPAddress ipAddress);
void LaunchUrl(string url); void LaunchUrl(string url);
void EnableLoopback(string appName);
} }
} }

View File

@ -63,7 +63,6 @@
<Compile Include="Parsers\MovieXmlParser.cs" /> <Compile Include="Parsers\MovieXmlParser.cs" />
<Compile Include="Parsers\MusicVideoXmlParser.cs" /> <Compile Include="Parsers\MusicVideoXmlParser.cs" />
<Compile Include="Parsers\PlaylistXmlParser.cs" /> <Compile Include="Parsers\PlaylistXmlParser.cs" />
<Compile Include="Parsers\SeasonXmlParser.cs" />
<Compile Include="Parsers\SeriesXmlParser.cs" /> <Compile Include="Parsers\SeriesXmlParser.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\BoxSetXmlProvider.cs" /> <Compile Include="Providers\BoxSetXmlProvider.cs" />
@ -75,7 +74,6 @@
<Compile Include="Providers\MusicVideoXmlProvider.cs" /> <Compile Include="Providers\MusicVideoXmlProvider.cs" />
<Compile Include="Providers\PersonXmlProvider.cs" /> <Compile Include="Providers\PersonXmlProvider.cs" />
<Compile Include="Providers\PlaylistXmlProvider.cs" /> <Compile Include="Providers\PlaylistXmlProvider.cs" />
<Compile Include="Providers\SeasonXmlProvider.cs" />
<Compile Include="Providers\SeriesXmlProvider.cs" /> <Compile Include="Providers\SeriesXmlProvider.cs" />
<Compile Include="Providers\VideoXmlProvider.cs" /> <Compile Include="Providers\VideoXmlProvider.cs" />
<Compile Include="Savers\BoxSetXmlSaver.cs" /> <Compile Include="Savers\BoxSetXmlSaver.cs" />

View File

@ -1,48 +0,0 @@
using System.Xml;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.LocalMetadata.Parsers
{
public class SeasonXmlParser : BaseItemXmlParser<Season>
{
public SeasonXmlParser(ILogger logger, IProviderManager providerManager)
: base(logger, providerManager)
{
}
/// <summary>
/// Fetches the data from XML node.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="result">The result.</param>
protected override void FetchDataFromXmlNode(XmlReader reader, MetadataResult<Season> result)
{
var item = result.Item;
switch (reader.Name)
{
case "SeasonNumber":
{
var number = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(number))
{
int num;
if (int.TryParse(number, out num))
{
item.IndexNumber = num;
}
}
break;
}
default:
base.FetchDataFromXmlNode(reader, result);
break;
}
}
}
}

View File

@ -1,46 +0,0 @@
using System.IO;
using System.Threading;
using CommonIO;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Providers;
using MediaBrowser.LocalMetadata.Parsers;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.LocalMetadata.Providers
{
/// <summary>
/// Class SeriesProviderFromXml
/// </summary>
public class SeasonXmlProvider : BaseXmlProvider<Season>, IHasOrder
{
private readonly ILogger _logger;
private readonly IProviderManager _providerManager;
public SeasonXmlProvider(IFileSystem fileSystem, ILogger logger, IProviderManager providerManager)
: base(fileSystem)
{
_logger = logger;
_providerManager = providerManager;
}
protected override void Fetch(MetadataResult<Season> result, string path, CancellationToken cancellationToken)
{
new SeasonXmlParser(_logger, _providerManager).Fetch(result, path, cancellationToken);
}
protected override FileSystemMetadata GetXmlFile(ItemInfo info, IDirectoryService directoryService)
{
return directoryService.GetFile(Path.Combine(info.Path, "season.xml"));
}
public int Order
{
get
{
// After Xbmc
return 1;
}
}
}
}

View File

@ -818,14 +818,17 @@ namespace MediaBrowser.MediaEncoding.Subtitles
public string GetSubtitleFileCharacterSetFromLanguage(string language) public string GetSubtitleFileCharacterSetFromLanguage(string language)
{ {
// https://developer.xamarin.com/api/type/System.Text.Encoding/
switch (language.ToLower()) switch (language.ToLower())
{ {
case "hun":
return "windows-1252";
case "pol": case "pol":
case "cze": case "cze":
case "ces": case "ces":
case "slo": case "slo":
case "slk": case "slk":
case "hun":
case "slv": case "slv":
case "srp": case "srp":
case "hrv": case "hrv":

View File

@ -53,15 +53,15 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
protected override Series Resolve(ItemResolveArgs args) protected override Series Resolve(ItemResolveArgs args)
{ {
if (args.IsDirectory) if (args.IsDirectory)
{
var collectionType = args.GetCollectionType();
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
{ {
if (args.HasParent<Series>()) if (args.HasParent<Series>())
{ {
return null; return null;
} }
var collectionType = args.GetCollectionType();
if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
{
var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path); var configuredContentType = _libraryManager.GetConfiguredContentType(args.Path);
if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
{ {
@ -76,11 +76,6 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
{ {
if (string.IsNullOrWhiteSpace(collectionType)) if (string.IsNullOrWhiteSpace(collectionType))
{ {
if (args.HasParent<Series>())
{
return null;
}
if (args.Parent.IsRoot) if (args.Parent.IsRoot)
{ {
return null; return null;

View File

@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.Udp
private bool _isDisposed; private bool _isDisposed;
private readonly List<Tuple<string, byte[], Action<string, Encoding>>> _responders = new List<Tuple<string, byte[], Action<string, Encoding>>>(); private readonly List<Tuple<string, bool, Func<string, string, Encoding, Task>>> _responders = new List<Tuple<string, bool, Func<string, string, Encoding, Task>>>();
private readonly IServerApplicationHost _appHost; private readonly IServerApplicationHost _appHost;
private readonly IJsonSerializer _json; private readonly IJsonSerializer _json;
@ -49,42 +49,35 @@ namespace MediaBrowser.Server.Implementations.Udp
_appHost = appHost; _appHost = appHost;
_json = json; _json = json;
AddMessageResponder("who is EmbyServer?", RespondToV2Message); AddMessageResponder("who is EmbyServer?", true, RespondToV2Message);
AddMessageResponder("who is MediaBrowserServer_v2?", RespondToV2Message); AddMessageResponder("who is MediaBrowserServer_v2?", false, RespondToV2Message);
} }
private void AddMessageResponder(string message, Action<string, Encoding> responder) private void AddMessageResponder(string message, bool isSubstring, Func<string, string, Encoding, Task> responder)
{ {
var expectedMessageBytes = Encoding.UTF8.GetBytes(message); _responders.Add(new Tuple<string, bool, Func<string, string, Encoding, Task>>(message, isSubstring, responder));
_responders.Add(new Tuple<string, byte[], Action<string, Encoding>>(message, expectedMessageBytes, responder));
} }
/// <summary> /// <summary>
/// Raises the <see cref="E:MessageReceived" /> event. /// Raises the <see cref="E:MessageReceived" /> event.
/// </summary> /// </summary>
/// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param> /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
private void OnMessageReceived(UdpMessageReceivedEventArgs e) private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
{ {
var responder = _responders.FirstOrDefault(i => i.Item2.SequenceEqual(e.Bytes));
var encoding = Encoding.UTF8; var encoding = Encoding.UTF8;
var responder = GetResponder(e.Bytes, encoding);
if (responder == null) if (responder == null)
{
var text = Encoding.Unicode.GetString(e.Bytes);
responder = _responders.FirstOrDefault(i => string.Equals(i.Item1, text, StringComparison.OrdinalIgnoreCase));
if (responder != null)
{ {
encoding = Encoding.Unicode; encoding = Encoding.Unicode;
} responder = GetResponder(e.Bytes, encoding);
} }
if (responder != null) if (responder != null)
{ {
try try
{ {
responder.Item3(e.RemoteEndPoint, encoding); await responder.Item2.Item3(responder.Item1, e.RemoteEndPoint, encoding).ConfigureAwait(false);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -93,8 +86,34 @@ namespace MediaBrowser.Server.Implementations.Udp
} }
} }
private async void RespondToV2Message(string endpoint, Encoding encoding) private Tuple<string, Tuple<string, bool, Func<string, string, Encoding, Task>>> GetResponder(byte[] bytes, Encoding encoding)
{ {
var text = encoding.GetString(bytes);
var responder = _responders.FirstOrDefault(i =>
{
if (i.Item2)
{
return text.IndexOf(i.Item1, StringComparison.OrdinalIgnoreCase) != -1;
}
return string.Equals(i.Item1, text, StringComparison.OrdinalIgnoreCase);
});
if (responder == null)
{
return null;
}
return new Tuple<string, Tuple<string, bool, Func<string, string, Encoding, Task>>>(text, responder);
}
private async Task RespondToV2Message(string messageText, string endpoint, Encoding encoding)
{
var parts = messageText.Split('|');
if (parts.Length > 1)
{
_appHost.EnableLoopback(parts[1]);
}
var localUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false); var localUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false);
if (!string.IsNullOrEmpty(localUrl)) if (!string.IsNullOrEmpty(localUrl))
@ -106,7 +125,7 @@ namespace MediaBrowser.Server.Implementations.Udp
Name = _appHost.FriendlyName Name = _appHost.FriendlyName
}; };
await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint); await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint).ConfigureAwait(false);
} }
else else
{ {

View File

@ -278,6 +278,11 @@ namespace MediaBrowser.Server.Mono.Native
return info; return info;
} }
public void EnableLoopback(string appName)
{
}
} }
public class NullPowerManagement : IPowerManagement public class NullPowerManagement : IPowerManagement

View File

@ -1392,5 +1392,10 @@ namespace MediaBrowser.Server.Startup.Common
{ {
NativeApp.LaunchUrl(url); NativeApp.LaunchUrl(url);
} }
public void EnableLoopback(string appName)
{
NativeApp.EnableLoopback(appName);
}
} }
} }

View File

@ -107,5 +107,7 @@ namespace MediaBrowser.Server.Startup.Common
void LaunchUrl(string url); void LaunchUrl(string url);
IDbConnector GetDbConnector(); IDbConnector GetDbConnector();
void EnableLoopback(string appName);
} }
} }

View File

@ -292,15 +292,6 @@ namespace MediaBrowser.ServerApplication
ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
} }
try
{
LoopUtil.Run();
}
catch (Exception ex)
{
logManager.GetLogger("LoopUtil").ErrorException("Error in LoopUtil", ex);
}
var task = _appHost.Init(initProgress); var task = _appHost.Init(initProgress);
Task.WaitAll(task); Task.WaitAll(task);

View File

@ -192,12 +192,12 @@ namespace MediaBrowser.ServerApplication.Native
return hasChanges; return hasChanges;
} }
public static void Run() public static void Run(string appName)
{ {
var util = new LoopUtil(); var util = new LoopUtil();
util.LoadApps(); util.LoadApps();
var hasChanges = util.CreateExcemptions("Emby"); var hasChanges = util.CreateExcemptions(appName);
if (hasChanges) if (hasChanges)
{ {

View File

@ -203,5 +203,10 @@ namespace MediaBrowser.ServerApplication.Native
{ {
((Process)sender).Dispose(); ((Process)sender).Dispose();
} }
public void EnableLoopback(string appName)
{
LoopUtil.Run(appName);
}
} }
} }

View File

@ -65,6 +65,9 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Drawing", "Emby.Drawing\Emby.Drawing.csproj", "{08FFF49B-F175-4807-A2B5-73B0EBD9F716}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emby.Drawing", "Emby.Drawing\Emby.Drawing.csproj", "{08FFF49B-F175-4807-A2B5-73B0EBD9F716}"
EndProject EndProject
Global Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms Debug|Mixed Platforms = Debug|Mixed Platforms

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common.Internal</id> <id>MediaBrowser.Common.Internal</id>
<version>3.0.656</version> <version>3.0.657</version>
<title>MediaBrowser.Common.Internal</title> <title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors> <authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption.</description> <description>Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Emby 2013</copyright> <copyright>Copyright © Emby 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.656" /> <dependency id="MediaBrowser.Common" version="3.0.657" />
<dependency id="NLog" version="4.3.6" /> <dependency id="NLog" version="4.3.6" />
<dependency id="SimpleInjector" version="3.2.0" /> <dependency id="SimpleInjector" version="3.2.0" />
</dependencies> </dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Common</id> <id>MediaBrowser.Common</id>
<version>3.0.656</version> <version>3.0.657</version>
<title>MediaBrowser.Common</title> <title>MediaBrowser.Common</title>
<authors>Emby Team</authors> <authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>MediaBrowser.Server.Core</id> <id>MediaBrowser.Server.Core</id>
<version>3.0.656</version> <version>3.0.657</version>
<title>Media Browser.Server.Core</title> <title>Media Browser.Server.Core</title>
<authors>Emby Team</authors> <authors>Emby Team</authors>
<owners>ebr,Luke,scottisafool</owners> <owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Emby Server.</description> <description>Contains core components required to build plugins for Emby Server.</description>
<copyright>Copyright © Emby 2013</copyright> <copyright>Copyright © Emby 2013</copyright>
<dependencies> <dependencies>
<dependency id="MediaBrowser.Common" version="3.0.656" /> <dependency id="MediaBrowser.Common" version="3.0.657" />
<dependency id="Interfaces.IO" version="1.0.0.5" /> <dependency id="Interfaces.IO" version="1.0.0.5" />
</dependencies> </dependencies>
</metadata> </metadata>