Publier les marques nommées comme chapitres du replay
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>
This commit is contained in:
parent
b0b81f3632
commit
989c782d5c
17 changed files with 422 additions and 33 deletions
|
|
@ -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<SavePodcastDraftRequest>(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()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/// <summary>A chapter of a published replay, in the timeline of its MP4.</summary>
|
||||
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<PodcastChapterItem> Chapters { get; } = new();
|
||||
public bool HasChapters => Chapters.Count > 0;
|
||||
/// <summary>Requests the player to show this time of the published replay.</summary>
|
||||
public event Action<long>? SeekRequested;
|
||||
|
||||
/// <summary>Shows the chapters of the replay actually played; other sources have none.</summary>
|
||||
public void ShowChapters(IEnumerable<PodcastChapter> 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 { } }
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
/// <summary>Optional title; a named mark is published as a chapter.</summary>
|
||||
[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));
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
<Grid ColumnDefinitions="2*,*" RowDefinitions="Auto,*,Auto,Auto" Margin="16" ColumnSpacing="16" RowSpacing="8">
|
||||
<TextBlock Grid.ColumnSpan="2" Text="{Binding Title}" FontSize="22" TextWrapping="Wrap" />
|
||||
|
|
@ -23,7 +24,7 @@
|
|||
<TextBlock Text="{Binding DraftState}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="{Binding DurationSummary}" TextWrapping="Wrap" />
|
||||
<TextBlock Text="Marques" FontWeight="SemiBold" />
|
||||
<TextBlock Text="Les temps sont ceux de la source originale. Les miniatures restent locales et sont effacees en quittant l'editeur."
|
||||
<TextBlock Text="Les temps sont ceux de la source originale. Les miniatures restent locales et sont effacees en quittant l'editeur. Une marque nommee devient un chapitre du replay publie."
|
||||
TextWrapping="Wrap" />
|
||||
<ItemsControl ItemsSource="{Binding Marks}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
|
|
@ -37,6 +38,9 @@
|
|||
<TextBlock Text="(supprimee)" IsVisible="{Binding IsRemoved}" />
|
||||
<TextBlock Text="✓ selectionnee" IsVisible="{Binding IsSelected}" />
|
||||
</StackPanel>
|
||||
<TextBox Text="{Binding Title}" Watermark="Titre du chapitre (facultatif)"
|
||||
MaxLength="{x:Static abs:ReplayEditPlan.MaxChapterTitleLength}"
|
||||
IsEnabled="{Binding $parent[ContentPage].((vm:ReplayEditorPageViewModel)DataContext).CanEdit}" />
|
||||
<WrapPanel>
|
||||
<Button Content="Aller" Margin="0,0,4,4"
|
||||
Command="{Binding $parent[ContentPage].((vm:ReplayEditorPageViewModel)DataContext).GoToMarkCommand}"
|
||||
|
|
|
|||
|
|
@ -4,12 +4,31 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:vm="using:PostIt.ViewModels"
|
||||
x:DataType="vm:VideoPageViewModel">
|
||||
<Grid RowDefinitions="Auto,*,Auto,Auto" Margin="16" RowSpacing="12">
|
||||
<Grid RowDefinitions="Auto,*,Auto,Auto,Auto" Margin="16" RowSpacing="12">
|
||||
<TextBlock Text="{Binding Title}" FontSize="22" TextWrapping="Wrap" />
|
||||
<Border Grid.Row="1" Background="Black" BorderThickness="1" BorderBrush="Green">
|
||||
<ContentControl x:Name="VideoSurface" />
|
||||
</Border>
|
||||
<Button Grid.Row="2" Content="Ouvrir dans le navigateur" Click="OpenExternal_Click" IsVisible="{Binding CanOpenExternal}" />
|
||||
<TextBlock x:Name="PlaybackStatus" Grid.Row="3" TextWrapping="Wrap" />
|
||||
<StackPanel Grid.Row="2" Spacing="4" IsVisible="{Binding HasChapters}">
|
||||
<TextBlock Text="Chapitres" FontWeight="SemiBold" />
|
||||
<ScrollViewer MaxHeight="160">
|
||||
<ItemsControl ItemsSource="{Binding Chapters}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<WrapPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="vm:PodcastChapterItem">
|
||||
<Button Content="{Binding Label}" Margin="0,0,6,6"
|
||||
Command="{Binding $parent[ContentPage].((vm:VideoPageViewModel)DataContext).GoToChapterCommand}"
|
||||
CommandParameter="{Binding}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</ScrollViewer>
|
||||
</StackPanel>
|
||||
<Button Grid.Row="3" Content="Ouvrir dans le navigateur" Click="OpenExternal_Click" IsVisible="{Binding CanOpenExternal}" />
|
||||
<TextBlock x:Name="PlaybackStatus" Grid.Row="4" TextWrapping="Wrap" />
|
||||
</Grid>
|
||||
</ContentPage>
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public partial class VideoPage : ContentPage
|
|||
private PodcastMediaInput? _podcastInput;
|
||||
private PodcastReplayMediaInput? _replayInput;
|
||||
private CancellationTokenSource? _initialization;
|
||||
private VideoPageViewModel? _chaptersOwner;
|
||||
|
||||
public VideoPage() => InitializeComponent();
|
||||
|
||||
|
|
@ -35,6 +36,9 @@ public partial class VideoPage : ContentPage
|
|||
ReleasePlayer();
|
||||
if (Design.IsDesignMode || DataContext is not VideoPageViewModel vm)
|
||||
return;
|
||||
vm.ShowChapters([]);
|
||||
vm.SeekRequested += SeekToChapter;
|
||||
_chaptersOwner = vm;
|
||||
var cancellation = new CancellationTokenSource();
|
||||
_initialization = cancellation;
|
||||
var ct = cancellation.Token;
|
||||
|
|
@ -55,6 +59,7 @@ public partial class VideoPage : ContentPage
|
|||
{
|
||||
_replayInput = new PodcastReplayMediaInput(replayClient, podcast.Id, podcast.Replay!.Bytes);
|
||||
_replayInput.Failed += PodcastFailed;
|
||||
vm.ShowChapters(podcast.Chapters);
|
||||
replay = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -122,8 +127,18 @@ public partial class VideoPage : ContentPage
|
|||
base.OnDetachedFromVisualTree(e);
|
||||
}
|
||||
|
||||
private void SeekToChapter(long timeMs)
|
||||
{
|
||||
if (_player is { IsSeekable: true } player) player.Time = timeMs;
|
||||
}
|
||||
|
||||
private void ReleasePlayer()
|
||||
{
|
||||
if (_chaptersOwner is not null)
|
||||
{
|
||||
_chaptersOwner.SeekRequested -= SeekToChapter;
|
||||
_chaptersOwner = null;
|
||||
}
|
||||
_initialization?.Cancel();
|
||||
_initialization?.Dispose();
|
||||
_initialization = null;
|
||||
|
|
|
|||
Loading…
Reference in a new issue