Esempio n. 1
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;
        }
Esempio n. 2
0
        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);
                }
            }
        }