/// <summary> /// Retries the current song mapping. /// </summary> /// <param name="song">The song.</param> public void RetryCurrentSongMapping(YouTubeGroovesharkSong song) { GroovesharkService groovesharkService = new GroovesharkService(); this.MapYouTubeArtistToGroovesharkArtist(groovesharkService, song); this.MapYouTubeSongTitleToGroovesharkSongTitle(groovesharkService, song); }
/// <summary> /// Handles the Click event of the btnRetry control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void btnRetry_Click(object sender, RoutedEventArgs e) { YouTubeGroovesharkSong selectedSong = (YouTubeGroovesharkSong)dgSongs.SelectedItem; if (selectedSong != null) { this.YouTubeSongsImportViewModel.RetryCurrentSongMapping(selectedSong); } }
/// <summary> /// Maps you tube song title to grooveshark song title. /// </summary> /// <param name="groovesharkService">The grooveshark service.</param> /// <param name="currentSong">The current song.</param> private void MapYouTubeSongTitleToGroovesharkSongTitle(GroovesharkService groovesharkService, YouTubeGroovesharkSong currentSong) { string searchName = currentSong.YouTubeSongTitle; string songTitle = string.Empty; int songId = default(int); bool shouldBreak = false; do { GetSongSearchResults.Result songsResult = null; searchName = this.TrimSpecialCharacters(searchName); if (currentSong.YouTubeArtist != null) { songsResult = groovesharkService.GetSongSearchResults(searchName, limit: 20); } if (songsResult == null || songsResult.songs == null || songsResult.songs.Count == 0) { searchName = GetNewSearchSongName(searchName, out shouldBreak); if (shouldBreak) { break; } continue; } songTitle = string.Empty; songId = default(int); var query = songsResult.songs.Where(x => x != null && x.SongName != null && x.SongName.ToLower().Contains(searchName.Trim().ToLower())); if (query.Count() > 0) { var searchedSong = query.FirstOrDefault(s => s.ArtistID.Equals(currentSong.GroovesharkArtistId)); if (searchedSong != null) { songTitle = searchedSong.SongName; songId = searchedSong.SongID; } } if (!string.IsNullOrEmpty(songTitle)) { break; } searchName = GetNewSearchSongName(searchName, out shouldBreak); if (shouldBreak) { break; } }while (string.IsNullOrEmpty(songTitle)); if (string.IsNullOrEmpty(songTitle) && songId == 0) { searchName = currentSong.YouTubeSongTitle; searchName = this.TrimSpecialCharacters(searchName); GetSongSearchResults.Result popularSongs = groovesharkService.GetArtistPopularSongs(currentSong.GroovesharkArtistId); songTitle = string.Empty; songId = default(int); do { var query = popularSongs.songs.Where(x => x != null && x.SongName != null && x.SongName.ToLower().Contains(searchName.Trim().ToLower())); if (query.Count() > 0) { var searchedSong = query.FirstOrDefault(); if (searchedSong != null) { songTitle = searchedSong.SongName; songId = searchedSong.SongID; } } if (!string.IsNullOrEmpty(songTitle)) { break; } searchName = GetNewSearchSongName(searchName, out shouldBreak); if (shouldBreak) { break; } }while (string.IsNullOrEmpty(songTitle)); } if (!string.IsNullOrEmpty(songTitle) && songId != 0) { currentSong.GroovesharkSongTitle = songTitle; currentSong.GroovesharkSongId = songId; } }
/// <summary> /// Maps you tube artist to grooveshark artist. /// </summary> /// <param name="groovesharkService">The grooveshark service.</param> /// <param name="currentSong">The current song.</param> private void MapYouTubeArtistToGroovesharkArtist(GroovesharkService groovesharkService, YouTubeGroovesharkSong currentSong) { Artist.Result artistResult = null; if (currentSong.YouTubeArtist != null) { artistResult = groovesharkService.GetArtistSearchResults(currentSong.YouTubeArtist, 5); } if (artistResult == null || artistResult.artists.Count == 0) { return; } string artistName = string.Empty; int artistId = default(int); var query = artistResult.artists.Where(x => x != null && x.ArtistName.ToLower().Equals(currentSong.YouTubeArtist.Trim().ToLower())); if (query.Count() > 0) { artistName = query.FirstOrDefault().ArtistName; artistId = query.FirstOrDefault().ArtistID; } if (string.IsNullOrEmpty(artistName)) { query = artistResult.artists.Where(x => x != null && x.IsVerified.Equals(true)); if (query.Count() > 0) { artistName = query.FirstOrDefault().ArtistName; artistId = query.FirstOrDefault().ArtistID; } } if (string.IsNullOrEmpty(artistName)) { artistName = artistResult.artists.FirstOrDefault().ArtistName; artistId = artistResult.artists.FirstOrDefault().ArtistID; } currentSong.GroovesharkArtist = artistName; currentSong.GroovesharkArtistId = artistId; }