Skip to content

Commit

Permalink
Merge pull request #2458 from MediaBrowser/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
LukePulverenti authored Feb 10, 2017
2 parents 548dbdd + 67838f5 commit 263f805
Show file tree
Hide file tree
Showing 74 changed files with 399 additions and 416 deletions.
26 changes: 25 additions & 1 deletion Emby.Common.Implementations/BaseApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ protected virtual Task RegisterResources(IProgress<double> progress)

RegisterSingleInstance(FileSystemManager);

HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, MemoryStreamFactory);
HttpClient = new HttpClientManager.HttpClientManager(ApplicationPaths, LogManager.GetLogger("HttpClient"), FileSystemManager, MemoryStreamFactory, GetDefaultUserAgent);
RegisterSingleInstance(HttpClient);

RegisterSingleInstance(NetworkManager);
Expand All @@ -549,6 +549,30 @@ protected virtual Task RegisterResources(IProgress<double> progress)
return Task.FromResult(true);
}

private string GetDefaultUserAgent()
{
var name = FormatAttribute(Name);

return name + "/" + ApplicationVersion.ToString();
}

private string FormatAttribute(string str)
{
var arr = str.ToCharArray();

arr = Array.FindAll<char>(arr, (c => (char.IsLetterOrDigit(c)
|| char.IsWhiteSpace(c))));

var result = new string(arr);

if (string.IsNullOrWhiteSpace(result))
{
result = "Emby";
}

return result;
}

/// <summary>
/// Gets a list of types within an assembly
/// This will handle situations that would normally throw an exception - such as a type within the assembly that depends on some other non-existant reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EnvironmentInfo : IEnvironmentInfo
public MediaBrowser.Model.System.Architecture? CustomArchitecture { get; set; }
public MediaBrowser.Model.System.OperatingSystem? CustomOperatingSystem { get; set; }

public MediaBrowser.Model.System.OperatingSystem OperatingSystem
public virtual MediaBrowser.Model.System.OperatingSystem OperatingSystem
{
get
{
Expand Down
53 changes: 35 additions & 18 deletions Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Threading.Tasks;
using Emby.Common.Implementations.HttpClientManager;
using MediaBrowser.Model.IO;
using MediaBrowser.Common;

namespace Emby.Common.Implementations.HttpClientManager
{
Expand All @@ -43,17 +44,12 @@ public class HttpClientManager : IHttpClient

private readonly IFileSystem _fileSystem;
private readonly IMemoryStreamFactory _memoryStreamProvider;
private readonly Func<string> _defaultUserAgentFn;

/// <summary>
/// Initializes a new instance of the <see cref="HttpClientManager" /> class.
/// </summary>
/// <param name="appPaths">The app paths.</param>
/// <param name="logger">The logger.</param>
/// <param name="fileSystem">The file system.</param>
/// <exception cref="System.ArgumentNullException">appPaths
/// or
/// logger</exception>
public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem, IMemoryStreamFactory memoryStreamProvider)
public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem fileSystem, IMemoryStreamFactory memoryStreamProvider, Func<string> defaultUserAgentFn)
{
if (appPaths == null)
{
Expand All @@ -68,6 +64,7 @@ public HttpClientManager(IApplicationPaths appPaths, ILogger logger, IFileSystem
_fileSystem = fileSystem;
_memoryStreamProvider = memoryStreamProvider;
_appPaths = appPaths;
_defaultUserAgentFn = defaultUserAgentFn;

#if NET46
// http://stackoverflow.com/questions/566437/http-post-returns-the-error-417-expectation-failed-c
Expand Down Expand Up @@ -257,6 +254,8 @@ private CredentialCache GetCredential(string url, string username, string passwo

private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions options)
{
var hasUserAgent = false;

foreach (var header in options.RequestHeaders.ToList())
{
if (string.Equals(header.Key, "Accept", StringComparison.OrdinalIgnoreCase))
Expand All @@ -265,11 +264,8 @@ private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions option
}
else if (string.Equals(header.Key, "User-Agent", StringComparison.OrdinalIgnoreCase))
{
#if NET46
request.UserAgent = header.Value;
#elif NETSTANDARD1_6
request.Headers["User-Agent"] = header.Value;
#endif
SetUserAgent(request, header.Value);
hasUserAgent = true;
}
else
{
Expand All @@ -280,6 +276,20 @@ private void AddRequestHeaders(HttpWebRequest request, HttpRequestOptions option
#endif
}
}

if (!hasUserAgent && options.EnableDefaultUserAgent)
{
SetUserAgent(request, _defaultUserAgentFn());
}
}

private void SetUserAgent(HttpWebRequest request, string userAgent)
{
#if NET46
request.UserAgent = userAgent;
#elif NETSTANDARD1_6
request.Headers["User-Agent"] = userAgent;
#endif
}

/// <summary>
Expand Down Expand Up @@ -448,15 +458,22 @@ private async Task<HttpResponseInfo> SendAsyncInternal(HttpRequestOptions option
!string.IsNullOrEmpty(options.RequestContent) ||
string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase))
{
var bytes = options.RequestContentBytes ??
Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);
try
{
var bytes = options.RequestContentBytes ??
Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty);

httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";
httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded";

#if NET46
httpWebRequest.ContentLength = bytes.Length;
#endif
(await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length);
httpWebRequest.ContentLength = bytes.Length;
#endif
(await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false)).Write(bytes, 0, bytes.Length);
}
catch (Exception ex)
{
throw new HttpException(ex.Message) { IsTimedOut = true };
}
}

