update schedules direct mapping

This commit is contained in:
Luke Pulverenti 2015-10-10 20:39:30 -04:00
parent 5144e0264c
commit cc213128e2
9 changed files with 98 additions and 37 deletions

View File

@ -314,7 +314,7 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember] [IgnoreDataMember]
public IEnumerable<BaseItem> Children public IEnumerable<BaseItem> Children
{ {
get { return ActualChildren; } get { return ActualChildren.ToList(); }
} }
/// <summary> /// <summary>

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.Controller.LiveTv
{ {
string Name { get; } string Name { get; }
string Type { get; } string Type { get; }
Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken); Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken);
Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken); Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, CancellationToken cancellationToken);
Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings); Task Validate(ListingsProviderInfo info, bool validateLogin, bool validateListings);
Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location); Task<List<NameIdPair>> GetLineups(ListingsProviderInfo info, string country, string location);

View File

@ -145,8 +145,12 @@ namespace MediaBrowser.Providers.Manager
foreach (var path in paths) foreach (var path in paths)
{ {
source.Position = 0; source.Position = 0;
string retryPath = null;
await SaveImageToLocation(source, path, retryPaths[currentPathIndex], cancellationToken).ConfigureAwait(false); if (paths.Length == retryPaths.Length)
{
retryPath = retryPaths[currentPathIndex];
}
await SaveImageToLocation(source, path, retryPath, cancellationToken).ConfigureAwait(false);
currentPathIndex++; currentPathIndex++;
} }
@ -190,7 +194,8 @@ namespace MediaBrowser.Providers.Manager
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {
var retry = !string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase); var retry = !string.IsNullOrWhiteSpace(retryPath) &&
!string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
if (retry) if (retry)
{ {

View File

@ -280,6 +280,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
} }
_recordingProvider.Delete(remove); _recordingProvider.Delete(remove);
} }
else
{
throw new ResourceNotFoundException("Recording not found: " + recordingId);
}
} }
public Task CreateTimerAsync(TimerInfo info, CancellationToken cancellationToken) public Task CreateTimerAsync(TimerInfo info, CancellationToken cancellationToken)
@ -360,9 +364,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(CancellationToken cancellationToken) public async Task<IEnumerable<RecordingInfo>> GetRecordingsAsync(CancellationToken cancellationToken)
{ {
return Task.FromResult((IEnumerable<RecordingInfo>)_recordingProvider.GetAll()); var recordings = _recordingProvider.GetAll().ToList();
var updated = false;
foreach (var recording in recordings)
{
if (recording.Status == RecordingStatus.InProgress)
{
if (string.IsNullOrWhiteSpace(recording.TimerId) || !_activeRecordings.ContainsKey(recording.TimerId))
{
recording.Status = RecordingStatus.Cancelled;
recording.DateLastUpdated = DateTime.UtcNow;
_recordingProvider.Update(recording);
updated = true;
}
}
}
if (updated)
{
recordings = _recordingProvider.GetAll().ToList();
}
return recordings;
} }
public Task<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cancellationToken) public Task<IEnumerable<TimerInfo>> GetTimersAsync(CancellationToken cancellationToken)
@ -417,7 +443,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
foreach (var provider in GetListingProviders()) foreach (var provider in GetListingProviders())
{ {
var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channel.Number, startDateUtc, endDateUtc, cancellationToken) var programs = await provider.Item1.GetProgramsAsync(provider.Item2, channel.Number, channel.Name, startDateUtc, endDateUtc, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
var list = programs.ToList(); var list = programs.ToList();

View File

@ -31,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings.Emby
get { return "emby"; } get { return "emby"; }
} }
public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{ {
return GetListingsProvider(info.Country).GetProgramsAsync(info, channelNumber, startDateUtc, endDateUtc, cancellationToken); return GetListingsProvider(info.Country).GetProgramsAsync(info, channelNumber, startDateUtc, endDateUtc, cancellationToken);
} }

View File

