Browse Source

update live tv channel ids

Luke Pulverenti 10 năm trước cách đây
mục cha
commit
061c363495

+ 28 - 35
MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs

@@ -117,14 +117,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
                 try
                 {
                     var channels = await hostInstance.Item1.GetChannels(hostInstance.Item2, cancellationToken).ConfigureAwait(false);
-                    var newChannels = channels.ToList();
 
-                    foreach (var channel in newChannels)
-                    {
-                        channel.Id = hostInstance.Item1.Type.GetMD5().ToString("N") + "-" + channel.Id;
-                    }
-
-                    list.AddRange(newChannels);
+                    list.AddRange(channels);
                 }
                 catch (Exception ex)
                 {
@@ -310,18 +304,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
             return Task.FromResult((IEnumerable<SeriesTimerInfo>)_seriesTimerProvider.GetAll());
         }
 
-        private string GetOriginalChannelId(string channelId)
-        {
-            var parts = channelId.Split('-');
-
-            return string.Join("-", parts.Skip(1).ToArray());
-        }
-
         public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(string channelId, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
         {
             foreach (var provider in GetListingProviders())
             {
-                var programs = await provider.Item1.GetProgramsAsync(provider.Item2, GetOriginalChannelId(channelId), startDateUtc, endDateUtc, cancellationToken)
+                var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channelId, startDateUtc, endDateUtc, cancellationToken)
                         .ConfigureAwait(false);
                 var list = programs.ToList();
 
@@ -364,15 +351,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
         {
             _logger.Info("Streaming Channel " + channelId);
 
-            var configurationId = channelId.Split('-')[0];
-
             foreach (var hostInstance in GetTunerHosts())
             {
-                if (!string.Equals(configurationId, hostInstance.Item1.Type.GetMD5().ToString("N"), StringComparison.OrdinalIgnoreCase))
-                {
-                    continue;
-                }
-
                 if (!string.IsNullOrWhiteSpace(streamId))
                 {
                     var originalStreamId = string.Join("-", streamId.Split('-').Skip(1).ToArray());
@@ -386,16 +366,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
                 MediaSourceInfo mediaSourceInfo = null;
                 try
                 {
-                    mediaSourceInfo = await hostInstance.Item1.GetChannelStream(hostInstance.Item2, GetOriginalChannelId(channelId), streamId, cancellationToken).ConfigureAwait(false);
+                    mediaSourceInfo = await hostInstance.Item1.GetChannelStream(hostInstance.Item2, channelId, streamId, cancellationToken).ConfigureAwait(false);
                 }
-                catch (ApplicationException e)
+                catch (Exception e)
                 {
-                    _logger.Info(e.Message);
-                    continue;
+                    _logger.ErrorException("Error getting channel stream", e);
                 }
 
-                mediaSourceInfo.Id = Guid.NewGuid().ToString("N");
-                return mediaSourceInfo;
+                if (mediaSourceInfo != null)
+                {
+                    mediaSourceInfo.Id = Guid.NewGuid().ToString("N");
+                    return mediaSourceInfo;
+                }
             }
 
             throw new ApplicationException("Tuner not found.");
@@ -403,20 +385,25 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
 
         public async Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(string channelId, CancellationToken cancellationToken)
         {
-            var configurationId = channelId.Split('-')[0];
-
             foreach (var hostInstance in GetTunerHosts())
             {
-                if (string.Equals(configurationId, hostInstance.Item1.Type.GetMD5().ToString("N"), StringComparison.OrdinalIgnoreCase))
+                try
                 {
-                    var sources = await hostInstance.Item1.GetChannelStreamMediaSources(hostInstance.Item2, GetOriginalChannelId(channelId), cancellationToken).ConfigureAwait(false);
+                    var sources = await hostInstance.Item1.GetChannelStreamMediaSources(hostInstance.Item2, channelId, cancellationToken).ConfigureAwait(false);
 
                     foreach (var source in sources)
                     {
                         source.Id = hostInstance.Item2.Id + "-" + source.Id;
                     }
 
-                    return sources;
+                    if (sources.Count > 0)
+                    {
+                        return sources;
+                    }
+                }
+                catch (NotImplementedException)
+                {
+                    
                 }
             }
 
@@ -636,7 +623,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
 
             var recordingShowIds = currentRecordings.Select(i => i.ShowId).ToList();
 
-            allPrograms = allPrograms.Where(epg => !recordingShowIds.Contains(epg.ShowId, StringComparer.OrdinalIgnoreCase)); 
+            allPrograms = allPrograms.Where(epg => !recordingShowIds.Contains(epg.ShowId, StringComparer.OrdinalIgnoreCase));
 
             return allPrograms.Select(i => RecordingHelper.CreateTimer(i, seriesTimer));
         }
@@ -650,7 +637,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
 
             if (seriesTimer.RecordNewOnly)
             {
-                allPrograms = allPrograms.Where(epg => !epg.IsRepeat); 
+                allPrograms = allPrograms.Where(epg => !epg.IsRepeat);
             }
 
             if (!seriesTimer.RecordAnyChannel)
@@ -660,6 +647,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
 
             allPrograms = allPrograms.Where(i => seriesTimer.Days.Contains(i.StartDate.DayOfWeek));
 
+            if (string.IsNullOrWhiteSpace(seriesTimer.SeriesId))
+            {
+                _logger.Error("seriesTimer.SeriesId is null. Cannot find programs for series");
+                return new List<ProgramInfo>();
+            }
+
             return allPrograms.Where(i => string.Equals(i.SeriesId, seriesTimer.SeriesId, StringComparison.OrdinalIgnoreCase));
         }
 

+ 12 - 13
MediaBrowser.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs

@@ -307,6 +307,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
                 imageLink = details.images;
             }
 
+            var showType = details.showType ?? string.Empty;
+
             var info = new ProgramInfo
             {
                 ChannelId = channel,
@@ -315,32 +317,29 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
                 StartDate = startAt,
                 EndDate = endAt,
                 Name = details.titles[0].title120 ?? "Unkown",
-                OfficialRating = "0",
+                OfficialRating = null,
                 CommunityRating = null,
                 EpisodeTitle = episodeTitle,
                 Audio = audioType,
                 IsHD = hdtv,
                 IsRepeat = repeat,
-                IsSeries =
-                    ((details.showType ?? "No ShowType") == "Series") ||
-                    (details.showType ?? "No ShowType") == "Miniseries",
+                IsSeries = showType.IndexOf("series", StringComparison.OrdinalIgnoreCase) != -1,
                 ImageUrl = imageLink,
                 HasImage = details.hasImageArtwork,
                 IsNews = false,
                 IsKids = false,
-                IsSports =
-                    ((details.showType ?? "No ShowType") == "Sports non-event") ||
-                    (details.showType ?? "No ShowType") == "Sports event",
+                IsSports = showType.IndexOf("sports", StringComparison.OrdinalIgnoreCase) != -1,
                 IsLive = false,
-                IsMovie =
-                    (details.showType ?? "No ShowType") == "Feature Film" ||
-                    (details.showType ?? "No ShowType") == "TV Movie" ||
-                    (details.showType ?? "No ShowType") == "Short Film",
+                IsMovie = showType.IndexOf("movie", StringComparison.OrdinalIgnoreCase) != -1 || showType.IndexOf("film", StringComparison.OrdinalIgnoreCase) != -1,
                 IsPremiere = false,
-                ShowId = programInfo.programID,
-                SeriesId = programInfo.programID.Substring(0, 10)
+                ShowId = programInfo.programID
             };
 
+            if (info.IsSeries)
+            {
+                info.SeriesId = programInfo.programID.Substring(0, 10);
+            }
+
             if (!string.IsNullOrWhiteSpace(details.originalAirDate))
             {
                 info.OriginalAirDate = DateTime.Parse(details.originalAirDate);

+ 14 - 2
MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs

@@ -47,6 +47,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
             get { return "hdhomerun"; }
         }
 
+        private const string ChannelIdPrefix = "hdhr_";
+
         public async Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
         {
             var options = new HttpRequestOptions
@@ -64,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
                     {
                         Name = i.GuideName,
                         Number = i.GuideNumber.ToString(CultureInfo.InvariantCulture),
-                        Id = i.GuideNumber.ToString(CultureInfo.InvariantCulture),
+                        Id = ChannelIdPrefix + i.GuideNumber.ToString(CultureInfo.InvariantCulture),
                         IsFavorite = i.Favorite
 
                     });
@@ -320,6 +322,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
         {
             var list = new List<MediaSourceInfo>();
 
+            if (!channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase))
+            {
+                return list;
+            }
+
             list.Add(GetMediaSource(info, channelId, "native"));
 
             try
@@ -339,7 +346,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
             }
             catch (Exception ex)
             {
-                
+
             }
 
             return list;
@@ -347,6 +354,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun
 
         public async Task<MediaSourceInfo> GetChannelStream(TunerHostInfo info, string channelId, string streamId, CancellationToken cancellationToken)
         {
+            if (!channelId.StartsWith(ChannelIdPrefix, StringComparison.OrdinalIgnoreCase))
+            {
+                return null;
+            }
+
             return GetMediaSource(info, channelId, streamId);
         }
 

+ 11 - 2
MediaBrowser.Server.Implementations/LiveTv/TunerHosts/M3UTunerHost.cs

@@ -35,6 +35,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
 
         public Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
         {
+            var urlHash = info.Url.GetMD5().ToString("N");
+            
             int position = 0;
             string line;
             // Read the file and display it line by line.
@@ -87,7 +89,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
                             switch (list[0])
                             {
                                 case "tvg-id":
-                                    channels.Last().Id = list[1];
+                                    channels.Last().Id = urlHash + list[1];
                                     channels.Last().Number = list[1];
                                     break;
                                 case "tvg-name":
@@ -126,6 +128,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
 
         public async Task<MediaSourceInfo> GetChannelStream(TunerHostInfo info, string channelId, string streamId, CancellationToken cancellationToken)
         {
+            var urlHash = info.Url.GetMD5().ToString("N");
+            if (!channelId.StartsWith(urlHash, StringComparison.OrdinalIgnoreCase))
+            {
+                return null;
+            }
+
+            channelId = channelId.Substring(urlHash.Length);
+
             var channels = await GetChannels(info, cancellationToken).ConfigureAwait(false);
             var m3uchannels = channels.Cast<M3UChannel>();
             var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId);
@@ -191,7 +201,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
             }
         }
 
-
         public Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(TunerHostInfo info, string channelId, CancellationToken cancellationToken)
         {
             throw new NotImplementedException();