luminescence-software / scripts

C# scripts for Metatogger
Mozilla Public License 2.0
8 stars 7 forks source link

Export the list of Artist / Album in the clipboard to be pasted anywhere #3

Open CyberSinh opened 7 years ago

CyberSinh commented 7 years ago
// Export the list of Artist / Album in the clipboard to be pasted anywhere

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using Metatogger.Data;

var data = new Dictionary<string, HashSet<string>>(StringComparer.InvariantCultureIgnoreCase);

void ProcessAudioFiles(string artist, string album)
{
   if (artist == null || album == null) return;

   if (data.ContainsKey(artist))
      data[artist].Add(album);
   else
      data.Add(artist, new HashSet<string>(new[] { album }, StringComparer.InvariantCultureIgnoreCase));
}

foreach (var file in files)
   if (file.IsEnabled)
      ProcessAudioFiles(file.GetFirstValue(TagName.Artist), file.GetFirstValue(TagName.Album));

var sb = new StringBuilder();
foreach (var kvp in data)
{
   sb.AppendLine(kvp.Key);
   foreach (string album in kvp.Value)
      sb.AppendLine("\t" + album);
   sb.AppendLine();
}

Clipboard.SetText(sb.ToString(), TextDataFormat.UnicodeText);