using MediaBrowser.Controller.Dlna;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace MediaBrowser.Dlna.PlayTo
{
class StreamHelper
{
///
/// Gets the audio URL.
///
/// The device properties.
/// The item.
/// The streams.
/// The server address.
/// System.String.
internal static string GetAudioUrl(DeviceInfo deviceProperties, PlaylistItem item, List streams, string serverAddress)
{
var dlnaCommand = BuildDlnaUrl(item.MediaSourceId, deviceProperties.UUID, !item.Transcode, null, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, null, 128000, item.StartPositionTicks, item.TranscodingSettings);
return string.Format("{0}/audio/{1}/stream{2}?{3}", serverAddress, item.ItemId, "." + item.Container.TrimStart('.'), dlnaCommand);
}
///
/// Gets the video URL.
///
/// The device properties.
/// The item.
/// The streams.
/// The server address.
/// The url to send to the device
internal static string GetVideoUrl(DeviceInfo deviceProperties, PlaylistItem item, List streams, string serverAddress)
{
var dlnaCommand = BuildDlnaUrl(item.MediaSourceId, deviceProperties.UUID, !item.Transcode, item.VideoCodec, item.AudioCodec, item.AudioStreamIndex, item.SubtitleStreamIndex, 1500000, 128000, item.StartPositionTicks, item.TranscodingSettings);
return string.Format("{0}/Videos/{1}/stream{2}?{3}", serverAddress, item.ItemId, item.Container, dlnaCommand);
}
///
/// Builds the dlna URL.
///
private static string BuildDlnaUrl(string mediaSourceId, string deviceID, bool isStatic, string videoCodec, string audioCodec, int? audiostreamIndex, int? subtitleIndex, int? videoBitrate, int? audioBitrate, long? startPositionTicks, List settings)
{
var profile = settings.Where(i => i.Name == TranscodingSettingType.VideoProfile).Select(i => i.Value).FirstOrDefault();
var videoLevel = settings.Where(i => i.Name == TranscodingSettingType.VideoLevel).Select(i => i.Value).FirstOrDefault();
var maxAudioChannels = settings.Where(i => i.Name == TranscodingSettingType.MaxAudioChannels).Select(i => i.Value).FirstOrDefault();
var usCulture = new CultureInfo("en-US");
var list = new List
{
deviceID ?? string.Empty,
mediaSourceId ?? string.Empty,
isStatic.ToString().ToLower(),
videoCodec ?? string.Empty,
audioCodec ?? string.Empty,
audiostreamIndex.HasValue ? audiostreamIndex.Value.ToString(usCulture) : string.Empty,
subtitleIndex.HasValue ? subtitleIndex.Value.ToString(usCulture) : string.Empty,
videoBitrate.HasValue ? videoBitrate.Value.ToString(usCulture) : string.Empty,
audioBitrate.HasValue ? audioBitrate.Value.ToString(usCulture) : string.Empty,
maxAudioChannels ?? string.Empty,
startPositionTicks.HasValue ? startPositionTicks.Value.ToString(usCulture) : string.Empty,
profile ?? string.Empty,
videoLevel ?? string.Empty
};
return string.Format("Params={0}", string.Join(";", list.ToArray()));
}
}
}