Skip to content

Commit 3aaa5ec

Browse files
committed
Fixed empty metadata if unedited, attachment filenames now get copied from all input files
1 parent 00befb4 commit 3aaa5ec

File tree

2 files changed

+38
-78
lines changed

2 files changed

+38
-78
lines changed

ff-utils-winforms/Data/Streams/Stream.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ public class Stream
44
{
55
public enum StreamType { Video, Audio, Subtitle, Data, Attachment, Unknown }
66
public StreamType Type;
7-
public int Index;
8-
public string Codec;
9-
public string CodecLong;
10-
public string Language;
11-
public string Title;
7+
public int Index = -1;
8+
public string Codec = "";
9+
public string CodecLong = "";
10+
public string Language = "";
11+
public string Title = "";
1212

1313
public override string ToString()
1414
{

ff-utils-winforms/UI/Tasks/QuickConvertUi.cs

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ public static void LoadMetadataGrid()
329329
if (TrackList.current == null)
330330
return;
331331

332+
Logger.Log($"Reloading metadata grid.", true);
332333
DataGridView grid = Program.mainForm.metaGrid;
333334
MediaFile c = TrackList.current.File;
334335

@@ -358,50 +359,6 @@ public static void LoadMetadataGrid()
358359
grid.Rows[newIdx].Visible = Program.mainForm.streamListBox.GetItemChecked(i);
359360
}
360361

361-
//if (FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).Any())
362-
// grid.Rows.Add("-1", $"File", metaEntries[0].Title, metaEntries[0].Language);
363-
364-
//var checkStreamEntries = Program.mainForm.streamListBox.Items.OfType<MediaStreamListEntry>().Where(x => Program.mainForm.streamListBox.CheckedItems.Contains(x));
365-
//List<MediaStreamListEntry> vStreams = checkStreamEntries.Where(e => e.Stream.Type == Stream.StreamType.Video).ToList();
366-
//List<MediaStreamListEntry> aStreams = checkStreamEntries.Where(e => e.Stream.Type == Stream.StreamType.Audio).ToList();
367-
//List<MediaStreamListEntry> sStreams = checkStreamEntries.Where(e => e.Stream.Type == Stream.StreamType.Subtitle).ToList();
368-
//
369-
//for (int i = 0; i < vStreams.Count; i++)
370-
//{
371-
// UniqueMetadataEntry e = new UniqueMetadataEntry(TrackList.current.SourcePath, Stream.StreamType.Video, vStreams[i].Stream.Index);
372-
// List<UniqueMetadataEntry> match = metaEntries.Where(x => x.GetPseudoHash() == e.GetPseudoHash()).ToList();
373-
// if (match.Count < 1) continue;
374-
// string title = match.Count > 0 ? match[0].Title : vStreams[i].Stream.Title;
375-
// string lang = match.Count > 0 ? match[0].Language : vStreams[i].Stream.Language;
376-
// if (!FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).Any()) continue;
377-
// int fileIdx = FileList.currentFiles.IndexOf(FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).First());
378-
// grid.Rows.Add(fileIdx, e.StreamIndex, $"Video Track {i + 1}", title, lang);
379-
//}
380-
//
381-
//for (int i = 0; i < aStreams.Count; i++)
382-
//{
383-
// UniqueMetadataEntry e = new UniqueMetadataEntry(TrackList.current.SourcePath, Stream.StreamType.Audio, aStreams[i].Stream.Index);
384-
// List<UniqueMetadataEntry> match = metaEntries.Where(x => x.GetPseudoHash() == e.GetPseudoHash()).ToList();
385-
// if (match.Count < 1) continue;
386-
// string title = match.Count > 0 ? match[0].Title : sStreams[i].Stream.Title;
387-
// string lang = match.Count > 0 ? match[0].Language : aStreams[i].Stream.Language;
388-
// if (!FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).Any()) continue;
389-
// int fileIdx = FileList.currentFiles.IndexOf(FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).First());
390-
// grid.Rows.Add(fileIdx, e.StreamIndex, $"Audio Track {i + 1}", title, lang);
391-
//}
392-
//
393-
//for (int i = 0; i < sStreams.Count; i++)
394-
//{
395-
// UniqueMetadataEntry e = new UniqueMetadataEntry(TrackList.current.SourcePath, Stream.StreamType.Subtitle, sStreams[i].Stream.Index);
396-
// List<UniqueMetadataEntry> match = metaEntries.Where(x => x.GetPseudoHash() == e.GetPseudoHash()).ToList();
397-
// if (match.Count < 1) continue;
398-
// string title = match.Count > 0 ? match[0].Title : sStreams[i].Stream.Title;
399-
// string lang = match.Count > 0 ? match[0].Language : sStreams[i].Stream.Language;
400-
// if (!FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).Any()) continue;
401-
// int fileIdx = FileList.currentFiles.IndexOf(FileList.currentFiles.Where(x => x.SourcePath == e.SourceFilePath).First());
402-
// grid.Rows.Add(fileIdx, e.StreamIndex, $"Subtitle Track {i + 1}", title, lang);
403-
//}
404-
405362
grid.RowHeadersVisible = false;
406363
grid.Columns[0].ReadOnly = true;
407364
grid.Columns.Cast<DataGridViewColumn>().ToList().ForEach(x => x.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill);
@@ -413,26 +370,10 @@ public static void LoadMetadataGrid()
413370
grid.Columns[2].FillWeight = 6;
414371
}
415372

