Переглянути джерело

updated nuget for live tv

Luke Pulverenti 11 роки тому
батько
коміт
4054846a6e

+ 2 - 2
MediaBrowser.Api/Images/ImageService.cs

@@ -80,8 +80,8 @@ namespace MediaBrowser.Api.Images
         public string Id { get; set; }
     }
 
-    [Route("/LiveTV/Channels/{Id}/Images/{Type}", "GET")]
-    [Route("/LiveTV/Channels/{Id}/Images/{Type}/{Index}", "GET")]
+    [Route("/LiveTv/Channels/{Id}/Images/{Type}", "GET")]
+    [Route("/LiveTv/Channels/{Id}/Images/{Type}/{Index}", "GET")]
     [Api(Description = "Gets an item image")]
     public class GetChannelImage : ImageRequest
     {

+ 12 - 17
MediaBrowser.Api/LiveTv/LiveTvService.cs

@@ -1,4 +1,5 @@
-using MediaBrowser.Controller.LiveTv;
+using System;
+using MediaBrowser.Controller.LiveTv;
 using MediaBrowser.Model.LiveTv;
 using ServiceStack.ServiceHost;
 using System.Collections.Generic;
@@ -41,7 +42,7 @@ namespace MediaBrowser.Api.LiveTv
         [ApiMember(Name = "Id", Description = "Channel Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
         public string Id { get; set; }
     }
-    
+
     [Route("/LiveTv/Recordings", "GET")]
     [Api(Description = "Gets available live tv recordings.")]
     public class GetRecordings : IReturn<List<RecordingInfo>>
@@ -50,9 +51,9 @@ namespace MediaBrowser.Api.LiveTv
         public string ServiceName { get; set; }
     }
 
-    [Route("/LiveTv/Guide", "GET")]
+    [Route("/LiveTv/Programs", "GET")]
     [Api(Description = "Gets available live tv epgs..")]
-    public class GetGuide : IReturn<List<ChannelGuide>>
+    public class GetPrograms : IReturn<List<ProgramInfo>>
     {
         [ApiMember(Name = "ServiceName", Description = "Live tv service name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
         public string ServiceName { get; set; }
@@ -143,21 +144,15 @@ namespace MediaBrowser.Api.LiveTv
             return recordings.SelectMany(i => i);
         }
 
-        public object Get(GetGuide request)
-        {
-            var result = GetGuideAsync(request).Result;
-
-            return ToOptimizedResult(result);
-        }
-
-        private async Task<IEnumerable<ChannelGuide>> GetGuideAsync(GetGuide request)
+        public object Get(GetPrograms request)
         {
-            var service = GetServices(request.ServiceName)
-                .First();
-
-            var channels = request.ChannelIds.Split(',');
+            var result = _liveTvManager.GetPrograms(new ProgramQuery
+            {
+                ServiceName = request.ServiceName,
+                ChannelIdList = (request.ChannelIds ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray()
+            });
 
-            return await service.GetChannelGuidesAsync(channels, CancellationToken.None).ConfigureAwait(false);
+            return ToOptimizedResult(result.ToList());
         }
     }
 }

+ 7 - 0
MediaBrowser.Controller/LiveTv/ILiveTvManager.cs

@@ -40,5 +40,12 @@ namespace MediaBrowser.Controller.LiveTv
         /// <param name="id">The identifier.</param>
         /// <returns>Channel.</returns>
         Channel GetChannel(string id);
+
+        /// <summary>
+        /// Gets the programs.
+        /// </summary>
+        /// <param name="query">The query.</param>
+        /// <returns>IEnumerable{ProgramInfo}.</returns>
+        IEnumerable<ProgramInfo> GetPrograms(ProgramQuery query);
     }
 }

+ 4 - 4
MediaBrowser.Controller/LiveTv/ILiveTvService.cs

@@ -61,11 +61,11 @@ namespace MediaBrowser.Controller.LiveTv
         Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(RecordingQuery query, CancellationToken cancellationToken);
 
         /// <summary>
-        /// Gets the channel guides.
+        /// Gets the channel guide.
         /// </summary>
-        /// <param name="channelIdList">The channel identifier list.</param>
+        /// <param name="channelId">The channel identifier.</param>
         /// <param name="cancellationToken">The cancellation token.</param>
