Skip to content

Commit

Permalink
Improved memory usage somewhat
Browse files Browse the repository at this point in the history
  • Loading branch information
EricStG committed Dec 21, 2020
1 parent b31789d commit 1339e22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
14 changes: 6 additions & 8 deletions Listatateur/Crawler/Crawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private static MediaFile ProcessFile(string filename)

private static IEnumerable<MediaFile> ProcessFolder(string folder, bool recursive)
{
List<MediaFile> list = new List<MediaFile>();
SearchOption options;
if (recursive)
{
Expand All @@ -62,29 +61,28 @@ private static IEnumerable<MediaFile> ProcessFolder(string folder, bool recursiv
var file = ProcessFile(filename);
if (file != null)
{
list.Add(file);
yield return file;
}
}

return list;
}

public static IEnumerable<MediaFile> ProcessPaths(IEnumerable<string> paths, bool recursive)
{
List<MediaFile> list = new List<MediaFile>();
foreach(var path in paths)
{
var attribs = File.GetAttributes(path);
if (attribs.HasFlag(FileAttributes.Directory))
{
list.AddRange(ProcessFolder(path, recursive));
foreach (var media in ProcessFolder(path, recursive))
{
yield return media;
}
}
else
{
list.Add(ProcessFile(path));
yield return ProcessFile(path);
}
}
return list;
}
}
}
22 changes: 7 additions & 15 deletions Listatateur/Listatateur-Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Listatateur_Console
{
Expand All @@ -26,24 +25,17 @@ static void Main(string[] args)

static void ExportFiles(IEnumerable<Crawler.MediaFile> files)
{
if (files.Count() > 0)
using (var outFile = File.CreateText(string.Format("Listateur-{0}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"))))
{
using (var outFile = File.CreateText(string.Format("Listateur-{0}.txt", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"))))
{
string[] header = {"Filename", "Title", "Artist", "Album artist", "Album", "Bpm", "Disc", "Disc count", "Year", "Genres"};
outFile.WriteLine(string.Join(Delimiter, header));
string[] header = {"Filename", "Title", "Artist", "Album artist", "Album", "Bpm", "Disc", "Disc count", "Year", "Genres"};
outFile.WriteLine(string.Join(Delimiter, header));

foreach (var file in files)
{
string[] line = { file.Filename, file.Title, file.Artist, file.AlbumArtist, file.Album, file.Bpm.ToString(), file.Disc.ToString(), file.DiscCount.ToString(), file.Year.ToString(), file.Genres };
outFile.WriteLine(string.Join(Delimiter, line));
}
foreach (var file in files)
{
string[] line = { file.Filename, file.Title, file.Artist, file.AlbumArtist, file.Album, file.Bpm.ToString(), file.Disc.ToString(), file.DiscCount.ToString(), file.Year.ToString(), file.Genres };
outFile.WriteLine(string.Join(Delimiter, line));
}
}
else
{

}
}

}
Expand Down

0 comments on commit 1339e22

Please sign in to comment.