public string ExtractArtist(string birth, FileInfo file)
{
switch (birth)
{
case "waffles":
{
/*Look for a space on either side of the dash*/
int startingPosition = 0;
int dashes = file.Name.Split('-').Length;
for (int a = 0; a <= dashes; a++)
{
int dash = file.Name.IndexOf('-', startingPosition);
if (file.Name[dash - 1].Equals(' ') && file.Name[dash + 1].Equals(' '))
{
return file.Name.Substring(0, dash - 1); //return the artist
}
startingPosition = dash + 1;
}
/*If that fails...*/
return IssueError("Can't parse artist", file);
}
case "what":
{
try
{
bool zipped = file.FullName.Contains("[CSL]--Temp");
switch (zipped) //Zipped or not zipped.. switch statement improves readability
{
case (true):
{
//...\[CSL]--Temp\artist\[physicalformat]\[files]
int firstSlash = file.FullName.IndexOf("[CSL]--Temp") - 1;
int secondSlash = file.FullName.IndexOf(@"\", firstSlash + 1) + 1;
int thirdSlash = file.FullName.IndexOf(@"\", secondSlash + 1);
return file.FullName.Substring(secondSlash, thirdSlash - secondSlash);
}
case (false):
{
/*Look for a space on either side of the dash*/
int startingPosition = 0;
int dashes = file.Name.Split('-').Length;
string filename = file.Name;
for (int a = 0; a <= dashes; a++)
{
int dash = filename.IndexOf('-', startingPosition);
if (filename[dash - 1].Equals(' ') && filename[dash + 1].Equals(' '))
{
string artist = filename.Substring(0, dash - 1);
return artist;
}
startingPosition = dash + 1;
}
/*If that fails..*/
return IssueError("Can't parse artist", file);
}
default:
return IssueError("Can't parse artist", file);
}
}
catch (Exception e)
{
ew.IssueGeneralWarning("Error extracting artist", "Please report", e.Message + "\n" + e.StackTrace);
return IssueError("Can't parse artist", file);
}
}
default:
return IssueError("Can't parse artist", file);
}
}