| | 1 | | #nullable disable |
| | 2 | |
|
| | 3 | | #pragma warning disable CS1591 |
| | 4 | |
|
| | 5 | | using System; |
| | 6 | | using System.Globalization; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Threading; |
| | 9 | | using System.Threading.Tasks; |
| | 10 | | using Jellyfin.Data.Enums; |
| | 11 | | using Jellyfin.Extensions; |
| | 12 | | using MediaBrowser.Common; |
| | 13 | | using MediaBrowser.Common.Extensions; |
| | 14 | | using MediaBrowser.Controller.Drawing; |
| | 15 | | using MediaBrowser.Controller.Dto; |
| | 16 | | using MediaBrowser.Controller.Entities; |
| | 17 | | using MediaBrowser.Controller.Library; |
| | 18 | | using MediaBrowser.Controller.LiveTv; |
| | 19 | | using MediaBrowser.Model.Dto; |
| | 20 | | using MediaBrowser.Model.Entities; |
| | 21 | | using MediaBrowser.Model.LiveTv; |
| | 22 | | using Microsoft.Extensions.Logging; |
| | 23 | |
|
| | 24 | | namespace Jellyfin.LiveTv |
| | 25 | | { |
| | 26 | | public class LiveTvDtoService |
| | 27 | | { |
| | 28 | | private const string InternalVersionNumber = "4"; |
| | 29 | |
|
| | 30 | | private const string ServiceName = "Emby"; |
| | 31 | |
|
| | 32 | | private readonly ILogger<LiveTvDtoService> _logger; |
| | 33 | | private readonly IImageProcessor _imageProcessor; |
| | 34 | | private readonly IDtoService _dtoService; |
| | 35 | | private readonly IApplicationHost _appHost; |
| | 36 | | private readonly ILibraryManager _libraryManager; |
| | 37 | |
|
| | 38 | | public LiveTvDtoService( |
| | 39 | | IDtoService dtoService, |
| | 40 | | IImageProcessor imageProcessor, |
| | 41 | | ILogger<LiveTvDtoService> logger, |
| | 42 | | IApplicationHost appHost, |
| | 43 | | ILibraryManager libraryManager) |
| | 44 | | { |
| 21 | 45 | | _dtoService = dtoService; |
| 21 | 46 | | _imageProcessor = imageProcessor; |
| 21 | 47 | | _logger = logger; |
| 21 | 48 | | _appHost = appHost; |
| 21 | 49 | | _libraryManager = libraryManager; |
| 21 | 50 | | } |
| | 51 | |
|
| | 52 | | public TimerInfoDto GetTimerInfoDto(TimerInfo info, ILiveTvService service, LiveTvProgram program, BaseItem chan |
| | 53 | | { |
| 0 | 54 | | var dto = new TimerInfoDto |
| 0 | 55 | | { |
| 0 | 56 | | Id = GetInternalTimerId(info.Id), |
| 0 | 57 | | Overview = info.Overview, |
| 0 | 58 | | EndDate = info.EndDate, |
| 0 | 59 | | Name = info.Name, |
| 0 | 60 | | StartDate = info.StartDate, |
| 0 | 61 | | ExternalId = info.Id, |
| 0 | 62 | | ChannelId = GetInternalChannelId(service.Name, info.ChannelId), |
| 0 | 63 | | Status = info.Status, |
| 0 | 64 | | SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : GetInternalSeriesTimerId(info.SeriesTi |
| 0 | 65 | | PrePaddingSeconds = info.PrePaddingSeconds, |
| 0 | 66 | | PostPaddingSeconds = info.PostPaddingSeconds, |
| 0 | 67 | | IsPostPaddingRequired = info.IsPostPaddingRequired, |
| 0 | 68 | | IsPrePaddingRequired = info.IsPrePaddingRequired, |
| 0 | 69 | | KeepUntil = info.KeepUntil, |
| 0 | 70 | | ExternalChannelId = info.ChannelId, |
| 0 | 71 | | ExternalSeriesTimerId = info.SeriesTimerId, |
| 0 | 72 | | ServiceName = service.Name, |
| 0 | 73 | | ExternalProgramId = info.ProgramId, |
| 0 | 74 | | Priority = info.Priority, |
| 0 | 75 | | RunTimeTicks = (info.EndDate - info.StartDate).Ticks, |
| 0 | 76 | | ServerId = _appHost.SystemId |
| 0 | 77 | | }; |
| | 78 | |
|
| 0 | 79 | | if (!string.IsNullOrEmpty(info.ProgramId)) |
| | 80 | | { |
| 0 | 81 | | dto.ProgramId = GetInternalProgramId(info.ProgramId).ToString("N", CultureInfo.InvariantCulture); |
| | 82 | | } |
| | 83 | |
|
| 0 | 84 | | if (program is not null) |
| | 85 | | { |
| 0 | 86 | | dto.ProgramInfo = _dtoService.GetBaseItemDto(program, new DtoOptions()); |
| | 87 | |
|
| 0 | 88 | | if (info.Status != RecordingStatus.Cancelled && info.Status != RecordingStatus.Error) |
| | 89 | | { |
| 0 | 90 | | dto.ProgramInfo.TimerId = dto.Id; |
| 0 | 91 | | dto.ProgramInfo.Status = info.Status.ToString(); |
| | 92 | | } |
| | 93 | |
|
| 0 | 94 | | dto.ProgramInfo.SeriesTimerId = dto.SeriesTimerId; |
| | 95 | |
|
| 0 | 96 | | if (!string.IsNullOrEmpty(info.SeriesTimerId)) |
| | 97 | | { |
| 0 | 98 | | FillImages(dto.ProgramInfo, info.Name, info.SeriesId); |
| | 99 | | } |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | if (channel is not null) |
| | 103 | | { |
| 0 | 104 | | dto.ChannelName = channel.Name; |
| | 105 | |
|
| 0 | 106 | | if (channel.HasImage(ImageType.Primary)) |
| | 107 | | { |
| 0 | 108 | | dto.ChannelPrimaryImageTag = GetImageTag(channel); |
| | 109 | | } |
| | 110 | | } |
| | 111 | |
|
| 0 | 112 | | return dto; |
| | 113 | | } |
| | 114 | |
|
| | 115 | | public SeriesTimerInfoDto GetSeriesTimerInfoDto(SeriesTimerInfo info, ILiveTvService service, string channelName |
| | 116 | | { |
| 0 | 117 | | var dto = new SeriesTimerInfoDto |
| 0 | 118 | | { |
| 0 | 119 | | Id = GetInternalSeriesTimerId(info.Id).ToString("N", CultureInfo.InvariantCulture), |
| 0 | 120 | | Overview = info.Overview, |
| 0 | 121 | | EndDate = info.EndDate, |
| 0 | 122 | | Name = info.Name, |
| 0 | 123 | | StartDate = info.StartDate, |
| 0 | 124 | | ExternalId = info.Id, |
| 0 | 125 | | PrePaddingSeconds = info.PrePaddingSeconds, |
| 0 | 126 | | PostPaddingSeconds = info.PostPaddingSeconds, |
| 0 | 127 | | IsPostPaddingRequired = info.IsPostPaddingRequired, |
| 0 | 128 | | IsPrePaddingRequired = info.IsPrePaddingRequired, |
| 0 | 129 | | Days = info.Days.ToArray(), |
| 0 | 130 | | Priority = info.Priority, |
| 0 | 131 | | RecordAnyChannel = info.RecordAnyChannel, |
| 0 | 132 | | RecordAnyTime = info.RecordAnyTime, |
| 0 | 133 | | SkipEpisodesInLibrary = info.SkipEpisodesInLibrary, |
| 0 | 134 | | KeepUpTo = info.KeepUpTo, |
| 0 | 135 | | KeepUntil = info.KeepUntil, |
| 0 | 136 | | RecordNewOnly = info.RecordNewOnly, |
| 0 | 137 | | ExternalChannelId = info.ChannelId, |
| 0 | 138 | | ExternalProgramId = info.ProgramId, |
| 0 | 139 | | ServiceName = service.Name, |
| 0 | 140 | | ChannelName = channelName, |
| 0 | 141 | | ServerId = _appHost.SystemId |
| 0 | 142 | | }; |
| | 143 | |
|
| 0 | 144 | | if (!string.IsNullOrEmpty(info.ChannelId)) |
| | 145 | | { |
| 0 | 146 | | dto.ChannelId = GetInternalChannelId(service.Name, info.ChannelId); |
| | 147 | | } |
| | 148 | |
|
| 0 | 149 | | if (!string.IsNullOrEmpty(info.ProgramId)) |
| | 150 | | { |
| 0 | 151 | | dto.ProgramId = GetInternalProgramId(info.ProgramId).ToString("N", CultureInfo.InvariantCulture); |
| | 152 | | } |
| | 153 | |
|
| 0 | 154 | | dto.DayPattern = info.Days is null ? null : GetDayPattern(info.Days.ToArray()); |
| | 155 | |
|
| 0 | 156 | | FillImages(dto, info.Name, info.SeriesId); |
| | 157 | |
|
| 0 | 158 | | return dto; |
| | 159 | | } |
| | 160 | |
|
| | 161 | | private void FillImages(BaseItemDto dto, string seriesName, string programSeriesId) |
| | 162 | | { |
| 0 | 163 | | var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery |
| 0 | 164 | | { |
| 0 | 165 | | IncludeItemTypes = new[] { BaseItemKind.Series }, |
| 0 | 166 | | Name = seriesName, |
| 0 | 167 | | Limit = 1, |
| 0 | 168 | | ImageTypes = new ImageType[] { ImageType.Thumb }, |
| 0 | 169 | | DtoOptions = new DtoOptions(false) |
| 0 | 170 | | }).FirstOrDefault(); |
| | 171 | |
|
| 0 | 172 | | if (librarySeries is not null) |
| | 173 | | { |
| 0 | 174 | | var image = librarySeries.GetImageInfo(ImageType.Thumb, 0); |
| 0 | 175 | | if (image is not null) |
| | 176 | | { |
| | 177 | | try |
| | 178 | | { |
| 0 | 179 | | dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image); |
| 0 | 180 | | dto.ParentThumbItemId = librarySeries.Id; |
| 0 | 181 | | } |
| 0 | 182 | | catch (Exception ex) |
| | 183 | | { |
| 0 | 184 | | _logger.LogError(ex, "Error"); |
| 0 | 185 | | } |
| | 186 | | } |
| | 187 | |
|
| 0 | 188 | | image = librarySeries.GetImageInfo(ImageType.Backdrop, 0); |
| 0 | 189 | | if (image is not null) |
| | 190 | | { |
| | 191 | | try |
| | 192 | | { |
| 0 | 193 | | dto.ParentBackdropImageTags = new string[] |
| 0 | 194 | | { |
| 0 | 195 | | _imageProcessor.GetImageCacheTag(librarySeries, image) |
| 0 | 196 | | }; |
| 0 | 197 | | dto.ParentBackdropItemId = librarySeries.Id; |
| 0 | 198 | | } |
| 0 | 199 | | catch (Exception ex) |
| | 200 | | { |
| 0 | 201 | | _logger.LogError(ex, "Error"); |
| 0 | 202 | | } |
| | 203 | | } |
| | 204 | | } |
| | 205 | |
|
| 0 | 206 | | var program = _libraryManager.GetItemList(new InternalItemsQuery |
| 0 | 207 | | { |
| 0 | 208 | | IncludeItemTypes = new[] { BaseItemKind.LiveTvProgram }, |
| 0 | 209 | | ExternalSeriesId = programSeriesId, |
| 0 | 210 | | Limit = 1, |
| 0 | 211 | | ImageTypes = new ImageType[] { ImageType.Primary }, |
| 0 | 212 | | DtoOptions = new DtoOptions(false), |
| 0 | 213 | | Name = string.IsNullOrEmpty(programSeriesId) ? seriesName : null |
| 0 | 214 | | }).FirstOrDefault(); |
| | 215 | |
|
| 0 | 216 | | if (program is not null) |
| | 217 | | { |
| 0 | 218 | | var image = program.GetImageInfo(ImageType.Primary, 0); |
| 0 | 219 | | if (image is not null) |
| | 220 | | { |
| | 221 | | try |
| | 222 | | { |
| 0 | 223 | | dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image); |
| 0 | 224 | | dto.ParentPrimaryImageItemId = program.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 225 | | } |
| 0 | 226 | | catch (Exception ex) |
| | 227 | | { |
| 0 | 228 | | _logger.LogError(ex, "Error"); |
| 0 | 229 | | } |
| | 230 | | } |
| | 231 | |
|
| 0 | 232 | | if (dto.ParentBackdropImageTags is null || dto.ParentBackdropImageTags.Length == 0) |
| | 233 | | { |
| 0 | 234 | | image = program.GetImageInfo(ImageType.Backdrop, 0); |
| 0 | 235 | | if (image is not null) |
| | 236 | | { |
| | 237 | | try |
| | 238 | | { |
| 0 | 239 | | dto.ParentBackdropImageTags = new string[] |
| 0 | 240 | | { |
| 0 | 241 | | _imageProcessor.GetImageCacheTag(program, image) |
| 0 | 242 | | }; |
| | 243 | |
|
| 0 | 244 | | dto.ParentBackdropItemId = program.Id; |
| 0 | 245 | | } |
| 0 | 246 | | catch (Exception ex) |
| | 247 | | { |
| 0 | 248 | | _logger.LogError(ex, "Error"); |
| 0 | 249 | | } |
| | 250 | | } |
| | 251 | | } |
| | 252 | | } |
| 0 | 253 | | } |
| | 254 | |
|
| | 255 | | private void FillImages(SeriesTimerInfoDto dto, string seriesName, string programSeriesId) |
| | 256 | | { |
| 0 | 257 | | var librarySeries = _libraryManager.GetItemList(new InternalItemsQuery |
| 0 | 258 | | { |
| 0 | 259 | | IncludeItemTypes = new[] { BaseItemKind.Series }, |
| 0 | 260 | | Name = seriesName, |
| 0 | 261 | | Limit = 1, |
| 0 | 262 | | ImageTypes = new ImageType[] { ImageType.Thumb }, |
| 0 | 263 | | DtoOptions = new DtoOptions(false) |
| 0 | 264 | | }).FirstOrDefault(); |
| | 265 | |
|
| 0 | 266 | | if (librarySeries is not null) |
| | 267 | | { |
| 0 | 268 | | var image = librarySeries.GetImageInfo(ImageType.Thumb, 0); |
| 0 | 269 | | if (image is not null) |
| | 270 | | { |
| | 271 | | try |
| | 272 | | { |
| 0 | 273 | | dto.ParentThumbImageTag = _imageProcessor.GetImageCacheTag(librarySeries, image); |
| 0 | 274 | | dto.ParentThumbItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 275 | | } |
| 0 | 276 | | catch (Exception ex) |
| | 277 | | { |
| 0 | 278 | | _logger.LogError(ex, "Error"); |
| 0 | 279 | | } |
| | 280 | | } |
| | 281 | |
|
| 0 | 282 | | image = librarySeries.GetImageInfo(ImageType.Backdrop, 0); |
| 0 | 283 | | if (image is not null) |
| | 284 | | { |
| | 285 | | try |
| | 286 | | { |
| 0 | 287 | | dto.ParentBackdropImageTags = new string[] |
| 0 | 288 | | { |
| 0 | 289 | | _imageProcessor.GetImageCacheTag(librarySeries, image) |
| 0 | 290 | | }; |
| 0 | 291 | | dto.ParentBackdropItemId = librarySeries.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 292 | | } |
| 0 | 293 | | catch (Exception ex) |
| | 294 | | { |
| 0 | 295 | | _logger.LogError(ex, "Error"); |
| 0 | 296 | | } |
| | 297 | | } |
| | 298 | | } |
| | 299 | |
|
| 0 | 300 | | var program = _libraryManager.GetItemList(new InternalItemsQuery |
| 0 | 301 | | { |
| 0 | 302 | | IncludeItemTypes = new[] { BaseItemKind.Series }, |
| 0 | 303 | | Name = seriesName, |
| 0 | 304 | | Limit = 1, |
| 0 | 305 | | ImageTypes = new ImageType[] { ImageType.Primary }, |
| 0 | 306 | | DtoOptions = new DtoOptions(false) |
| 0 | 307 | | }).FirstOrDefault(); |
| | 308 | |
|
| 0 | 309 | | if (program is null) |
| | 310 | | { |
| 0 | 311 | | program = _libraryManager.GetItemList(new InternalItemsQuery |
| 0 | 312 | | { |
| 0 | 313 | | IncludeItemTypes = new[] { BaseItemKind.LiveTvProgram }, |
| 0 | 314 | | ExternalSeriesId = programSeriesId, |
| 0 | 315 | | Limit = 1, |
| 0 | 316 | | ImageTypes = new ImageType[] { ImageType.Primary }, |
| 0 | 317 | | DtoOptions = new DtoOptions(false), |
| 0 | 318 | | Name = string.IsNullOrEmpty(programSeriesId) ? seriesName : null |
| 0 | 319 | | }).FirstOrDefault(); |
| | 320 | | } |
| | 321 | |
|
| 0 | 322 | | if (program is not null) |
| | 323 | | { |
| 0 | 324 | | var image = program.GetImageInfo(ImageType.Primary, 0); |
| 0 | 325 | | if (image is not null) |
| | 326 | | { |
| | 327 | | try |
| | 328 | | { |
| 0 | 329 | | dto.ParentPrimaryImageTag = _imageProcessor.GetImageCacheTag(program, image); |
| 0 | 330 | | dto.ParentPrimaryImageItemId = program.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 331 | | } |
| 0 | 332 | | catch (Exception ex) |
| | 333 | | { |
| 0 | 334 | | _logger.LogDebug(ex, "GetImageCacheTag raised an exception in LiveTvDtoService.FillImages."); |
| 0 | 335 | | } |
| | 336 | | } |
| | 337 | |
|
| 0 | 338 | | if (dto.ParentBackdropImageTags is null || dto.ParentBackdropImageTags.Length == 0) |
| | 339 | | { |
| 0 | 340 | | image = program.GetImageInfo(ImageType.Backdrop, 0); |
| 0 | 341 | | if (image is not null) |
| | 342 | | { |
| | 343 | | try |
| | 344 | | { |
| 0 | 345 | | dto.ParentBackdropImageTags = new[] |
| 0 | 346 | | { |
| 0 | 347 | | _imageProcessor.GetImageCacheTag(program, image) |
| 0 | 348 | | }; |
| 0 | 349 | | dto.ParentBackdropItemId = program.Id.ToString("N", CultureInfo.InvariantCulture); |
| 0 | 350 | | } |
| 0 | 351 | | catch (Exception ex) |
| | 352 | | { |
| 0 | 353 | | _logger.LogError(ex, "Error"); |
| 0 | 354 | | } |
| | 355 | | } |
| | 356 | | } |
| | 357 | | } |
| 0 | 358 | | } |
| | 359 | |
|
| | 360 | | public DayPattern? GetDayPattern(DayOfWeek[] days) |
| | 361 | | { |
| 0 | 362 | | DayPattern? pattern = null; |
| | 363 | |
|
| 0 | 364 | | if (days.Length > 0) |
| | 365 | | { |
| 0 | 366 | | if (days.Length == 7) |
| | 367 | | { |
| 0 | 368 | | pattern = DayPattern.Daily; |
| | 369 | | } |
| 0 | 370 | | else if (days.Length == 2) |
| | 371 | | { |
| 0 | 372 | | if (days.Contains(DayOfWeek.Saturday) && days.Contains(DayOfWeek.Sunday)) |
| | 373 | | { |
| 0 | 374 | | pattern = DayPattern.Weekends; |
| | 375 | | } |
| | 376 | | } |
| 0 | 377 | | else if (days.Length == 5) |
| | 378 | | { |
| 0 | 379 | | if (days.Contains(DayOfWeek.Monday) && days.Contains(DayOfWeek.Tuesday) && days.Contains(DayOfWeek.W |
| | 380 | | { |
| 0 | 381 | | pattern = DayPattern.Weekdays; |
| | 382 | | } |
| | 383 | | } |
| | 384 | | } |
| | 385 | |
|
| 0 | 386 | | return pattern; |
| | 387 | | } |
| | 388 | |
|
| | 389 | | internal string GetImageTag(BaseItem info) |
| | 390 | | { |
| | 391 | | try |
| | 392 | | { |
| 0 | 393 | | return _imageProcessor.GetImageCacheTag(info, ImageType.Primary); |
| | 394 | | } |
| 0 | 395 | | catch (Exception ex) |
| | 396 | | { |
| 0 | 397 | | _logger.LogError(ex, "Error getting image info for {Name}", info.Name); |
| 0 | 398 | | } |
| | 399 | |
|
| 0 | 400 | | return null; |
| 0 | 401 | | } |
| | 402 | |
|
| | 403 | | public Guid GetInternalChannelId(string serviceName, string externalId) |
| | 404 | | { |
| 0 | 405 | | var name = serviceName + externalId + InternalVersionNumber; |
| | 406 | |
|
| 0 | 407 | | return _libraryManager.GetNewItemId(name.ToLowerInvariant(), typeof(LiveTvChannel)); |
| | 408 | | } |
| | 409 | |
|
| | 410 | | public string GetInternalTimerId(string externalId) |
| | 411 | | { |
| 0 | 412 | | var name = ServiceName + externalId + InternalVersionNumber; |
| | 413 | |
|
| 0 | 414 | | return name.ToLowerInvariant().GetMD5().ToString("N", CultureInfo.InvariantCulture); |
| | 415 | | } |
| | 416 | |
|
| | 417 | | public Guid GetInternalSeriesTimerId(string externalId) |
| | 418 | | { |
| 0 | 419 | | var name = ServiceName + externalId + InternalVersionNumber; |
| | 420 | |
|
| 0 | 421 | | return name.ToLowerInvariant().GetMD5(); |
| | 422 | | } |
| | 423 | |
|
| | 424 | | public Guid GetInternalProgramId(string externalId) |
| | 425 | | { |
| 0 | 426 | | var name = ServiceName + externalId + InternalVersionNumber; |
| | 427 | |
|
| 0 | 428 | | return _libraryManager.GetNewItemId(name.ToLowerInvariant(), typeof(LiveTvProgram)); |
| | 429 | | } |
| | 430 | |
|
| | 431 | | public async Task<TimerInfo> GetTimerInfo(TimerInfoDto dto, bool isNew, LiveTvManager liveTv, CancellationToken |
| | 432 | | { |
| | 433 | | var info = new TimerInfo |
| | 434 | | { |
| | 435 | | Overview = dto.Overview, |
| | 436 | | EndDate = dto.EndDate, |
| | 437 | | Name = dto.Name, |
| | 438 | | StartDate = dto.StartDate, |
| | 439 | | Status = dto.Status, |
| | 440 | | PrePaddingSeconds = dto.PrePaddingSeconds, |
| | 441 | | PostPaddingSeconds = dto.PostPaddingSeconds, |
| | 442 | | IsPostPaddingRequired = dto.IsPostPaddingRequired, |
| | 443 | | IsPrePaddingRequired = dto.IsPrePaddingRequired, |
| | 444 | | KeepUntil = dto.KeepUntil, |
| | 445 | | Priority = dto.Priority, |
| | 446 | | SeriesTimerId = dto.ExternalSeriesTimerId, |
| | 447 | | ProgramId = dto.ExternalProgramId, |
| | 448 | | ChannelId = dto.ExternalChannelId, |
| | 449 | | Id = dto.ExternalId |
| | 450 | | }; |
| | 451 | |
|
| | 452 | | // Convert internal server id's to external tv provider id's |
| | 453 | | if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id)) |
| | 454 | | { |
| | 455 | | var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false); |
| | 456 | |
|
| | 457 | | info.Id = timer.ExternalId; |
| | 458 | | } |
| | 459 | |
|
| | 460 | | if (!dto.ChannelId.IsEmpty() && string.IsNullOrEmpty(info.ChannelId)) |
| | 461 | | { |
| | 462 | | var channel = _libraryManager.GetItemById(dto.ChannelId); |
| | 463 | |
|
| | 464 | | if (channel is not null) |
| | 465 | | { |
| | 466 | | info.ChannelId = channel.ExternalId; |
| | 467 | | } |
| | 468 | | } |
| | 469 | |
|
| | 470 | | if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId)) |
| | 471 | | { |
| | 472 | | var program = _libraryManager.GetItemById(dto.ProgramId); |
| | 473 | |
|
| | 474 | | if (program is not null) |
| | 475 | | { |
| | 476 | | info.ProgramId = program.ExternalId; |
| | 477 | | } |
| | 478 | | } |
| | 479 | |
|
| | 480 | | if (!string.IsNullOrEmpty(dto.SeriesTimerId) && string.IsNullOrEmpty(info.SeriesTimerId)) |
| | 481 | | { |
| | 482 | | var timer = await liveTv.GetSeriesTimer(dto.SeriesTimerId, cancellationToken).ConfigureAwait(false); |
| | 483 | |
|
| | 484 | | if (timer is not null) |
| | 485 | | { |
| | 486 | | info.SeriesTimerId = timer.ExternalId; |
| | 487 | | } |
| | 488 | | } |
| | 489 | |
|
| | 490 | | return info; |
| | 491 | | } |
| | 492 | |
|
| | 493 | | public async Task<SeriesTimerInfo> GetSeriesTimerInfo(SeriesTimerInfoDto dto, bool isNew, LiveTvManager liveTv, |
| | 494 | | { |
| | 495 | | var info = new SeriesTimerInfo |
| | 496 | | { |
| | 497 | | Overview = dto.Overview, |
| | 498 | | EndDate = dto.EndDate, |
| | 499 | | Name = dto.Name, |
| | 500 | | StartDate = dto.StartDate, |
| | 501 | | PrePaddingSeconds = dto.PrePaddingSeconds, |
| | 502 | | PostPaddingSeconds = dto.PostPaddingSeconds, |
| | 503 | | IsPostPaddingRequired = dto.IsPostPaddingRequired, |
| | 504 | | IsPrePaddingRequired = dto.IsPrePaddingRequired, |
| | 505 | | Days = dto.Days.ToList(), |
| | 506 | | Priority = dto.Priority, |
| | 507 | | RecordAnyChannel = dto.RecordAnyChannel, |
| | 508 | | RecordAnyTime = dto.RecordAnyTime, |
| | 509 | | SkipEpisodesInLibrary = dto.SkipEpisodesInLibrary, |
| | 510 | | KeepUpTo = dto.KeepUpTo, |
| | 511 | | KeepUntil = dto.KeepUntil, |
| | 512 | | RecordNewOnly = dto.RecordNewOnly, |
| | 513 | | ProgramId = dto.ExternalProgramId, |
| | 514 | | ChannelId = dto.ExternalChannelId, |
| | 515 | | Id = dto.ExternalId |
| | 516 | | }; |
| | 517 | |
|
| | 518 | | // Convert internal server id's to external tv provider id's |
| | 519 | | if (!isNew && !string.IsNullOrEmpty(dto.Id) && string.IsNullOrEmpty(info.Id)) |
| | 520 | | { |
| | 521 | | var timer = await liveTv.GetSeriesTimer(dto.Id, cancellationToken).ConfigureAwait(false); |
| | 522 | |
|
| | 523 | | info.Id = timer.ExternalId; |
| | 524 | | } |
| | 525 | |
|
| | 526 | | if (!dto.ChannelId.IsEmpty() && string.IsNullOrEmpty(info.ChannelId)) |
| | 527 | | { |
| | 528 | | var channel = _libraryManager.GetItemById(dto.ChannelId); |
| | 529 | |
|
| | 530 | | if (channel is not null) |
| | 531 | | { |
| | 532 | | info.ChannelId = channel.ExternalId; |
| | 533 | | } |
| | 534 | | } |
| | 535 | |
|
| | 536 | | if (!string.IsNullOrEmpty(dto.ProgramId) && string.IsNullOrEmpty(info.ProgramId)) |
| | 537 | | { |
| | 538 | | var program = _libraryManager.GetItemById(dto.ProgramId); |
| | 539 | |
|
| | 540 | | if (program is not null) |
| | 541 | | { |
| | 542 | | info.ProgramId = program.ExternalId; |
| | 543 | | } |
| | 544 | | } |
| | 545 | |
|
| | 546 | | return info; |
| | 547 | | } |
| | 548 | | } |
| | 549 | | } |