More updates to the XmlTVListingsProvider
This commit is contained in:
parent
4c52fc094f
commit
767de9aa1e
|
@ -14,13 +14,20 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
|||
{
|
||||
public class XmlTvListingsProvider : IListingsProvider
|
||||
{
|
||||
private string _filePath = "C:\\Temp\\";
|
||||
private string _language = null;
|
||||
private Dictionary<string, List<string>> _categoryMappings = new Dictionary<string, List<string>>(){
|
||||
{ "Movie", new List<String>() { "Movie", "Film" } },
|
||||
{ "Sports", new List<String>() { "Sports", "Football", "Rugby", "Soccer" } },
|
||||
{ "Kids", new List<String>() { "Childrens", "Children", "Kids", "Disney" } },
|
||||
{ "News", new List<String>() { "News", "Journalism", "Documentary", "Current Affairs" } },
|
||||
//{ "Sports", new List<String>() { "Sports", "Football", "Rugby", "Soccer" } },
|
||||
//{ "Kids", new List<String>() { "Childrens", "Children", "Kids", "Disney" } },
|
||||
//{ "News", new List<String>() { "News", "Journalism", "Documentary", "Current Affairs" } },
|
||||
};
|
||||
|
||||
private Dictionary<string, string> _channelMappings = new Dictionary<string, string>(){
|
||||
{ "1", "UK_RT_2667" },
|
||||
{ "2", "UK_RT_116" },
|
||||
{ "3", "UK_RT_2118" },
|
||||
{ "4", "UK_RT_2056" },
|
||||
{ "5", "UK_RT_134" }
|
||||
};
|
||||
|
||||
public string Name
|
||||
|
@ -36,12 +43,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
|||
// TODO: Should this method be async?
|
||||
public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
|
||||
{
|
||||
var reader = new XmlTvReader(_filePath, _language, null);
|
||||
var results = reader.GetProgrammes(channelNumber, startDateUtc, endDateUtc, cancellationToken);
|
||||
var reader = new XmlTvReader(info.Path, _language, null);
|
||||
string mappedChannel = channelNumber;
|
||||
|
||||
if (_channelMappings.ContainsKey(channelNumber))
|
||||
{
|
||||
mappedChannel = _channelMappings[channelNumber];
|
||||
}
|
||||
|
||||
var results = reader.GetProgrammes(mappedChannel, startDateUtc, endDateUtc, cancellationToken);
|
||||
return Task.FromResult(results.Select(p => new ProgramInfo()
|
||||
{
|
||||
ChannelId = p.ChannelId,
|
||||
//CommunityRating = p.Rating.,
|
||||
EndDate = p.EndDate,
|
||||
EpisodeNumber = p.Episode == null ? null : p.Episode.Episode,
|
||||
EpisodeTitle = p.Episode == null ? null : p.Episode.Title,
|
||||
|
@ -50,26 +63,27 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
|||
StartDate = p.StartDate,
|
||||
Name = p.Title,
|
||||
Overview = p.Description,
|
||||
// OfficialRating = p.OfficialRating,
|
||||
ShortOverview = p.Description,
|
||||
ProductionYear = !p.CopyrightDate.HasValue ? (int?)null : p.CopyrightDate.Value.Year,
|
||||
SeasonNumber = p.Episode == null ? null : p.Episode.Series,
|
||||
IsSeries = p.IsSeries,
|
||||
IsRepeat = p.IsRepeat,
|
||||
IsPremiere = !p.PreviouslyShown.HasValue,
|
||||
IsKids = p.Categories.Any(_categoryMappings["Kids"].Contains),
|
||||
// IsPremiere = !p.PreviouslyShown.HasValue,
|
||||
IsKids = p.Categories.Any(info.KidsGenres.Contains),
|
||||
IsMovie = p.Categories.Any(_categoryMappings["Movie"].Contains),
|
||||
IsNews = p.Categories.Any(_categoryMappings["News"].Contains),
|
||||
IsSports = p.Categories.Any(_categoryMappings["Sports"].Contains),
|
||||
IsNews = p.Categories.Any(info.NewsGenres.Contains),
|
||||
IsSports = p.Categories.Any(info.SportsGenres.Contains),
|
||||
ImageUrl = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source) ? p.Icon.Source : null,
|
||||
HasImage = p.Icon != null && !String.IsNullOrEmpty(p.Icon.Source),
|
||||
OfficialRating = p.Rating != null && !String.IsNullOrEmpty(p.Rating.Value) ? p.Rating.Value : null,
|
||||
CommunityRating = p.StarRating.HasValue ? p.StarRating.Value : (float?)null
|
||||
}));
|
||||
}
|
||||
|
||||
public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken)
|
||||
{
|
||||
// Add the channel image url
|
||||
var reader = new XmlTvReader(_filePath, _language, null);
|
||||
var reader = new XmlTvReader(info.Path, _language, null);
|
||||
var results = reader.GetChannels().ToList();
|
||||
|
||||
if (channels != null && channels.Count > 0)
|
||||
|
@ -87,16 +101,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
|
|||
public async Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings)
|
||||
{
|
||||
// Check that the path or url is valid. If not, throw a file not found exception
|
||||
if (!File.Exists(_filePath))
|
||||
if (!File.Exists(info.Path))
|
||||
{
|
||||
throw new FileNotFoundException("Could not find the XmlTv file specified", _filePath);
|
||||
throw new FileNotFoundException("Could not find the XmlTv file specified:", info.Path);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location)
|
||||
{
|
||||
// In theory this should never be called because there is always only one lineup
|
||||
var reader = new XmlTvReader(_filePath, _language, null);
|
||||
var reader = new XmlTvReader(info.Path, _language, null);
|
||||
var results = reader.GetChannels();
|
||||
|
||||
// Should this method be async?
|
||||
|
|
Loading…
Reference in New Issue
Block a user