public async Task <TopWordsResult> TopWordsAsync([FromBody] TopWordsParams topWordsParams) { if (topWordsParams == null) { throw new ArgumentNullException(nameof(topWordsParams)); } return(await _lyricsService.GetTopWordsFromArtistLyrics(topWordsParams)); }
public async Task <TopWordsResult> GetTopWordsFromArtistLyrics(TopWordsParams topWordsParams) { _logger.LogInformation($"Looking for artist with Id {topWordsParams.ArtistId}"); await NotifyClient(topWordsParams.ConnectionId, "Starting.."); if (TopWordsFileExists(topWordsParams.ArtistId)) { _logger.LogInformation("File found, done!"); return(GetTopWordsFromFile(topWordsParams.ArtistId)); } var songsPageInfo = await _crawlerService.GetSongsPageInfo(topWordsParams.ArtistId); if (songsPageInfo.SongsUrls.Count == 0) { _logger.LogInformation("No songs found"); return(new TopWordsResult(message: "No songs were found..")); } _logger.LogInformation($"{songsPageInfo.SongsUrls.Count} songs urls found"); await NotifyClient(topWordsParams.ConnectionId, $"{songsPageInfo.SongsUrls.Count} songs urls found"); for (int i = 0; i < songsPageInfo.SongsUrls.Take(_apiSettings.CrawlSongsCount).Count(); i++) { _logger.LogInformation($"Crawling song #{i + 1} from {songsPageInfo.ArtistName}.."); await NotifyClient(topWordsParams.ConnectionId, $"Crawling song #{i + 1} from {songsPageInfo.ArtistName}.."); string songLyrics = await _crawlerService.GetSongLyrics(songsPageInfo.SongsUrls[i]); _artistLyrics.Add(songLyrics); } _logger.LogInformation("Analyzing.."); await NotifyClient(topWordsParams.ConnectionId, "Analyzing.."); var topWords = _wordFrequencyService.GetWordsFrequencies(_artistLyrics); var result = new TopWordsResult(artist: new Artist(topWordsParams.ArtistId, songsPageInfo.ArtistName), message: "OK", words: topWords); await SaveTopWordsToFile(result); _logger.LogInformation("Done!"); return(result); }
public async Task <IActionResult> TopWordsAsync([FromBody] TopWordsParams topWordsParams) { var result = await _topWordsController.TopWordsAsync(topWordsParams); return(Ok(result)); }