if (options.ResourcePool != null)
Expand Down
3 changes: 1 addition & 2 deletions Emby.Dlna/Profiles/WdtvLiveProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ public WdtvLiveProfile()

new DirectPlayProfile
{
Container = "flac",
AudioCodec = "flac",
Container = "flac,ac3",
Type = DlnaProfileType.Audio
},

Expand Down
2 changes: 1 addition & 1 deletion Emby.Dlna/Profiles/Xml/WDTV Live.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<DirectPlayProfile container="asf" audioCodec="mp2,ac3" videoCodec="mpeg2video" type="Video" />
<DirectPlayProfile container="mp3" audioCodec="mp2,mp3" type="Audio" />
<DirectPlayProfile container="mp4" audioCodec="mp4" type="Audio" />
<DirectPlayProfile container="flac" audioCodec="flac" type="Audio" />
<DirectPlayProfile container="flac,ac3" type="Audio" />
<DirectPlayProfile container="asf" audioCodec="wmav2,wmapro,wmavoice" type="Audio" />
<DirectPlayProfile container="ogg" audioCodec="vorbis" type="Audio" />
<DirectPlayProfile container="jpeg,png,gif,bmp,tiff" type="Photo" />
Expand Down
46 changes: 9 additions & 37 deletions Emby.Dlna/Ssdp/DeviceDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@

