update live tv recordings

This commit is contained in:
Luke Pulverenti 2015-07-29 13:16:00 -04:00
parent 4d7f983618
commit 1f6b5a8c7c
6 changed files with 89 additions and 66 deletions

View file

@ -1,4 +1,5 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
@ -376,17 +377,40 @@ namespace MediaBrowser.Api.LiveTv
public string Country { get; set; }
}
[Route("/LiveTv/ListingProviders/SchedulesDirect/Countries", "GET", Summary = "Gets available lineups")]
[Authenticated]
public class GetSchedulesDirectCountries
{
}
public class LiveTvService : BaseApiService
{
private readonly ILiveTvManager _liveTvManager;
private readonly IUserManager _userManager;
private readonly IConfigurationManager _config;
private readonly IHttpClient _httpClient;
public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, IConfigurationManager config)
public LiveTvService(ILiveTvManager liveTvManager, IUserManager userManager, IConfigurationManager config, IHttpClient httpClient)
{
_liveTvManager = liveTvManager;
_userManager = userManager;
_config = config;
_httpClient = httpClient;
}
public async Task<object> Get(GetSchedulesDirectCountries request)
{
// https://json.schedulesdirect.org/20141201/available/countries
var response = await _httpClient.Get(new HttpRequestOptions
{
Url = "https://json.schedulesdirect.org/20141201/available/countries",
CacheLength = TimeSpan.FromDays(1),
CacheMode = CacheMode.Unconditional
}).ConfigureAwait(false);
return ResultFactory.GetResult(response, "application/json");
}
private void AssertUserCanManageLiveTv()

View file

