From 989c782d5ca930ea21491f4193a02bd6760b3ca9 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 16 Nov 2026 16:33:53 +0000 Subject: [PATCH] =?UTF-8?q?Publier=20les=20marques=20nomm=C3=A9es=20comme?= =?UTF-8?q?=20chapitres=20du=20replay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le brouillon accepte un titre facultatif par marque (120 caractères au plus) ; la publication convertit les temps vers la chronologie du MP4, intègre les chapitres par FFmpeg sans réencodage et les expose dans PodcastResponse.Chapters. L'éditeur PostIt nomme les marques, le lecteur PostIt et la page web des podcasts listent les chapitres cliquables. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- CHANGELOG.md | 2 + doc/video-edition.md | 20 ++++- src/PostIt/PostIt.Tests/ReplayEditorTests.cs | 56 +++++++++++- .../ViewModels/Blogs/VideoPageViewModel.cs | 29 +++++++ .../ViewModels/ReplayEditorPageViewModel.cs | 24 ++++- .../PostIt/Views/Video/ReplayEditorPage.axaml | 6 +- src/PostIt/PostIt/Views/Video/VideoPage.axaml | 25 +++++- .../PostIt/Views/Video/VideoPage.axaml.cs | 15 ++++ src/Yavsc.Abstract/Streaming/Podcast.cs | 13 +++ .../Streaming/ReplayEditPlan.cs | 36 ++++++++ src/Yavsc.Org/Views/Podcast/Index.cshtml | 19 ++++ src/Yavsc.Org/wwwroot/js/podcasts.js | 6 ++ .../Interfaces/IPodcastReplayEditor.cs | 7 ++ .../Services/FfmpegPodcastReplayEditor.cs | 42 +++++++++ src/Yavsc.Server/Services/LiveProcessor.cs | 60 +++++++++---- .../Yavsc.Api.Tests/PodcastReplayTests.cs | 87 ++++++++++++++++++- .../Controllers/PodcastWebTests.cs | 8 +- 17 files changed, 422 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52fae0b46..9732594a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ ### Added +* [Podcasts] Publish named marks as replay chapters: the draft stores optional mark titles (`Chapters`, at most 120 characters, a title's time is also a mark, titles of removed marks are dropped). Publication converts their times to the published timeline, embeds them in the MP4 with an FFmpeg stream copy (titles only go through an escaped metadata file) and exposes them in `PodcastResponse.Chapters`. The PostIt editor names marks, and the PostIt replay player and the web podcasts page list the chapters as buttons that seek the replay. + * [PostIt/Podcasts] Add the desktop replay draft editor: from the refinement panel, the owner plays the private draft source, steps frame by frame, adds marks at the current time (Ctrl+M) with local thumbnails, picks start and end marks to remove ranges, restores ranges, then saves with the read revision (a conflict keeps local edits and asks for a reload) or publishes after saving pending edits. `ReplayEditPlan` moves to `Yavsc.Abstract` so the editor merges and validates ranges like the server. * [PostIt/Podcasts] Add the refined replay options and owner controls to the podcasts page: opt into refinement and choose the originals retention (0–365 days) for planned and immediate lives, see the draft state and originals deadline, publish the draft unchanged, and delete the originals after publication with confirmation. Playback now prefers the published MP4, lets the owner play unpublished originals, and tells other viewers the replay is being finalized instead of failing. diff --git a/doc/video-edition.md b/doc/video-edition.md index 57645a20e..e7e2f600f 100644 --- a/doc/video-edition.md +++ b/doc/video-edition.md @@ -238,7 +238,10 @@ Le brouillon privé est implémenté côté serveur, et son éditeur sur PostIt supprimées (200 au plus) pour la révision courante ; une révision périmée renvoie 409, des plages ou marques hors de la durée renvoient 400. Les marques sont dédoublonnées et triées ; celles situées dans une plage - supprimée disparaissent. + supprimée disparaissent. `Chapters` donne un titre (120 caractères au + plus, caractères de contrôle remplacés, titre vide ignoré) à une marque ; + son temps est ajouté aux marques s'il manque, et deux titres au même temps + renvoient 400. Le titre d'une marque supprimée disparaît avec elle. - `POST podcasts/{id}/draft/publish` (202) met en file la publication d'une révision ; répéter la demande pour la même révision est sans effet. - `GET`/`HEAD podcasts/{id}/draft/source.mp4` sert la source navigable, avec @@ -296,9 +299,18 @@ Le brouillon privé est implémenté côté serveur, et son éditeur sur PostIt par le serveur à l'enregistrement. L'enregistrement envoie la révision lue ; un conflit conserve les modifications locales et invite à recharger. La publication enregistre d'abord les modifications en attente. -- **Reste à faire** : chapitres nommés, miniatures des marques rechargées - depuis le serveur (elles ne sont créées qu'à la pose), éditeur Android et - validation sur de vrais médias. +- **Chapitres** : seules les marques nommées deviennent des chapitres. Dans + l'éditeur, chaque marque a un champ « Titre du chapitre (facultatif) ». À la + publication, leurs temps sont convertis vers la durée du MP4 (cumul des + plages conservées) ; FFmpeg les intègre au MP4 par copie sans réencodage, à + partir d'un fichier de métadonnées où les titres sont échappés (ils ne sont + jamais passés en argument). Sans plage supprimée, ils sont ajoutés à une + copie de la source. `PodcastResponse.Chapters` expose les chapitres publiés + à tous les auditeurs ; le site web les affiche en boutons sous le lecteur du + MP4 et PostIt dans le lecteur du replay, chacun positionnant la lecture. +- **Reste à faire** : miniatures des marques rechargées depuis le serveur + (elles ne sont créées qu'à la pose), éditeur Android et validation sur de + vrais médias. Une émission interrompue doit rester récupérable par son auteur. Lorsqu'un direct programmé s'arrête après le délai « Direct interrompu », ou qu'un diff --git a/src/PostIt/PostIt.Tests/ReplayEditorTests.cs b/src/PostIt/PostIt.Tests/ReplayEditorTests.cs index 9dc502fd3..7cdd81d91 100644 --- a/src/PostIt/PostIt.Tests/ReplayEditorTests.cs +++ b/src/PostIt/PostIt.Tests/ReplayEditorTests.cs @@ -130,6 +130,54 @@ public sealed class ReplayEditorTests(AvaloniaUiFixture ui) Assert.False(vm.AddMarkCommand.CanExecute(null)); }, TestContext.Current.CancellationToken); + [Fact] + public Task Mark_titles_are_loaded_edited_and_saved_as_chapters() + => ui.RunAsync(async () => + { + var api = new DraftApi(); + api.Podcast = api.Podcast with + { + Draft = api.Podcast.Draft! with { Marks = [5_000, 15_000, 25_000], Chapters = [new(15_000, "Invite")] } + }; + var vm = Editor(api); + Assert.Equal([null, "Invite", null], vm.Marks.Select(m => m.Title)); + Assert.False(vm.IsDirty); + + vm.Marks[0].Title = " Ouverture\t"; + Assert.True(vm.IsDirty); + vm.Marks[1].Title = "Coupee"; + vm.Marks[2].Title = " "; + // [15 s, 25 s) removes the start mark and keeps the end mark. + RemoveBetween(vm, 25_000, 15_000); + Assert.True(await vm.SaveAsync()); + + Assert.Equal([new PodcastChapter(5_000, "Ouverture"), new PodcastChapter(15_000, "Coupee")], api.Saved!.Chapters); + // The server drops the title of a removed mark. + Assert.Equal([5_000L, 25_000], vm.Marks.Select(m => m.TimeMs)); + Assert.Equal(["Ouverture", null], vm.Marks.Select(m => m.Title)); + Assert.False(vm.IsDirty); + }, TestContext.Current.CancellationToken); + + [Fact] + public Task Published_chapters_seek_the_replay_player() + => ui.RunAsync(() => + { + var vm = new VideoPageViewModel(new Uri("https://api.example/replay.mp4"), "video/mp4"); + long? seek = null; + vm.SeekRequested += t => seek = t; + Assert.False(vm.HasChapters); + + vm.ShowChapters([new(0, "Intro"), new(61_500, "Fin")]); + Assert.True(vm.HasChapters); + Assert.Equal("1:01 Fin", vm.Chapters[1].Label); + vm.GoToChapterCommand.Execute(vm.Chapters[1]); + Assert.Equal(61_500, seek); + + vm.ShowChapters([]); + Assert.False(vm.HasChapters); + return Task.CompletedTask; + }, TestContext.Current.CancellationToken); + private static ReplayEditorPageViewModel Editor(DraftApi api) => new(new PodcastApiClient(api, () => "https://api.example/"), api.Podcast); @@ -142,7 +190,7 @@ public sealed class ReplayEditorTests(AvaloniaUiFixture ui) private sealed class DraftApi : IYavscApiClient { - public PodcastResponse Podcast { get; private set; } = new(Guid.NewGuid(), "Concert", "owner", "Owner", + public PodcastResponse Podcast { get; set; } = new(Guid.NewGuid(), "Concert", "owner", "Owner", DateTimeOffset.UtcNow, DateTimeOffset.UtcNow, PodcastState.Completed, 1, 1024, 60) { RefineReplay = true, @@ -162,13 +210,13 @@ public sealed class ReplayEditorTests(AvaloniaUiFixture ui) { Saved = Assert.IsType(body); var ranges = Saved.RemovedRanges; + var marks = Saved.Marks.Where(m => !ranges.Any(r => m >= r.StartMs && m < r.EndMs)).ToArray(); Podcast = Podcast with { Draft = draft with { - Revision = draft.Revision + 1, - Marks = Saved.Marks.Where(m => !ranges.Any(r => m >= r.StartMs && m < r.EndMs)).ToArray(), - RemovedRanges = ranges + Revision = draft.Revision + 1, Marks = marks, RemovedRanges = ranges, + Chapters = Saved.Chapters.Where(c => marks.Contains(c.TimeMs)).ToArray() } }; } diff --git a/src/PostIt/PostIt/ViewModels/Blogs/VideoPageViewModel.cs b/src/PostIt/PostIt/ViewModels/Blogs/VideoPageViewModel.cs index 80f6de51a..820e0d5e6 100644 --- a/src/PostIt/PostIt/ViewModels/Blogs/VideoPageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Blogs/VideoPageViewModel.cs @@ -1,10 +1,20 @@ using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using PostIt.Services; using Yavsc.Abstract.Streaming; using Yavsc.Api.Client; namespace PostIt.ViewModels; +/// A chapter of a published replay, in the timeline of its MP4. +public sealed record PodcastChapterItem(long TimeMs, string Title) +{ + public string Label => $"{ReplayControlsState.FormatTime(TimeMs)} {Title}"; +} + public partial class VideoPageViewModel(Uri source, string mimeType, Uri? externalUri = null) : ViewModelBase { public Uri Source { get; } = source; @@ -13,6 +23,25 @@ public partial class VideoPageViewModel(Uri source, string mimeType, Uri? extern public PodcastApiClient? PodcastClient { get; init; } public PodcastResponse? Podcast { get; set; } + public ObservableCollection Chapters { get; } = new(); + public bool HasChapters => Chapters.Count > 0; + /// Requests the player to show this time of the published replay. + public event Action? SeekRequested; + + /// Shows the chapters of the replay actually played; other sources have none. + public void ShowChapters(IEnumerable chapters) + { + Chapters.Clear(); + foreach (var chapter in chapters) Chapters.Add(new(chapter.TimeMs, chapter.Title)); + OnPropertyChanged(nameof(HasChapters)); + } + + [RelayCommand] + private void GoToChapter(PodcastChapterItem? chapter) + { + if (chapter is not null) SeekRequested?.Invoke(chapter.TimeMs); + } + public bool CanOpenExternal => CanLaunchExternally(ExternalUri); public string Title => Podcast?.Title ?? Uri.UnescapeDataString(System.IO.Path.GetFileName(Source.AbsolutePath)); public override bool CanNavigateNext { get => false; protected set { } } diff --git a/src/PostIt/PostIt/ViewModels/ReplayEditorPageViewModel.cs b/src/PostIt/PostIt/ViewModels/ReplayEditorPageViewModel.cs index 96246ff2d..8ed0e6026 100644 --- a/src/PostIt/PostIt/ViewModels/ReplayEditorPageViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/ReplayEditorPageViewModel.cs @@ -27,6 +27,9 @@ public sealed partial class ReplayMarkItem(long timeMs) : ObservableObject public partial bool IsRemoved { get; set; } [ObservableProperty] public partial bool IsSelected { get; set; } + /// Optional title; a named mark is published as a chapter. + [ObservableProperty] + public partial string? Title { get; set; } } public sealed record ReplayRangeItem(long StartMs, long EndMs) @@ -167,7 +170,7 @@ public sealed partial class ReplayEditorPageViewModel : ViewModelBase Status = $"Une marque existe deja a {ReplayControlsState.FormatPreciseTime(time)}."; return; } - var mark = new ReplayMarkItem(time); + var mark = Track(new ReplayMarkItem(time)); var index = Marks.TakeWhile(m => m.TimeMs < time).Count(); Marks.Insert(index, mark); UpdateRemovedMarks(); @@ -181,6 +184,15 @@ public sealed partial class ReplayEditorPageViewModel : ViewModelBase } } + private ReplayMarkItem Track(ReplayMarkItem mark) + { + mark.PropertyChanged += (_, e) => + { + if (e.PropertyName == nameof(ReplayMarkItem.Title) && Marks.Contains(mark)) IsDirty = true; + }; + return mark; + } + private void RemoveMark(ReplayMarkItem? mark) { if (mark is null || !Marks.Remove(mark)) return; @@ -261,7 +273,9 @@ public sealed partial class ReplayEditorPageViewModel : ViewModelBase { Revision = draft.Revision, Marks = Marks.Select(m => m.TimeMs).ToArray(), - RemovedRanges = RemovedRanges.Select(r => new PodcastDraftRange(r.StartMs, r.EndMs)).ToArray() + RemovedRanges = RemovedRanges.Select(r => new PodcastDraftRange(r.StartMs, r.EndMs)).ToArray(), + Chapters = Marks.Select(m => (m.TimeMs, Title: ReplayEditPlan.ChapterTitle(m.Title))) + .Where(c => c.Title is not null).Select(c => new PodcastChapter(c.TimeMs, c.Title!)).ToArray() }); Load(saved, keepThumbnails: true); Status = $"Brouillon enregistre (revision {saved.Draft?.Revision})."; @@ -318,8 +332,12 @@ public sealed partial class ReplayEditorPageViewModel : ViewModelBase RangeStart = null; RangeEnd = null; Marks.Clear(); + var titles = (podcast.Draft?.Chapters ?? []).ToDictionary(c => c.TimeMs, c => c.Title); foreach (var time in marks.Order()) - Marks.Add(new ReplayMarkItem(time) { Thumbnail = thumbnails.GetValueOrDefault(time) }); + Marks.Add(Track(new ReplayMarkItem(time) + { + Thumbnail = thumbnails.GetValueOrDefault(time), Title = titles.GetValueOrDefault(time) + })); RemovedRanges.Clear(); foreach (var range in (podcast.Draft?.RemovedRanges ?? []).OrderBy(r => r.StartMs)) RemovedRanges.Add(new(range.StartMs, range.EndMs)); diff --git a/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml b/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml index 644c97878..eb642fc43 100644 --- a/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml +++ b/src/PostIt/PostIt/Views/Video/ReplayEditorPage.axaml @@ -3,6 +3,7 @@ xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vm="using:PostIt.ViewModels" + xmlns:abs="using:Yavsc.Abstract.Streaming" x:DataType="vm:ReplayEditorPageViewModel"> @@ -23,7 +24,7 @@ - @@ -37,6 +38,9 @@ + + + } + + + } @if (!ready) {