@ -60,7 +60,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
return dates; return dates;
} }
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{ {
List<ProgramInfo> programsInfo = new List<ProgramInfo>(); List<ProgramInfo> programsInfo = new List<ProgramInfo>();
@ -89,12 +89,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
var dates = GetScheduleRequestDates(startDateUtc, endDateUtc); var dates = GetScheduleRequestDates(startDateUtc, endDateUtc);
ScheduleDirect.Station station = null; ScheduleDirect.Station station = GetStation(channelNumber, channelName);
if (!_channelPair.TryGetValue(channelNumber, out station)) if (station == null)
{ {
return programsInfo; return programsInfo;
} }
string stationID = station.stationID; string stationID = station.stationID;
_logger.Info("Channel Station ID is: " + stationID); _logger.Info("Channel Station ID is: " + stationID);
@ -167,6 +168,30 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
return programsInfo; return programsInfo;
} }
private ScheduleDirect.Station GetStation(string channelNumber, string channelName)
{
ScheduleDirect.Station station;
if (_channelPair.TryGetValue(channelNumber, out station))
{
return station;
}
if (string.IsNullOrWhiteSpace(channelName))
{
return null;
}
channelName = NormalizeName(channelName);
return _channelPair.Values.FirstOrDefault(i => string.Equals(NormalizeName(i.callsign ?? string.Empty), channelName, StringComparison.OrdinalIgnoreCase));
}
private string NormalizeName(string value)
{
return value.Replace(" ", string.Empty).Replace("-", string.Empty);
}
public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels, public async Task AddMetadata(ListingsProviderInfo info, List<ChannelInfo> channels,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
@ -200,45 +225,42 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
_logger.Info("Mapping Stations to Channel"); _logger.Info("Mapping Stations to Channel");
foreach (ScheduleDirect.Map map in root.map) foreach (ScheduleDirect.Map map in root.map)
{ {
var channel = map.logicalChannelNumber; var channelNumber = map.logicalChannelNumber;
if (string.IsNullOrWhiteSpace(channel)) if (string.IsNullOrWhiteSpace(channelNumber))
{ {
channel = map.channel; channelNumber = map.channel;
} }
if (string.IsNullOrWhiteSpace(channel)) if (string.IsNullOrWhiteSpace(channelNumber))
{ {
channel = (map.atscMajor + "." + map.atscMinor); channelNumber = (map.atscMajor + "." + map.atscMinor);
} }
channel = channel.TrimStart('0'); channelNumber = channelNumber.TrimStart('0');
_logger.Debug("Found channel: " + channel + " in Schedules Direct"); _logger.Debug("Found channel: " + channelNumber + " in Schedules Direct");
var schChannel = root.stations.FirstOrDefault(item => item.stationID == map.stationID); var schChannel = root.stations.FirstOrDefault(item => item.stationID == map.stationID);
if (!_channelPair.ContainsKey(channel) && channel != "0.0" && schChannel != null) _channelPair.TryAdd(channelNumber, schChannel);
{
_channelPair.TryAdd(channel, schChannel);
}
} }
_logger.Info("Added " + _channelPair.Count() + " channels to the dictionary"); _logger.Info("Added " + _channelPair.Count + " channels to the dictionary");
foreach (ChannelInfo channel in channels) foreach (ChannelInfo channel in channels)
{ {
// Helper.logger.Info("Modifyin channel " + channel.Number); var station = GetStation(channel.Number, channel.Number);
if (_channelPair.ContainsKey(channel.Number))
if (station != null)
{ {
if (_channelPair[channel.Number].logo != null) if (station.logo != null)
{ {
channel.ImageUrl = _channelPair[channel.Number].logo.URL; channel.ImageUrl = station.logo.URL;
channel.HasImage = true; channel.HasImage = true;
} }
string channelName = _channelPair[channel.Number].name; string channelName = station.name;
channel.Name = channelName; channel.Name = channelName;
} }
else else
{ {
_logger.Info("Schedules Direct doesnt have data for channel: " + channel.Number + " " + _logger.Info("Schedules Direct doesnt have data for channel: " + channel.Number + " " + channel.Name);
channel.Name);
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
get { return "xmltv"; } get { return "xmltv"; }
} }
public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken) public Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, string channelName, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -759,7 +759,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
{ {
await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
} }
else if (pathChanged || info.DateLastUpdated > recording.DateLastSaved) else if (pathChanged || info.DateLastUpdated > recording.DateLastSaved || info.Status != recording.Status)
{ {
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
} }
@ -1292,7 +1292,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false); var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false);
CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new Progress<double>(), cancellationToken).ConfigureAwait(false); await CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new Progress<double>(), cancellationToken).ConfigureAwait(false);
_lastRecordingRefreshTime = DateTime.UtcNow; _lastRecordingRefreshTime = DateTime.UtcNow;
} }
@ -1601,7 +1601,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv
var service = GetService(recording.ServiceName); var service = GetService(recording.ServiceName);
await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false); try
{
await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false);
}
catch (ResourceNotFoundException)
{
}
await _libraryManager.DeleteItem((BaseItem)recording).ConfigureAwait(false);
_lastRecordingRefreshTime = DateTime.MinValue; _lastRecordingRefreshTime = DateTime.MinValue;
} }

View File

@ -1396,8 +1396,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
typeof(LiveTvVideoRecording), typeof(LiveTvVideoRecording),
typeof(LiveTvAudioRecording), typeof(LiveTvAudioRecording),
typeof(Series), typeof(Series),
typeof(LiveTvAudioRecording),
typeof(LiveTvVideoRecording),
typeof(Audio), typeof(Audio),
typeof(MusicAlbum), typeof(MusicAlbum),
typeof(MusicArtist), typeof(MusicArtist),