From ac67ecf7bbc6cff3747e1f9996326399fc405ab6 Mon Sep 17 00:00:00 2001 From: Emilian Roman Date: Sat, 4 Dec 2021 23:12:43 +0800 Subject: [PATCH] Fix and improve Gunloader Album hydration logic --- src/Albums/Gunloader.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Albums/Gunloader.cs b/src/Albums/Gunloader.cs index 9d3b1f9..c036459 100644 --- a/src/Albums/Gunloader.cs +++ b/src/Albums/Gunloader.cs @@ -41,21 +41,20 @@ public Gunloader(FileInfo file) public override void Hydrate(Metadata metadata) { - var records = ReadAllLines(_file.FullName) + var lines = ReadAllLines(_file.FullName) .Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#') && !line.StartsWith(';')) .ToArray(); - Title = records[0].Trim(); - Source = records[1].Trim(); + var title = lines[0].Trim(); /* first line */ + var source = lines[1].Trim(); /* second line */ + var records = lines.Skip(2).ToList(); /* remaining lines */ - /** - * Parse the Records file when the first line is NOT a YouTube video, or when no Tracks have been successfully - * inferred from YouTube chapters. - */ + Title = title; + Source = source; - for (var i = 2; i < records.Skip(2).Count(); i++) + foreach (var song in records) { - var split = records[i].Split(' '); + var split = song.Split(' '); var track = new Track { Number = split[0], @@ -118,4 +117,4 @@ public override void Load(ISerialisation serialisation) Tracks = album.Tracks; } } -} \ No newline at end of file +}