-        /// <returns>Task{IEnumerable{ChannelGuide}}.</returns>
-        Task<IEnumerable<ChannelGuide>> GetChannelGuidesAsync(IEnumerable<string> channelIdList, CancellationToken cancellationToken);
+        /// <returns>Task{IEnumerable{ProgramInfo}}.</returns>
+        Task<IEnumerable<ProgramInfo>> GetChannelGuideAsync(string channelId, CancellationToken cancellationToken);
     }
 }

+ 3 - 3
MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj

@@ -224,9 +224,6 @@
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
       <Link>IO\IZipClient.cs</Link>
     </Compile>
-    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelGuide.cs">
-      <Link>LiveTv\ChannelGuide.cs</Link>
-    </Compile>
     <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
       <Link>LiveTv\ChannelInfoDto.cs</Link>
     </Compile>
@@ -242,6 +239,9 @@
     <Compile Include="..\MediaBrowser.Model\LiveTv\ProgramInfo.cs">
       <Link>LiveTv\ProgramInfo.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\ProgramQuery.cs">
+      <Link>LiveTv\ProgramQuery.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingInfo.cs">
       <Link>LiveTv\RecordingInfo.cs</Link>
     </Compile>

+ 3 - 3
MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj

@@ -211,9 +211,6 @@
     <Compile Include="..\MediaBrowser.Model\IO\IZipClient.cs">
       <Link>IO\IZipClient.cs</Link>
     </Compile>
-    <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelGuide.cs">
-      <Link>LiveTv\ChannelGuide.cs</Link>
-    </Compile>
     <Compile Include="..\MediaBrowser.Model\LiveTv\ChannelInfoDto.cs">
       <Link>LiveTv\ChannelInfoDto.cs</Link>
     </Compile>
@@ -229,6 +226,9 @@
     <Compile Include="..\MediaBrowser.Model\LiveTv\ProgramInfo.cs">
       <Link>LiveTv\ProgramInfo.cs</Link>
     </Compile>
+    <Compile Include="..\MediaBrowser.Model\LiveTv\ProgramQuery.cs">
+      <Link>LiveTv\ProgramQuery.cs</Link>
+    </Compile>
     <Compile Include="..\MediaBrowser.Model\LiveTv\RecordingInfo.cs">
       <Link>LiveTv\RecordingInfo.cs</Link>
     </Compile>

+ 0 - 23
MediaBrowser.Model/LiveTv/ChannelGuide.cs

@@ -1,23 +0,0 @@
-using System.Collections.Generic;
-
-namespace MediaBrowser.Model.LiveTv
-{
-    public class ChannelGuide
-    {
-        /// <summary>
-        /// Gets or sets the name of the service.
-        /// </summary>
-        /// <value>The name of the service.</value>
-        public string ServiceName { get; set; }
-
-        /// <summary>
-        /// ChannelId for the EPG.
-        /// </summary>
-        public string ChannelId { get; set; }
-
-        /// <summary>
-        /// List of all the programs for a specific channel
-        /// </summary>
-        public List<ProgramInfo> Programs { get; set; } 
-    }
-}

+ 18 - 0
MediaBrowser.Model/LiveTv/ProgramInfo.cs

@@ -9,6 +9,24 @@ namespace MediaBrowser.Model.LiveTv
         /// </summary>
         public string Id { get; set; }
 
+        /// <summary>
+        /// Gets or sets the channel identifier.
+        /// </summary>
+        /// <value>The channel identifier.</value>
+        public string ChannelId { get; set; }
+
+        /// <summary>
+        /// Gets or sets the name of the service.
+        /// </summary>
+        /// <value>The name of the service.</value>
+        public string ServiceName { get; set; }
+        
+        /// <summary>
+        /// Gets or sets the external channel identifier.
+        /// </summary>
+        /// <value>The external channel identifier.</value>
+        public string ExternalChannelId { get; set; }
+        
         /// <summary>
         /// Name of the program
         /// </summary>

+ 25 - 0
MediaBrowser.Model/LiveTv/ProgramQuery.cs

@@ -0,0 +1,25 @@
+namespace MediaBrowser.Model.LiveTv
+{
+    /// <summary>
+    /// Class ProgramQuery.
+    /// </summary>
+    public class ProgramQuery
+    {
+        /// <summary>
+        /// Gets or sets the name of the service.
+        /// </summary>
+        /// <value>The name of the service.</value>
+        public string ServiceName { get; set; }
+
+        /// <summary>
+        /// Gets or sets the channel identifier.
+        /// </summary>
+        /// <value>The channel identifier.</value>
+        public string[] ChannelIdList { get; set; }
+
+        public ProgramQuery()
+        {
+            ChannelIdList = new string[] { };
+        }
+    }
+}

