From 5291832e6c1492a74544e3aaf4334f67688d20d9 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Fri, 6 Oct 2023 19:36:42 -0500 Subject: [PATCH] fix clipboard and logs (#1466) * fix copy to clipboard in some cases * improve subtitle language selection logging * log playout item details --- CHANGELOG.md | 3 +++ ...layoutItemProcessByChannelNumberHandler.cs | 21 ++++++++++++++++ ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs | 13 +++++++--- ErsatzTV/Pages/_Host.cshtml | 25 +++++++++++++++---- 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ce35ec3..0f5b67151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - **This mode does NOT detect black and intelligently crop** - The goal is to fill the canvas by over-scaling and cropping, instead of minimally scaling and padding - Include `inputstream.ffmpegdirect` properties in channels.m3u when requested by Kodi +- Log playout item title and path when starting a stream + - This will help with media server libraries where the URL passed to ffmpeg doesn't indicate which file is streaming ### Fixed - Fix playout bug that caused some schedule items with fixed start times to be pushed to the next day @@ -22,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Remove ffmpeg and ffprobe as required dependencies for scanning media server libraries - Note that ffmpeg is still *always* required for playback to work - Fix PGS subtitle pixel format with Intel VAAPI +- Fix some cases where `Copy` button would fail to copy to clipboard ### Changed - Upgrade ffmpeg to 6.1, which is now *required* for all installs diff --git a/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs b/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs index e8d6b20df..a2af09a89 100644 --- a/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs +++ b/ErsatzTV.Application/Streaming/Queries/GetPlayoutItemProcessByChannelNumberHandler.cs @@ -1,5 +1,6 @@ using CliWrap; using Dapper; +using ErsatzTV.Application.Playouts; using ErsatzTV.Core; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Domain.Filler; @@ -83,6 +84,10 @@ public class GetPlayoutItemProcessByChannelNumberHandler : FFmpegProcessHandler< .ThenInclude(mi => (mi as Episode).MediaVersions) .ThenInclude(mv => mv.Streams) .Include(i => i.MediaItem) + .ThenInclude(mi => (mi as Episode).Season) + .ThenInclude(s => s.Show) + .ThenInclude(s => s.ShowMetadata) + .Include(i => i.MediaItem) .ThenInclude(mi => (mi as Movie).MovieMetadata) .ThenInclude(mm => mm.Subtitles) .Include(i => i.MediaItem) @@ -142,6 +147,22 @@ public class GetPlayoutItemProcessByChannelNumberHandler : FFmpegProcessHandler< foreach (PlayoutItemWithPath playoutItemWithPath in maybePlayoutItem.RightToSeq()) { + try + { + PlayoutItemViewModel viewModel = Mapper.ProjectToViewModel(playoutItemWithPath.PlayoutItem); + if (!string.IsNullOrWhiteSpace(viewModel.Title)) + { + _logger.LogDebug( + "Found playout item {Title} with path {Path}", + viewModel.Title, + playoutItemWithPath.Path); + } + } + catch (Exception ex) + { + _logger.LogDebug(ex, "Failed to get playout item title"); + } + MediaVersion version = playoutItemWithPath.PlayoutItem.MediaItem.GetHeadVersion(); string videoPath = playoutItemWithPath.Path; diff --git a/ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs b/ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs index f671e7f34..df1fecbc1 100644 --- a/ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs +++ b/ErsatzTV.Core/FFmpeg/FFmpegStreamSelector.cs @@ -138,6 +138,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector return None; } + var allCodes = new List(); string language = (preferredSubtitleLanguage ?? string.Empty).ToLowerInvariant(); if (string.IsNullOrWhiteSpace(language)) { @@ -146,10 +147,14 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector else { // filter to preferred language - List allCodes = await _searchRepository.GetAllLanguageCodes(new List { language }); + allCodes = await _searchRepository.GetAllLanguageCodes(new List { language }); + if (allCodes.Count > 1) + { + _logger.LogDebug("Preferred subtitle language has multiple codes {Codes}", allCodes); + } + subtitles = subtitles - .Filter( - s => allCodes.Any(c => string.Equals(s.Language, c, StringComparison.OrdinalIgnoreCase))) + .Filter(s => allCodes.Any(c => string.Equals(s.Language, c, StringComparison.OrdinalIgnoreCase))) .ToList(); } @@ -185,7 +190,7 @@ public class FFmpegStreamSelector : IFFmpegStreamSelector "Found no subtitles for channel {ChannelNumber} with mode {Mode} matching language {Language}", channel.Number, subtitleMode, - preferredSubtitleLanguage); + allCodes); return None; } diff --git a/ErsatzTV/Pages/_Host.cshtml b/ErsatzTV/Pages/_Host.cshtml index 863476671..3d1c8c1f9 100644 --- a/ErsatzTV/Pages/_Host.cshtml +++ b/ErsatzTV/Pages/_Host.cshtml @@ -79,11 +79,26 @@ }; window.clipboardCopy = { - copyText: function (codeElement) { - navigator.clipboard.writeText(codeElement.textContent) - .catch(function (error) { - console.log(error); - }); + copyText: async function (codeElement) { + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(codeElement.textContent); + } else { + const textArea = document.createElement("textarea"); + textArea.value = codeElement.textContent; + textArea.style.position = "absolute"; + textArea.style.left = "-999999px"; + + document.body.prepend(textArea); + textArea.select(); + + try { + document.execCommand('copy'); + } catch (error) { + console.error(error); + } finally { + textArea.remove(); + } + } } };