我正在通过抓取音乐节的网站艺术家页面来创建Spotify播放列表生成器。我可以返回所有艺术家的姓名,但是其中一些没有链接到Spotify搜索字词,例如:
Festival Artist Name: "Slash and..."
Spotify Search Term: "Slash"
我创建了一个名为EdgeCases
的对象:
public int EdgeCasesID { get; set; }
public int FestivalID { get; set; }
public string ComparableString { get; set; }
public string SearchTerm { get; set; }
public bool Skip { get; set; }
它代表替换/跳过/搜索与该Spotify搜索词不完全匹配的该艺术家所需的所有数据。
我目前拥有的代码将所有边缘情况与从网页中提取的所有艺术家进行比较;我只需要有关减少代码+比较的帮助
foreach (string artist in artistNames)
{
bool skipArtist = false;
SearchItem searchItem = null;
// Check if any of those artists exist in the UnfoundArtists database
// More or less check if the name is different on Spotify or if they are even on Spotify
foreach (EdgeCase unfoundArtist in EdgeCases)
{
// If the download artist page contains the a specific name
// e.g if 'slash & the conspirators' contains 'slash'
if (artist.Trim().Contains(unfoundArtist.ComparableString))
{
// If so, check if the artist is on Spotify
if (unfoundArtist.ToSearch)
{
// search using SearchTerm
}
// This case is if the artist is on the page but not on Spotify
skipArtist = true;
}
else
{
// Search the artist if there is no edge case - different Spotify
// name/on Spotify at all etc
searchItem = _api.SearchItems(artist.Trim(), SearchType.Artist, limit: 1);
}
}
}