The Free Software Media System - Server Backend & API
update sat/ip
Luke Pulverenti1381447bda79
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.csindex 87c2e8394b..d40f2a141d 100644--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs@@ -2450,7 +2450,7 @@ namespace MediaBrowser.Server.Implementations.LiveTvpublic List<NameValuePair> GetSatIniMappings(){- var names = GetType().Assembly.GetManifestResourceNames().Where(i => i.IndexOf("SatIp.ini.satellite", StringComparison.OrdinalIgnoreCase) != -1).ToList();+ var names = GetType().Assembly.GetManifestResourceNames().Where(i => i.IndexOf("SatIp.ini", StringComparison.OrdinalIgnoreCase) != -1).ToList();return names.Select(GetSatIniMappings).Where(i => i != null).DistinctBy(i => i.Value.Split('|')[0]).ToList();}@@ -2472,20 +2472,21 @@ namespace MediaBrowser.Server.Implementations.LiveTvreturn null;}+ var srch = "SatIp.ini.";+ var filename = Path.GetFileName(resource);+return new NameValuePair{Name = satType1 + " " + satType2,- Value = satType2 + "|" + Path.GetFileName(resource)+ Value = satType2 + "|" + filename.Substring(filename.IndexOf(srch) + srch.Length)};}}}- public async Task<List<ChannelInfo>> GetSatChannelScanResult(TunerHostInfo info, CancellationToken cancellationToken)+ public Task<List<ChannelInfo>> GetSatChannelScanResult(TunerHostInfo info, CancellationToken cancellationToken){- var result = await new TunerHosts.SatIp.ChannelScan().Scan(info, cancellationToken).ConfigureAwait(false);-- return result.Select(i => new ChannelInfo()).ToList();+ return new TunerHosts.SatIp.ChannelScan(_logger).Scan(info, cancellationToken);}}}\ No newline at end of filediff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/ChannelScan.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/ChannelScan.csindex 2277f8f630..20737df50d 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/ChannelScan.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/ChannelScan.cs@@ -1,15 +1,104 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;+using System.Globalization;+using System.IO;+using System.Linq;using System.Threading;using System.Threading.Tasks;+using IniParser;+using IniParser.Model;+using MediaBrowser.Controller.LiveTv;using MediaBrowser.Model.LiveTv;+using MediaBrowser.Model.Logging;+using MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp;namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp{public class ChannelScan{- public async Task<List<SatChannel>> Scan(TunerHostInfo info, CancellationToken cancellationToken)+ private readonly ILogger _logger;++ public ChannelScan(ILogger logger)+ {+ _logger = logger;+ }++ public async Task<List<ChannelInfo>> Scan(TunerHostInfo info, CancellationToken cancellationToken)+ {+ var timedToken = new CancellationTokenSource(TimeSpan.FromSeconds(30));+ var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(timedToken.Token, cancellationToken);++ using (var rtspSession = new RtspSession(info.Url, _logger))+ {+ var ini = info.SourceA.Split('|')[1];+ var resource = GetType().Assembly.GetManifestResourceNames().FirstOrDefault(i => i.EndsWith(ini, StringComparison.OrdinalIgnoreCase));++ _logger.Info("Opening ini file {0}", resource);+ using (var stream = GetType().Assembly.GetManifestResourceStream(resource))+ {+ using (var reader = new StreamReader(stream))+ {+ var parser = new StreamIniDataParser();+ var data = parser.ReadData(reader);++ var count = GetInt(data, "DVB", "0", 0);++ var index = 1;+ var source = "1";++ while (!linkedToken.IsCancellationRequested)+ {+ float percent = count == 0 ? 0 : (float)(index) / count;+ percent = Math.Max(percent * 100, 100);++ //SetControlPropertyThreadSafe(pgbSearchResult, "Value", (int)percent);+ var strArray = data["DVB"][index.ToString(CultureInfo.InvariantCulture)].Split(',');++ string tuning;+ if (strArray[4] == "S2")+ {+ tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs2&mtype={5}&plts=on&ro=0.35&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2].ToLower(), strArray[3], strArray[5].ToLower());+ }+ else+ {+ tuning = string.Format("src={0}&freq={1}&pol={2}&sr={3}&fec={4}&msys=dvbs&mtype={5}&pids=0,16,17,18,20", source, strArray[0], strArray[1].ToLower(), strArray[2], strArray[3], strArray[5].ToLower());+ }++ if (string.IsNullOrEmpty(rtspSession.RtspSessionId))+ {+ rtspSession.Setup(tuning, "unicast");++ rtspSession.Play(string.Empty);+ }+ else+ {+ rtspSession.Play(tuning);+ }++ int signallevel;+ int signalQuality;+ rtspSession.Describe(out signallevel, out signalQuality);++ await Task.Delay(500).ConfigureAwait(false);+ index++;+ }+ }+ }+ }++ return new List<ChannelInfo>();+ }++ private int GetInt(IniData data, string s1, string s2, int defaultValue){- return new List<SatChannel>();+ var value = data[s1][s2];+ int numericValue;+ if (int.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out numericValue))+ {+ return numericValue;+ }++ return defaultValue;}}diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspMethod.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspMethod.csindex fae7c4bfc7..5f286f1db5 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspMethod.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspMethod.cs@@ -17,7 +17,7 @@using System.Collections.Generic;-namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIp+namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp{/// <summary>/// Standard RTSP request methods.diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspRequest.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspRequest.csindex d8462b2238..600eda02da 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspRequest.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspRequest.cs@@ -18,8 +18,7 @@using System.Collections.Generic;using System.Text;--namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIp+namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp{/// <summary>/// A simple class that can be used to serialise RTSP requests.diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspResponse.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspResponse.csindex 0bf80012d2..97290623b9 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspResponse.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspResponse.cs@@ -21,8 +21,7 @@ using System.Linq;using System.Text;using System.Text.RegularExpressions;--namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIp+namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp{/// <summary>/// A simple class that can be used to deserialise RTSP responses.diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.csindex e76fb71757..71b3f8a184 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspSession.cs@@ -25,7 +25,7 @@ using System.Net.Sockets;using System.Text.RegularExpressions;using MediaBrowser.Model.Logging;-namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIp+namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp{public class RtspSession : IDisposable{@@ -58,15 +58,22 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIpprivate Socket _rtspSocket;private int _rtspSequenceNum = 1;private bool _disposed = false;- private ILogger _logger;+ private readonly ILogger _logger;#endregion#region Constructorpublic RtspSession(string address, ILogger logger){+ if (string.IsNullOrWhiteSpace(address))+ {+ throw new ArgumentNullException("address");+ }+_address = address;_logger = logger;++ _logger.Info("Creating RtspSession with url {0}", address);}~RtspSession(){diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspStatusCode.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspStatusCode.csindex 8786314edb..6d6d50623b 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspStatusCode.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/Rtsp/RtspStatusCode.cs@@ -17,7 +17,7 @@using System.ComponentModel;-namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.SatIp+namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIp.Rtsp{/// <summary>/// Standard RTSP status codes.diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.csindex 46a2a8524b..ffd85fd18a 100644--- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs+++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/SatIp/SatIpHost.cs@@ -40,7 +40,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.SatIpreturn await new M3uParser(Logger, _fileSystem, _httpClient).Parse(tuner.M3UUrl, ChannelIdPrefix, tuner.Id, cancellationToken).ConfigureAwait(false);}- return new List<ChannelInfo>();+ var channels = await new ChannelScan(Logger).Scan(tuner, cancellationToken).ConfigureAwait(false);+ return channels;}public static string DeviceType