416-
// private static void GetMetadata ()
417-
// {
418-
// var checkedStreams = Program.mainForm.streamListBox.Items.OfType<MediaStreamListEntry>().Where(x => Program.mainForm.streamListBox.CheckedItems.Contains(x));
419-
// List<Stream> allStreams = checkedStreams.Select(s => s.Stream).ToList();
420-
// List<VideoStream> vStreams = checkedStreams.Where(e => e.Stream.Type == Stream.StreamType.Video).Select(s => (VideoStream)s.Stream).ToList();
421-
// List<AudioStream> aStreams = checkedStreams.Where(e => e.Stream.Type == Stream.StreamType.Audio).Select(s => (AudioStream)s.Stream).ToList();
422-
// List<SubtitleStream> sStreams = checkedStreams.Where(e => e.Stream.Type == Stream.StreamType.Subtitle).Select(s => (SubtitleStream)s.Stream).ToList();
423-
//
424-
// metaEntries.Add(new UniqueMetadataEntry(TrackList.current.File.SourcePath, Stream.StreamType.Data, -1, TrackList.current.Title, TrackList.current.Language));
425-
//
426-
// for (int i = 0; i < checkedStreams.Count(); i++)
427-
// {
428-
// MediaStreamListEntry e = checkedStreams.ElementAt(i);
429-
// metaEntries.Add(new UniqueMetadataEntry(e.MediaFile.SourcePath, e.Stream.Type, i, e.Stream.Title, e.Stream.Language));
430-
// }
431-
// }
432-
433373
public static void SaveMetadata ()
434374
{
435375
DataGridView grid = Program.mainForm.metaGrid;
376+
Logger.Log($"Saving metadata.", true);
436377

437378
for (int i = 0; i < grid.Rows.Count; i++)
438379
{
@@ -446,26 +387,45 @@ public static void SaveMetadata ()
446387
{
447388
TrackList.current.TitleEdited = title;
448389
TrackList.current.LanguageEdited = lang;
449-
//Logger.Log($"Saved file metadata: {title} | {lang}");
450390
}
451391
else
452392
{
453393
MediaStreamListEntry entry = (MediaStreamListEntry)Program.mainForm.streamListBox.Items[idx];
454394
entry.TitleEdited = title;
455395
entry.LanguageEdited = lang;
456-
//Logger.Log($"Saved file metadata: {entry.TitleEdited} | {entry.LanguageEdited}");
457396
}
458397
}
459398
}
460399