@ -228,7 +228,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
public Task CreateSeriesTimerAsync(SeriesTimerInfo info, CancellationToken cancellationToken)
{
info.Id = info.ProgramId.Substring(0, 10);
info.Id = Guid.NewGuid().ToString("N");
UpdateTimersForSeriesTimer(info);
_seriesTimerProvider.Add(info);
@ -581,7 +581,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
epgData = GetEpgDataForChannel(seriesTimer.ChannelId);
}
var newTimers = RecordingHelper.GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll(), _logger);
var newTimers = GetTimersForSeries(seriesTimer, epgData, _recordingProvider.GetAll()).ToList();
var existingTimers = _timerProvider.GetAll()
.Where(i => string.Equals(i.SeriesTimerId, seriesTimer.Id, StringComparison.OrdinalIgnoreCase))
@ -603,6 +603,38 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
}
}
private IEnumerable<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> allPrograms, IReadOnlyList<RecordingInfo> currentRecordings)
{
allPrograms = GetProgramsForSeries(seriesTimer, allPrograms);
allPrograms = allPrograms.Where(epg => currentRecordings.All(r => r.ProgramId.Substring(0, 14) != epg.Id.Substring(0, 14))); //filtered recordings already running
return allPrograms.Select(i => RecordingHelper.CreateTimer(i, seriesTimer));
}
private IEnumerable<ProgramInfo> GetProgramsForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> allPrograms)
{
if (!seriesTimer.RecordAnyTime)
{
allPrograms = allPrograms.Where(epg => (seriesTimer.StartDate.TimeOfDay == epg.StartDate.TimeOfDay));
}
if (seriesTimer.RecordNewOnly)
{
allPrograms = allPrograms.Where(epg => !epg.IsRepeat); //Filtered by New only
}
if (!seriesTimer.RecordAnyChannel)
{
allPrograms = allPrograms.Where(epg => string.Equals(epg.ChannelId, seriesTimer.ChannelId, StringComparison.OrdinalIgnoreCase));
}
allPrograms = allPrograms.Where(epg => seriesTimer.Days.Contains(epg.StartDate.DayOfWeek));
// TODO: This assumption will require review once additional listing providers are added
return allPrograms.Where(epg => epg.Id.StartsWith(seriesTimer.ProgramId, StringComparison.OrdinalIgnoreCase));
}
private string GetChannelEpgCachePath(string channelId)
{
return Path.Combine(DataPath, "epg", channelId + ".json");

View file

@ -1,51 +1,12 @@
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
internal class RecordingHelper
{
public static List<TimerInfo> GetTimersForSeries(SeriesTimerInfo seriesTimer, IEnumerable<ProgramInfo> epgData, IReadOnlyList<RecordingInfo> currentRecordings, ILogger logger)
{
List<TimerInfo> timers = new List<TimerInfo>();
// Filtered Per Show
var filteredEpg = epgData.Where(epg => epg.Id.Substring(0, 10) == seriesTimer.Id);
if (!seriesTimer.RecordAnyTime)
{
filteredEpg = filteredEpg.Where(epg => (seriesTimer.StartDate.TimeOfDay == epg.StartDate.TimeOfDay));
}
if (seriesTimer.RecordNewOnly)
{
filteredEpg = filteredEpg.Where(epg => !epg.IsRepeat); //Filtered by New only
}
if (!seriesTimer.RecordAnyChannel)
{
filteredEpg = filteredEpg.Where(epg => string.Equals(epg.ChannelId, seriesTimer.ChannelId, StringComparison.OrdinalIgnoreCase));
}
filteredEpg = filteredEpg.Where(epg => seriesTimer.Days.Contains(epg.StartDate.DayOfWeek));
filteredEpg = filteredEpg.Where(epg => currentRecordings.All(r => r.Id.Substring(0, 14) != epg.Id.Substring(0, 14))); //filtered recordings already running
filteredEpg = filteredEpg.GroupBy(epg => epg.Id.Substring(0, 14)).Select(g => g.First()).ToList();
foreach (var epg in filteredEpg)
{
timers.Add(CreateTimer(epg, seriesTimer));
}
return timers;
}
public static DateTime GetStartTime(TimerInfo timer)
{
return timer.StartDate.AddSeconds(-timer.PrePaddingSeconds);

View file

@ -35,6 +35,22 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
_httpClient = httpClient;
}
private List<string> GetScheduleRequestDates(DateTime startDateUtc, DateTime endDateUtc)
{
List<string> dates = new List<string>();
var start = new List<DateTime> { startDateUtc, startDateUtc.ToLocalTime() }.Min();
var end = new List<DateTime> { endDateUtc, endDateUtc.ToLocalTime() }.Max();
while (start.DayOfYear <= end.Day)
{
dates.Add(start.ToString("yyyy-MM-dd"));
start = start.AddDays(1);
}
return dates;
}
public async Task<IEnumerable<ProgramInfo>> GetProgramsAsync(ListingsProviderInfo info, string channelNumber, DateTime startDateUtc, DateTime endDateUtc, CancellationToken cancellationToken)
{
List<ProgramInfo> programsInfo = new List<ProgramInfo>();
@ -60,15 +76,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
httpOptions.RequestHeaders["token"] = token;
List<string> dates = new List<string>();
int numberOfDay = 0;
DateTime lastEntry = startDateUtc;
while (lastEntry != endDateUtc)
{
lastEntry = startDateUtc.AddDays(numberOfDay);
dates.Add(lastEntry.ToString("yyyy-MM-dd"));
numberOfDay++;
}
var dates = GetScheduleRequestDates(startDateUtc, endDateUtc);
ScheduleDirect.Station station = null;
@ -97,8 +105,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
StreamReader reader = new StreamReader(response.Content);
string responseString = reader.ReadToEnd();
var dailySchedules = _jsonSerializer.DeserializeFromString<List<ScheduleDirect.Day>>(responseString);
_logger.Debug("Found " + dailySchedules.Count() + " programs on " + channelNumber +
" ScheduleDirect");
_logger.Debug("Found " + dailySchedules.Count() + " programs on " + channelNumber + " ScheduleDirect");
httpOptions = new HttpRequestOptions()
{
@ -234,10 +241,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
bool repeat = (programInfo.@new == null);
string newID = programInfo.programID + "T" + startAt.Ticks + "C" + channel;
if (programInfo.audioProperties != null)
{
if (programInfo.audioProperties.Exists(item => item == "stereo"))
if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd 5.1", StringComparison.OrdinalIgnoreCase)))
{
audioType = ProgramAudio.DolbyDigital;
}
else if (programInfo.audioProperties.Exists(item => string.Equals(item, "dd", StringComparison.OrdinalIgnoreCase)))
{
audioType = ProgramAudio.DolbyDigital;
}
else if (programInfo.audioProperties.Exists(item => string.Equals(item, "stereo", StringComparison.OrdinalIgnoreCase)))
{
audioType = ProgramAudio.Stereo;
}
@ -286,7 +300,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
imageLink = details.images;
}
var info = new ProgramInfo
{
ChannelId = channel,
@ -554,7 +567,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
};
httpOptions.RequestHeaders["token"] = token;
using (var response = await _httpClient.SendAsync(httpOptions, "PUT"))
{
}
@ -915,6 +928,5 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings
}
}
}
}

View file

@ -10,11 +10,11 @@ namespace MediaBrowser.Server.Implementations.Sync
{
if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
{
profileBitrate = Convert.ToInt32(profileBitrate.Value * .75);
profileBitrate = Math.Min(Convert.ToInt32(profileBitrate.Value * .7), 4000000);
}
else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
{
profileBitrate = Convert.ToInt32(profileBitrate.Value*.5);
profileBitrate = Math.Min(Convert.ToInt32(profileBitrate.Value * .5), 1500000);
}
}

View file

@ -742,9 +742,6 @@
<Content Include="dashboard-ui\livetvnewrecording.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\livetvrecording.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\livetvrecordinglist.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@ -1003,9 +1000,6 @@
<Content Include="dashboard-ui\scripts\livetvnewrecording.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\livetvrecording.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="dashboard-ui\scripts\livetvrecordinglist.js">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>