コード例 #1
0
ファイル: Program.cs プロジェクト: kennedykinyanjui/Projects
        static void Main(string[] args)
        {
            List<string> playListSongs = new List<string>();
            playListSongs = YouTubeServiceClient.Instance.GetPlayListSongs("*****@*****.**", "PL1CTk64TxYtCwLKL1FAT9H8BG4fcyK2I3");
            Regex regexNamespaceInitializations = new Regex(RegexSongPattern, RegexOptions.None);
            List<Song> songs = new List<Song>();
            foreach (string currentPlayListSong in playListSongs)
            {
                System.Console.WriteLine(currentPlayListSong);
                Match m = regexNamespaceInitializations.Match(currentPlayListSong);
                if (m.Success)
                {
                    songs.Add(new Song(m.Groups["Artist"].ToString(), m.Groups["Name"].ToString()));
                }
            }
            GroovesharkService groovesharkService = new GroovesharkService();
            Session.Result sessionResult = groovesharkService.StartSession();
            StreamWriter writer = new StreamWriter("whatIsFound.txt", false, Encoding.UTF8, 10);
            using(writer)
            {
                foreach (Song currentSong in songs)
                {
                    Artist.Result artistResult = null;
                    if (currentSong.Artist != null)
                    {
                        artistResult = groovesharkService.GetArtistSearchResults(currentSong.Artist, 5);
                    }
                    if (artistResult == null || artistResult.artists.Count == 0)
                    {
                        string strToWrite = string.Format("Artist: {0} Name: {1} NOT FOUND G", currentSong.Artist, currentSong.Name);
                        System.Console.WriteLine(strToWrite);
                        writer.WriteLine(strToWrite);
                        continue;
                    }
                    string artistName = string.Empty;
                    var query = artistResult.artists.Where(x => x != null && x.ArtistName.Equals(currentSong.Artist));
                    if (query.Count() > 0)
                    {
                        artistName = query.FirstOrDefault().ArtistName;
                    }
                    if (string.IsNullOrEmpty(artistName))
                    {
                        query = artistResult.artists.Where(x => x != null && x.IsVerified.Equals(true));
                        if (query.Count() > 0)
                        {
                            artistName = query.FirstOrDefault().ArtistName;
                        }
                    }
                    else
                    {
                        artistName = artistResult.artists.FirstOrDefault().ArtistName;
                    }

                    string strToWrite1 = string.Format("Artist: {0} Name: {1} Found On G: {2}", currentSong.Artist, currentSong.Name, artistName);
                    System.Console.WriteLine(strToWrite1);
                    writer.WriteLine(strToWrite1);
                }  
            }
            
        }    
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
 /// <summary>
 /// Maps the songs titles.
 /// </summary>
 /// <param name="songsToMap">The songs to map.</param>
 /// <param name="groovesharkService">The grooveshark service.</param>
 private void MapSongsTitles(List<YouTubeGroovesharkSong> songsToMap, GroovesharkService groovesharkService)
 {
     foreach (YouTubeGroovesharkSong currentSong in songsToMap)
     {
         if (string.IsNullOrEmpty(currentSong.GroovesharkArtist) || currentSong.GroovesharkArtistId == 0)
         {
             continue;
         }
         this.MapYouTubeSongTitleToGroovesharkSongTitle(groovesharkService, currentSong);
     }
 }
コード例 #4
0
        /// <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;
        }
コード例 #5
0
 /// <summary>
 /// Maps the songs artists.
 /// </summary>
 /// <param name="songsToMap">The songs to map.</param>
 /// <param name="groovesharkService">The grooveshark service.</param>
 private void MapSongsArtists(List<YouTubeGroovesharkSong> songsToMap, GroovesharkService groovesharkService)
 {
     foreach (YouTubeGroovesharkSong currentSong in songsToMap)
     {
         this.MapYouTubeArtistToGroovesharkArtist(groovesharkService, currentSong);
     }
 }
コード例 #6
0
 /// <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);
 }
コード例 #7
0
        /// <summary>
        /// Maps you tube songs to grooveshark.
        /// </summary>
        /// <param name="songsToMap">The songs to map.</param>
        /// <returns></returns>
        public List<YouTubeGroovesharkSong> MapYouTubeSongsToGrooveshark(List<YouTubeGroovesharkSong> songsToMap)
        {
            GroovesharkService groovesharkService = new GroovesharkService();
            this.MapSongsArtists(songsToMap, groovesharkService);
            this.MapSongsTitles(songsToMap, groovesharkService);

            return songsToMap;
        }