update live tv channel ids

This commit is contained in:
Luke Pulverenti 2015-08-16 14:37:53 -04:00
parent 96e207acb3
commit 061c363495
4 changed files with 65 additions and 52 deletions

View file

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

View file

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

View file

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

View file

@ -35,6 +35,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
public Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken) public Task<IEnumerable<ChannelInfo>> GetChannels(TunerHostInfo info, CancellationToken cancellationToken)
{ {
var urlHash = info.Url.GetMD5().ToString("N");
int position = 0; int position = 0;
string line; string line;
// Read the file and display it line by line. // Read the file and display it line by line.
@ -87,7 +89,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts
switch (list[0]) switch (list[0])
{ {
case "tvg-id": case "tvg-id":
channels.Last().Id = list[1]; channels.Last().Id = urlHash + list[1];
channels.Last().Number = list[1]; channels.Last().Number = list[1];
break; break;
case "tvg-name": 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) 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 channels = await GetChannels(info, cancellationToken).ConfigureAwait(false);
var m3uchannels = channels.Cast<M3UChannel>(); var m3uchannels = channels.Cast<M3UChannel>();
var channel = m3uchannels.FirstOrDefault(c => c.Id == channelId); 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) public Task<List<MediaSourceInfo>> GetChannelStreamMediaSources(TunerHostInfo info, string channelId, CancellationToken cancellationToken)
{ {
throw new NotImplementedException(); throw new NotImplementedException();