namespace Emby.Dlna.Ssdp
{
public class DeviceDiscovery : IDeviceDiscovery, IDisposable
public class DeviceDiscovery : IDeviceDiscovery
{
private bool _disposed;

private readonly ILogger _logger;
private readonly IServerConfigurationManager _config;
private readonly CancellationTokenSource _tokenSource;

public event EventHandler<GenericEventArgs<UpnpDeviceInfo>> DeviceDiscovered;
public event EventHandler<GenericEventArgs<UpnpDeviceInfo>> DeviceLeft;
Expand All @@ -37,8 +36,6 @@ public class DeviceDiscovery : IDeviceDiscovery, IDisposable

public DeviceDiscovery(ILogger logger, IServerConfigurationManager config, ISocketFactory socketFactory, ITimerFactory timerFactory)
{
_tokenSource = new CancellationTokenSource();

_logger = logger;
_config = config;
_socketFactory = socketFactory;
Expand All @@ -59,39 +56,10 @@ public void Start(ISsdpCommunicationsServer communicationsServer)
_deviceLocator.DeviceAvailable += deviceLocator_DeviceAvailable;
_deviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable;

// Perform a search so we don't have to wait for devices to broadcast notifications
// again to get any results right away (notifications are broadcast periodically).
StartAsyncSearch();
}

private void StartAsyncSearch()
{
Task.Factory.StartNew(async (o) =>
{
while (!_tokenSource.IsCancellationRequested)
{
try
{
// Enable listening for notifications (optional)
_deviceLocator.StartListeningForNotifications();

await _deviceLocator.SearchAsync(_tokenSource.Token).ConfigureAwait(false);
var dueTime = TimeSpan.FromSeconds(5);
var interval = TimeSpan.FromSeconds(_config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds);

var delay = _config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds * 1000;

await Task.Delay(delay, _tokenSource.Token).ConfigureAwait(false);
}
catch (OperationCanceledException)
{

}
catch (Exception ex)
{
_logger.ErrorException("Error searching for devices", ex);
}
}

}, CancellationToken.None, TaskCreationOptions.LongRunning);
_deviceLocator.RestartBroadcastTimer(dueTime, interval);
}

// Process each found device in the event handler
Expand Down Expand Up @@ -141,7 +109,11 @@ public void Dispose()
if (!_disposed)
{
_disposed = true;
_tokenSource.Cancel();
if (_deviceLocator != null)
{
_deviceLocator.Dispose();
_deviceLocator = null;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@
<Project>{4f26d5d8-a7b0-42b3-ba42-7cb7d245934e}</Project>
<Name>SocketHttpListener.Portable</Name>
</ProjectReference>
<Reference Include="Emby.XmlTv, Version=1.0.6241.4924, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Emby.XmlTv.1.0.5\lib\portable-net45+win8\Emby.XmlTv.dll</HintPath>
<Reference Include="Emby.XmlTv, Version=1.0.6249.32870, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Emby.XmlTv.1.0.6\lib\portable-net45+win8\Emby.XmlTv.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MediaBrowser.Naming, Version=1.0.6201.24431, Culture=neutral, processorArchitecture=MSIL">
Expand Down
12 changes: 12 additions & 0 deletions Emby.Server.Implementations/Library/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,18 @@ public string GetPathAfterNetworkSubstitution(string path, BaseItem ownerItem)
}
}

foreach (var map in ConfigurationManager.Configuration.PathSubstitutions)
{
if (!string.IsNullOrWhiteSpace(map.From))
{
var substitutionResult = SubstitutePathInternal(path, map.From, map.To);
if (substitutionResult.Item2)
{
return substitutionResult.Item1;
}
}
}

return path;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,20 @@ protected override MusicArtist Resolve(ItemResolveArgs args)
return new MusicArtist();
}

return null;
//if (_config.Configuration.EnableSimpleArtistDetection)
//{
// return null;
//}
if (_config.Configuration.EnableSimpleArtistDetection)
{
return null;
}

//// Avoid mis-identifying top folders
//if (args.Parent.IsRoot) return null;
// Avoid mis-identifying top folders
if (args.Parent.IsRoot) return null;

//var directoryService = args.DirectoryService;
var directoryService = args.DirectoryService;

//var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);
var albumResolver = new MusicAlbumResolver(_logger, _fileSystem, _libraryManager);

//// If we contain an album assume we are an artist folder
//return args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null;
// If we contain an album assume we are an artist folder
return args.FileSystemChildren.Where(i => i.IsDirectory).Any(i => albumResolver.IsMusicAlbum(i.FullName, directoryService, args.GetLibraryOptions())) ? new MusicArtist() : null;
}

}
Expand Down
28 changes: 15 additions & 13 deletions Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ private async Task AddMetadata(IListingsProvider provider, ListingsProviderInfo
{
tunerChannel.Name = epgChannel.Name;
}
if (!string.IsNullOrWhiteSpace(epgChannel.ImageUrl))
{
tunerChannel.ImageUrl = epgChannel.ImageUrl;
tunerChannel.HasImage = true;
}
}
}
}
Expand Down Expand Up @@ -469,16 +474,20 @@ private ChannelInfo GetEpgChannelFromTunerChannel(ListingsProviderInfo info, Cha

public ChannelInfo GetEpgChannelFromTunerChannel(List<NameValuePair> mappings, ChannelInfo tunerChannel, List<ChannelInfo> epgChannels)
{
if (!string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId))
var tunerChannelId = string.IsNullOrWhiteSpace(tunerChannel.TunerChannelId)
? tunerChannel.Id
: tunerChannel.TunerChannelId;

if (!string.IsNullOrWhiteSpace(tunerChannelId))
{
var tunerChannelId = GetMappedChannel(tunerChannel.TunerChannelId, mappings);
var mappedTunerChannelId = GetMappedChannel(tunerChannelId, mappings);

if (string.IsNullOrWhiteSpace(tunerChannelId))
if (string.IsNullOrWhiteSpace(mappedTunerChannelId))
{
tunerChannelId = tunerChannel.TunerChannelId;
mappedTunerChannelId = tunerChannelId;
}

var channel = epgChannels.FirstOrDefault(i => string.Equals(tunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase));
var channel = epgChannels.FirstOrDefault(i => string.Equals(mappedTunerChannelId, i.Id, StringComparison.OrdinalIgnoreCase));

if (channel != null)
{
Expand Down Expand Up @@ -1163,7 +1172,7 @@ public async Task<List<MediaSourceInfo>> GetRecordingStreamMediaSources(string r
};

var isAudio = false;
await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, cancellationToken).ConfigureAwait(false);
await new LiveStreamHelper(_mediaEncoder, _logger).AddMediaInfoWithProbe(stream, isAudio, false, cancellationToken).ConfigureAwait(false);

return new List<MediaSourceInfo>
{
Expand Down Expand Up @@ -2092,13 +2101,6 @@ private void SaveVideoNfo(TimerInfo timer, string recordingPath, BaseItem item,
writer.WriteElementString("credits", person);
}

var rt = item.GetProviderId(MetadataProviders.RottenTomatoes);

if (!string.IsNullOrEmpty(rt))
{
writer.WriteElementString("rottentomatoesid", rt);
}

var tmdbCollection = item.GetProviderId(MetadataProviders.TmdbCollection);

if (!string.IsNullOrEmpty(tmdbCollection))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ private string GetCommandLineArgs(MediaSourceInfo mediaSource, string inputTempF
var durationParam = " -t " + _mediaEncoder.GetTimeParameter(duration.Ticks);
var inputModifiers = "-fflags +genpts -async 1 -vsync -1";
var mapArgs = string.Equals(OutputFormat, "mkv", StringComparison.OrdinalIgnoreCase) ? "-map 0" : "-sn";
// temporary
mapArgs = "-sn";
var commandLineArgs = "-i \"{0}\"{4} " + mapArgs + " {2} -map_metadata -1 -threads 0 {3} -y \"{1}\"";

Expand Down
Loading

0 comments on commit 263f805

Please sign in to comment.