Skip to content

Commit

Permalink
Hotfixes
Browse files Browse the repository at this point in the history
Added better formatings.
Fix Version
  • Loading branch information
maxpiva committed Dec 29, 2020
1 parent ade8e6c commit 67d77ec
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Sushi.Net.Library/Events/BlockManipulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void ExpandBorders(List<Event> events, AudioStream stream, float min_leng
end_diff *= diff;
start_diff *= diff;
states[x].ExpandEnd = states[x].Event.End + (float)end_diff;
states[x].ExpandStart = states[x].ExpandStart - (float)start_diff;
states[x+1].ExpandStart = states[x+1].Event.Start - (float)start_diff;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sushi.Net.Library/Events/Grouping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ public void Fix_Near_Borders(List<Event> events)
public float AverageShifts<T>(List<T> events) where T : Event
{
List<T> nevents = events.Where(a => !a.Linked).ToList();
if (nevents.Count == 0)
return events.FirstOrDefault()?.Diff ?? 0f;
if (nevents.Count <2)
return events.FirstOrDefault()?.Shift ?? 0f;
float[] shifts = nevents.Select(a => a.Shift).ToArray();
float[] weights = nevents.Select(a => 1 - a.Diff).ToArray();
double average = shifts.Average(weights);
Expand Down Expand Up @@ -429,7 +429,7 @@ public List<List<Event>> GroupWithChapters(List<Event> events, List<float> chapt
float start_shift = g[0].Shift;
float end_shift = g[^1].Shift;
float avg_shift = AverageShifts(g);
_logger.LogInformation($"Group (start: {g[0].Start.FormatTime()}, end: {g[^1].End.FormatTime()}, lines: {g.Count}), shifts (start: {start_shift}, end: {end_shift}, average: {avg_shift})");
_logger.LogInformation($"Group ({g[0].Start.FormatTime()}=>{g[^1].End.FormatTime()} to {g[0].ShiftedStart.FormatTime()}=>{g[^1].ShiftedEnd.FormatTime()}, lines: {g.Count,4:D}), shifts (start: {start_shift,15: 0.0000000000;-0.0000000000}, end: {end_shift,15: 0.0000000000;-0.0000000000}, average: {avg_shift,15: 0.0000000000;-0.0000000000})");
}

return groups;
Expand Down
4 changes: 3 additions & 1 deletion Sushi.Net.Library/Sushi.Net.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Version>0.9.0</Version>
<Version>0.9.1</Version>
<Authors>Máximo Piva</Authors>
<Company />
<Product />
Expand All @@ -17,6 +17,8 @@ Or it can shift in chunks a foreign/original audio stream to match another forei
<PackageIcon>sushi.png</PackageIcon>
<RepositoryUrl>https://github.com/maxpiva/Sushi.Net</RepositoryUrl>
<PackageTags>.net sushi subtitle audio shifter</PackageTags>
<AssemblyVersion>0.9.1.0</AssemblyVersion>
<FileVersion>0.9.1.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
14 changes: 12 additions & 2 deletions Sushi.Net.Library/Sushi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,18 @@ public async Task ShiftAudio(SushiSettings args)
using (AudioStream src_stream = await src_audio.ObtainWithoutProcess().ConfigureAwait(false))
{
_manipulation.ExpandBorders(events.Events, src_stream, .1F, args.SilenceThreshold);
foreach (Event ev in events.Events)
_logger.LogInformation($"Chunk (start: {(ev.Start + ev.Shift).FormatTime()}, end: {(ev.End + ev.Shift).FormatTime()}, shifts : {-ev.Shift}, diff: {Math.Abs(ev.Diff)}");
for(int x=0;x<events.Events.Count;x++)
{
Event ev = events.Events[x];
string orig = $"Chunk ({ev.ShiftedStart.FormatTime()}=>{ev.ShiftedEnd.FormatTime()} to {ev.Start.FormatTime()}=>{ev.End.FormatTime()}), shift : {-ev.Shift,15: 0.0000000000;-0.0000000000}, diff: {Math.Abs(ev.Diff),15: 0.0000000000;-0.0000000000}";
if (x > 0)
{
Event prev = events.Events.Take(x).FirstOrDefault(a => a.ShiftedEnd > ev.ShiftedStart);
if (prev!=null)
orig+=$" [Warn: Section of this block already used at {ev.ShiftedStart.FormatTime()}=>{prev.ShiftedEnd.FormatTime()}]";
}
_logger.LogInformation(orig);
}
List<Split> splits = _manipulation.CreateSplits(events.Events, dst_stream.DurationInSeconds);
if (!args.DryRun)
{
Expand Down
5 changes: 3 additions & 2 deletions Sushi.Net/Sushi.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
<PackageProjectUrl>https://github.com/maxpiva/Sushi.Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/maxpiva/Sushi.Net</RepositoryUrl>
<PackageTags>.net sushi subtitle audio shifter</PackageTags>
<AssemblyVersion>0.9.0.0</AssemblyVersion>
<FileVersion>0.9.0.0</FileVersion>
<AssemblyVersion>0.9.1.0</AssemblyVersion>
<FileVersion>0.9.1.0</FileVersion>
<Description>Sushi.Net Library
Automatic Subtitle &amp; Audio Shifter
It can shift subtitles based on two different audio streams using pattern matching.
Or it can shift in chunks a foreign/original audio stream to match another foreign/original audio stream using the ambience sound pattern matching.</Description>
<Copyright>Copyright © 2020 Máximo Piva</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>0.9.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 67d77ec

Please sign in to comment.