461400
public static string GetMetadataArgs()
462401
{
463-
bool attachments = TrackList.current.File.AttachmentStreams.Count > 0;
464-
string stripStr = attachments ? ":s:t 0:s:t" : " -1"; // If there are attachments, only copy the attachment metadata, otherwise none
402+
SaveMetadata();
403+
MainForm form = Program.mainForm;
404+
bool attachments = form.streamListBox.CheckedItems.OfType<MediaStreamListEntry>().Where(x => x.Stream.Type == Stream.StreamType.Attachment).Count() > 0;
405+
string stripStr = ""; // If there are attachments, only copy the attachment metadata, otherwise none
406+
407+
if (attachments)
408+
{
409+
for (int i = 0; i < form.fileListBox.Items.Count; i++)
410+
{
411+
MediaFile file = ((FileListEntry)form.fileListBox.Items[i]).File;
412+
413+
bool fileHasAttachments = form.streamListBox.CheckedItems.OfType<MediaStreamListEntry>().Where(x => x.MediaFile.SourcePath == file.SourcePath).Where(x => x.Stream.Type == Stream.StreamType.Attachment).Count() > 0;
414+
415+
if (fileHasAttachments)
416+
stripStr += $"-map_metadata:s:t {i}:s:t";
417+
}
418+
}
419+
else
420+
{
421+
stripStr = "-map_metadata -1";
422+
}
423+
424+
465425
int cfg = Config.GetInt(Config.Key.metaMode);
466-
DataGridView grid = Program.mainForm.metaGrid;
467-
int defaultAudio = Program.mainForm.trackListDefaultAudioBox.SelectedIndex;
468-
int defaultSubs = Program.mainForm.trackListDefaultSubsBox.SelectedIndex - 1;
426+
DataGridView grid = form.metaGrid;
427+
int defaultAudio = form.trackListDefaultAudioBox.SelectedIndex;
428+
int defaultSubs = form.trackListDefaultSubsBox.SelectedIndex - 1;
469429
List<string> argsDispo = new List<string>();
470430

471431
int relIdxAud = 0;
@@ -476,7 +436,7 @@ public static string GetMetadataArgs()
476436
DataGridViewRow row = grid.Rows[i];
477437
string trackTitle = row.Cells[0].Value?.ToString();
478438

479-
if (i > 0 && Program.mainForm.streamListBox.GetItemChecked(i - 1))
439+
if (i > 0 && form.streamListBox.GetItemChecked(i - 1))
480440
{
481441
if (trackTitle.ToLower().Contains("audio"))
482442
{
@@ -503,7 +463,7 @@ public static string GetMetadataArgs()
503463
if (!string.IsNullOrWhiteSpace(TrackList.current.LanguageEdited))
504464
argsMeta.Add($"-metadata title=\"{TrackList.current.LanguageEdited}\"");
505465

506-
var streamEntries = Program.mainForm.streamListBox.CheckedItems.OfType<MediaStreamListEntry>().ToArray();
466+
var streamEntries = form.streamListBox.CheckedItems.OfType<MediaStreamListEntry>().ToArray();
507467

508468
for (int i = 0; i < streamEntries.Count(); i++)
509469
{
@@ -523,11 +483,11 @@ public static string GetMetadataArgs()
523483

524484
if (cfg == 0) // 0 = Map all and add titles/langs
525485
return $"-map_metadata 0 {string.Join(" ", argsMeta)} {string.Join(" ", argsDispo)}";
526-
else if (cfg == 0) // 1 = Strip but add titles/langs
527-
return $"-map_metadata{stripStr} {string.Join(" ", argsMeta)} {string.Join(" ", argsDispo)}";
486+
else if (cfg == 1) // 1 = Strip but add titles/langs
487+
return $"{stripStr} {string.Join(" ", argsMeta)} {string.Join(" ", argsDispo)}";
528488

529489
Logger.Log($"Metadata mode not 0, 1, or 2!! cfg = {cfg}", true);
530-
return $"-map_metadata{stripStr} {string.Join(" ", argsMeta)} {string.Join(" ", argsDispo)}";
490+
return $"{stripStr} {string.Join(" ", argsMeta)} {string.Join(" ", argsDispo)}";
531491
}
532492

533493
#endregion

0 commit comments

Comments
 (0)