Skip to content

Commit

Permalink
Example client project refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
skuill committed Jan 27, 2024
1 parent 4d643f4 commit 312882c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
27 changes: 27 additions & 0 deletions LyricsScraperNET.Client/ConsoleExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;

namespace LyricsScraperNET
{
public static class ConsoleExtensions
{
private static readonly char indentSymbol = '-';

public static void WriteLineColored(this string str, ConsoleColor color = ConsoleColor.Gray, bool reset = true)
{
Console.ForegroundColor = color;
Console.WriteLine(str);
if (reset)
Console.ResetColor();
}

public static void WriteLineDelimeter(int repeatAmount = 20, ConsoleColor color = ConsoleColor.Gray, bool reset = true)
{
Console.ForegroundColor = color;
Console.WriteLine();
Console.WriteLine(new String(indentSymbol, repeatAmount));
Console.WriteLine();
if (reset)
Console.ResetColor();
}
}
}
30 changes: 17 additions & 13 deletions LyricsScraperNET.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,40 @@ static async Task Main()
//// 2) The requested song contains only the instrumental, no lyrics. In this case the flag 'Instrumental' will be true.
if (result.IsEmpty())
{
ConsoleExtensions.WriteLineDelimeter();
if (result.Instrumental)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine($"This song [{artistToSearch} - {songToSearch}] is instrumental.\r\nIt does not contain any lyrics");
$"This song [{artistToSearch} - {songToSearch}] is instrumental.\r\nIt does not contain any lyrics"
.WriteLineColored(ConsoleColor.Gray);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"Can't find lyrics for: [{artistToSearch} - {songToSearch}]. " +
($"Can't find lyrics for: [{artistToSearch} - {songToSearch}]. " +
$"Status code: [{result.ResponseStatusCode}]. " +
$"Response message: [{result.ResponseMessage}].");
$"Response message: [{result.ResponseMessage}].").WriteLineColored(ConsoleColor.Red);
}
Console.ResetColor();
ConsoleExtensions.WriteLineDelimeter();

"Press any key to exit..".WriteLineColored(ConsoleColor.DarkGray);
Console.ReadLine();
return;
}

//// Output result to console
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[{artistToSearch} - {songToSearch}]\r\n");
Console.ResetColor();
//// Artist and song information
$"[{artistToSearch} - {songToSearch}]".WriteLineColored(ConsoleColor.Yellow);

Console.WriteLine(result.LyricText);
ConsoleExtensions.WriteLineDelimeter();
//// Lyric text
result.LyricText.WriteLineColored();
ConsoleExtensions.WriteLineDelimeter();

Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine($"\r\nThis lyric was found by [{result.ExternalProviderType}]\r\n");
Console.ResetColor();
//// Lyrics provider information
$"This lyric was found by [{result.ExternalProviderType}]\r\n".WriteLineColored(ConsoleColor.Magenta);

"Press any key to exit..".WriteLineColored(ConsoleColor.DarkGray);
Console.ReadLine();
return;
}

/// <summary>
Expand Down

0 comments on commit 312882c

Please sign in to comment.