+ 1 - 1
MediaBrowser.Model/MediaBrowser.Model.csproj

@@ -60,10 +60,10 @@
     <Compile Include="Dto\ItemCounts.cs" />
     <Compile Include="Dto\ItemIndex.cs" />
     <Compile Include="Entities\PackageReviewInfo.cs" />
-    <Compile Include="LiveTv\ChannelGuide.cs" />
     <Compile Include="LiveTv\ChannelInfoDto.cs" />
     <Compile Include="LiveTv\ChannelQuery.cs" />
     <Compile Include="LiveTv\ProgramInfo.cs" />
+    <Compile Include="LiveTv\ProgramQuery.cs" />
     <Compile Include="LiveTv\RecordingQuery.cs" />
     <Compile Include="Providers\ImageProviderInfo.cs" />
     <Compile Include="Providers\RemoteImageInfo.cs" />

+ 44 - 3
MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs

@@ -29,6 +29,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
         private List<Channel> _channels = new List<Channel>();
 
+        private Dictionary<Guid, List<ProgramInfo>> _guide = new Dictionary<Guid, List<ProgramInfo>>();
+
         private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
 
         public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor)
@@ -79,6 +81,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
             };
         }
 
+        private ILiveTvService GetService(ChannelInfo channel)
+        {
+            return _services.FirstOrDefault(i => string.Equals(channel.ServiceName, i.Name, StringComparison.OrdinalIgnoreCase));
+        }
+
         private Guid? GetLogoImageTag(Channel info)
         {
             var path = info.PrimaryImagePath;
@@ -137,16 +144,30 @@ namespace MediaBrowser.Server.Implementations.LiveTv
             var allChannels = results.SelectMany(i => i).ToList();
 
             var list = new List<Channel>();
+            var guide = new Dictionary<Guid, List<ProgramInfo>>();
 
             var numComplete = 0;
 
-            foreach (var channel in allChannels)
+            foreach (var channelInfo in allChannels)
             {
                 try
                 {
-                    var item = await GetChannel(channel, cancellationToken).ConfigureAwait(false);
+                    var item = await GetChannel(channelInfo, cancellationToken).ConfigureAwait(false);
+
+                    var service = GetService(channelInfo);
+
+                    var programs = await service.GetChannelGuideAsync(channelInfo.Id, cancellationToken).ConfigureAwait(false);
+                    var programList = programs.ToList();
+
+                    foreach (var program in programList)
+                    {
+                        program.ExternalChannelId = channelInfo.Id;
+                        program.ChannelId = item.Id.ToString("N");
+                        program.ServiceName = service.Name;
+                    }
 
                     list.Add(item);
+                    guide[item.Id] = programList;
                 }
                 catch (OperationCanceledException)
                 {
@@ -154,7 +175,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 }
                 catch (Exception ex)
                 {
-                    _logger.ErrorException("Error getting channel information for {0}", ex, channel.Name);
+                    _logger.ErrorException("Error getting channel information for {0}", ex, channelInfo.Name);
                 }
 
                 numComplete++;
@@ -164,6 +185,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
                 progress.Report(90 * percent + 10);
             }
 
+            _guide = guide;
             _channels = list;
         }
 
@@ -218,5 +240,24 @@ namespace MediaBrowser.Server.Implementations.LiveTv
 
             return item;
         }
+
+        public IEnumerable<ProgramInfo> GetPrograms(ProgramQuery query)
+        {
+            var programs = _guide.Values.SelectMany(i => i);
+
+            if (!string.IsNullOrEmpty(query.ServiceName))
+            {
+                programs = programs.Where(i => string.Equals(i.ServiceName, query.ServiceName, StringComparison.OrdinalIgnoreCase));
+            }
+
+            if (query.ChannelIdList.Length > 0)
+            {
+                var guids = query.ChannelIdList.Select(i => new Guid(i)).ToList();
+
+                programs = programs.Where(i => guids.Contains(new Guid(i.ChannelId)));
+            } 
+            
+            return programs;
+        }
     }
 }

+ 2 - 2
Nuget/MediaBrowser.Common.Internal.nuspec

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

+ 1 - 1
Nuget/MediaBrowser.Common.nuspec

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

+ 2 - 2
Nuget/MediaBrowser.Server.Core.nuspec

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