public async Task <ApiResponse <AddSongResponse> > AddSong([FromBody] AddSongRequest request) { if (request == null || !this.ModelState.IsValid) { return(this.ModelStateErrors <AddSongResponse>()); } var splitter = new SongNameSplitter(); // TODO: Move to constructor var artists = splitter.SplitArtistName(request.Artists).ToList(); var songId = await this.songsService.CreateSongAsync(request.SongName, artists, SourcesNames.User, this.User.GetId()); var song = new SongArtistsAndTitle(artists, request.SongName); await this.songsService.UpdateSongsSystemDataAsync(songId); return(new AddSongResponse { Id = songId, SongTitle = song.ToString() }.ToApiResponse()); }
public async Task <ApiResponse <AddSongResponse> > AddSong([FromBody] AddSongRequest request) { if (request == null || !this.ModelState.IsValid) { return(this.ModelStateErrors <AddSongResponse>()); } var artists = this.songNameSplitter.SplitArtistName(request.Artists).ToList(); var songId = await this.songsService.CreateSongAsync(request.SongName, artists, SourcesNames.User, this.User.GetId()); var song = new SongArtistsAndTitle(artists, request.SongName); // Find video if available var videoId = this.youTubeDataProvider.SearchVideo(string.Join(" ", song.Artists), song.Title); if (videoId != null) { await this.songMetadataService.AddMetadataInfoAsync( songId, new SongAttributes(SongMetadataType.YouTubeVideoId, videoId), SourcesNames.YouTube, null); } // Find lyrics if available var lyrics = this.lyricsPluginDataProvider.GetLyrics(song.Artist, song.Title); if (!string.IsNullOrWhiteSpace(lyrics)) { await this.songMetadataService.AddMetadataInfoAsync( songId, new SongAttributes(SongMetadataType.Lyrics, lyrics), SourcesNames.LyricsPlugin, null); } await this.songsService.UpdateSongsSystemDataAsync(songId); return(new AddSongResponse { Id = songId, SongTitle = song.ToString() }.ToApiResponse()); }