//----------------------------------- ALBUMS --------------------------------------------------------------

        public void GetAlbums()
        {
            try
            {
                foreach (var a in Artists)
                {
                    Albums.AddRange(LastFm.GetTopAlbums(a));
                }

                Albums.RemoveAll(a => a.Name == "(null)");
                Albums.ForEach(a => a.Name    = a.Name.Replace("&", "And"));
                Albums.ForEach(a => a.SqlName = a.Name.Replace("'", "''"));

                Albums.ForEach(aa => aa.Artist.Name    = aa.Artist.Name.Replace("&", "And"));
                Albums.ForEach(aa => aa.Artist.SqlName = aa.Artist.Name.Replace("'", "''"));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Init();// this method fills the arrays above with data


            // - print the mass of the earth on July 1895 XD

            /*
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░
             *  ░░███████░░░░░░░░░░███▒▒▒▒▒▒▒▒███░░░░░░
             *  ░░█▒▒▒▒▒▒█░░░░░░░███▒▒▒▒▒▒▒▒▒▒▒▒███░░░░
             *  ░░░█▒▒▒▒▒▒█░░░░██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░
             *  ░░░░█▒▒▒▒▒█░░░██▒▒▒▒▄██▄▒▒▒▒▄██▄▒▒▒███░
             *  ░░░░░█▒▒▒█░░░█▒▒▒▒▒▒████▒▒▒▒████▒▒▒▒▒██
             *  ░░░█████████████▒▒▒▒▀██▀▒▒▒▒▀██▀▒▒▒▒▒██
             *  ░░░█▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒██
             *  ░██▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒██▒▒▒▒▒▒▒▒▒██▒▒▒▒██
             *  ██▒▒▒███████████▒▒▒▒▒██▒▒▒▒▒▒▒██▒▒▒▒▒██
             *  █▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒███████▒▒▒▒▒▒▒██
             *  ██▒▒▒▒▒▒▒▒▒▒▒▒▒▒█▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░
             *  ░█▒▒▒███████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██░░░
             *  ░██▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█░░░░░
             *  ░░████████████░░░████████████████░░░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░▄█████▄░▄███████▄░▄███████▄░██████▄░░
             *  ░░██▒▒▒▒█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░██▒▒▒▒▒░██▒▒▒▒▒██░██▒▒▒▒▒██░██▒▒▒██░░
             *  ░░██▒▒▒▀█░███▒▒▒███░███▒▒▒███░██▒▒▒██░░
             *  ░░▀█████▀░▀███████▀░▀███████▀░██████▀░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░▄█████░██▒▒▒▒██▀░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▀▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░██▒▒▒▒░██▒▒▒██░██▒▒▒▒░█████▀░░░░░░░
             *  ░░░░██▒▒▒▒░██▄▒▄██░██▄▒▒▒░██▒▒▒██░░░░░░
             *  ░░░░▀█████░▀█████▀░▀█████░██▒▒▒▒██▄░░░░
             *  ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
             */

            // QUERIES!
            foreach (Artist artist in Artists)
            {
                foreach (Album album in artist.Albums)
                {
                    Console.WriteLine($"{artist.FullName}, {artist.Albums.Count} {album.Name}");
                }
            }
            Console.WriteLine("---------------------------------");
            Albums.ForEach(album => Console.WriteLine($"{album.Name}, {album.Genre}, {album.Year}, {album.Songs.Count}"));
            Console.WriteLine("---------------------------------");
            foreach (Album album in Albums)
            {
                foreach (Song song in album.Songs)
                {
                    Console.WriteLine($"{album.Name}, {song.Name}, {song.Duration}");
                }
            }
            Console.WriteLine("---------------------------------");


            // - how many Songs start with the letter 'a' (case insensitive)

            var songsStartWithA = from song in Songs
                                  where song.Name.StartsWith('a') || song.Name.StartsWith('A')
                                  select song;

            Console.WriteLine($"{songsStartWithA.ToList().Count} songs start(s) with A");
            Console.WriteLine("---------------------------------");


            // - how many artists end with letter 'a' (case insensitive)

            var artistEndWithA = from artist in Artists
                                 where artist.FullName.EndsWith('a') || artist.FullName.EndsWith('A')
                                 select artist;

            Console.WriteLine($"{artistEndWithA.ToList().Count} artist end(s) with A");
            //artistEndWithA.ToList().ForEach(artist => Console.WriteLine(artist.FullName));
            Console.WriteLine("---------------------------------");


            // - whats the name of the song with longest duration

            var longestSong = from song in Songs
                              orderby song.Duration
                              select song.Name;

            Console.WriteLine($"The name of the longet song is {longestSong.LastOrDefault()}");
            Console.WriteLine("---------------------------------");


            // - whats the total Duration of all Songs

            var totalDuration = from song in Songs
                                select song.Duration;

            Console.WriteLine($"The total duration of all songs is {totalDuration.ToList().Sum()} seconds");
            Console.WriteLine("---------------------------------");


            // - how many albums have Songs longer than 300 seconds

            var albumsWithSongOver300 = from album in Albums
                                        from song in album.Songs
                                        where song.Duration > 300
                                        select album;

            Console.WriteLine($"{albumsWithSongOver300.Distinct().ToList().Count} album have(has) song(s) longer than 300 seconds");
            //albumsWithSongOver300.ToList().ForEach(album => Console.WriteLine(album.Name));
            Console.WriteLine("---------------------------------");


            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre

            var artistsWithPoprockAlbum = from artist in Artists
                                          from album in artist.Albums
                                          where album.Genre == Genre.PopRock
                                          select artist;

            var moreThenOne = from artist in artistsWithPoprockAlbum.Distinct().ToList()
                              where artist.Albums.Count > 1
                              select artist.FullName;

            Console.WriteLine("These artists have more than one album of PopRock genre:");
            moreThenOne.ToList().ForEach(Console.WriteLine);
            Console.WriteLine("---------------------------------");


            // - print the name of the album that has highest Average duration of a song

            var albumSongsHigherAverage = from album in Albums
                                          orderby album.Songs.ToList().Average(song => song.Duration)
                                          select album.Name;

            Console.WriteLine($"The name of the album that has highest Average duration of a song is {albumSongsHigherAverage.LastOrDefault()}");
            Console.WriteLine("---------------------------------");


            // - how many characters has the song that has the shortest Duration

            var shortestSongChars = from song in Songs
                                    orderby song.Duration
                                    select song;

            Console.WriteLine($"The shortest song has {shortestSongChars.ToList().FirstOrDefault().Name.Length} characters");
            Console.WriteLine("---------------------------------");


            // - print the name and the genre of the album that has most songs

            var albumWithMostSongs = from album in Albums
                                     orderby album.Songs.Count
                                     select album;

            Console.WriteLine($"The album that has most songs is {albumWithMostSongs.LastOrDefault().Name}," +
                              $" genre: {albumWithMostSongs.LastOrDefault().Genre}");
            Console.WriteLine("---------------------------------");


            // - print the name of the artist that has most songs

            var artistWithMostSongs = from artist in Artists
                                      from album in artist.Albums
                                      orderby artist.Albums.ToList().Sum(album => album.Songs.Count)
                                      select artist.FullName;

            Console.WriteLine($"{artistWithMostSongs.LastOrDefault()} has most songs");
            Console.WriteLine("---------------------------------");


            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000

            var artistWithMostalbumsBefore2000 = from artist in Artists
                                                 from album in artist.Albums
                                                 where album.Year < 2000
                                                 orderby artist.Albums.Count
                                                 select artist;

            Console.WriteLine(artistWithMostalbumsBefore2000.ToList().LastOrDefault().ArtistType);
            Console.WriteLine("---------------------------------");


            // - print the average song duration, of the album that has most songs

            var albumFilterMost = from album in Albums
                                  orderby album.Songs.Count
                                  select album;
            var averageSongDuration = from song in albumFilterMost.LastOrDefault().Songs
                                      select song.Duration;

            Console.WriteLine($"The average song duration of album that has most songs is {averageSongDuration.Average()} seconds");
            Console.WriteLine("---------------------------------");


            // Bonus:
            // - print the longest song duration of the album that has least songs

            var albumFilterLess = from album in Albums
                                  orderby album.Songs.Count
                                  select album;

            int least          = albumFilterLess.ToList().FirstOrDefault().Songs.Count;
            var filteredAlbums = from album in albumFilterLess
                                 where album.Songs.Count == least
                                 select album;

            var longestSongDur = from album in filteredAlbums
                                 from song in album.Songs
                                 orderby song.Duration
                                 select song.Duration;

            Console.WriteLine($"The longest song duration in the album that has least songs is {longestSongDur.LastOrDefault()} seconds");
            Console.WriteLine("---------------------------------");


            // - print the name of the album that has most songs that contain letter 'a' in the name

            var mostSongsThatContainA = from album in Albums
                                        from song in album.Songs
                                        where song.Name.Contains('a')
                                        group album by album.Name;

            var albumName = from name in mostSongsThatContainA
                            orderby name.Count()
                            select name;

            Console.WriteLine($"The name of the album that has most songs that contain letter 'a' in the name is" +
                              $" {albumName.ToList().LastOrDefault().Key}");
            //albumName.ToList().ForEach(album => Console.WriteLine(album.Key));
            Console.WriteLine("---------------------------------");


            // - print the name of the artist that has most songs that end with letter 'd'

            var mostSongsThatEndWithD = from artist in Artists
                                        from album in artist.Albums
                                        from song in album.Songs
                                        where song.Name.EndsWith('d')
                                        group artist by artist.FullName;

            var artistName = from name in mostSongsThatEndWithD
                             orderby name.Count()
                             select name;

            Console.WriteLine($"The name of the artist that has most songs that end with letter 'd' is " +
                              $"{artistName.ToList().LastOrDefault().Key}");
            //artistName.ToList().ForEach(artist => Console.WriteLine(artist.Key));


            // ************ Don't mind the structure, focus on the lists declared on the beginning of Program.cs ****************

            // 3, 2, 1.... GO! :)



            Console.ReadLine();
        }