Ejemplo n.º 1
0
        public async Task RemoveMediaFromCollectionAndDatabase(IMediaItem media)
        {
            if (media is TrackItem)
            {
                var trackItem = media as TrackItem;
                var trackDB   = LoadTrackById(trackItem.Id);
                if (trackDB == null)
                {
                    return;
                }
                musicDatabase.Remove(trackDB);

                var albumDB = LoadAlbum(trackItem.AlbumId);
                if (albumDB == null)
                {
                    return;
                }
                var albumTracks = LoadTracksByAlbumId(albumDB.Id);
                if (!albumTracks.Any())
                {
                    Albums.Remove(Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId));
                    musicDatabase.Remove(albumDB);
                }

                var artistDB = LoadArtist(trackItem.ArtistId);
                if (artistDB == null)
                {
                    return;
                }
                var artistAlbums = LoadAlbums(artistDB.Id);
                if (!artistAlbums.Any())
                {
                    Artists.Remove(Artists.FirstOrDefault(x => x.Id == trackItem.ArtistId));
                    musicDatabase.Remove(artistDB);
                }

                await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () =>
                {
                    Tracks.Remove(Tracks.FirstOrDefault(x => x.Path == trackItem.Path));

                    var playingTrack = Locator.MediaPlaybackViewModel.PlaybackService.Playlist.FirstOrDefault(x => x.Id == trackItem.Id);
                    if (playingTrack != null)
                    {
                        Locator.MediaPlaybackViewModel.PlaybackService.Playlist.Remove(playingTrack);
                    }
                });
            }
            else if (media is VideoItem)
            {
                var videoItem = media as VideoItem;
                var videoDb   = LoadVideoById(videoItem.Id);
                if (videoDb == null)
                {
                    return;
                }
                videoDatabase.Remove(videoDb);

                Videos.Remove(Videos.FirstOrDefault(x => x.Path == videoItem.Path));
            }
        }
Ejemplo n.º 2
0
        private void DeleteRelatedObjects(Track track)
        {
            var displaySameAsAlbumArtist = track.DisplayArtist.EqualsIgnoreCase(track.AlbumArtist);

            var albumArtist = Artists.FirstOrDefault(p =>
                                                     p.Name.EqualsIgnoreCase(track.AlbumArtist));

            if (albumArtist != null)
            {
                albumArtist.Tracks.Remove(track);
                if (albumArtist.Tracks.Count == 0 && albumArtist.TracksThatAppearsIn.Count == 0)
                {
                    Artists.Remove(albumArtist);
                }
            }

            DeleteAlbum(track, albumArtist);

            if (!displaySameAsAlbumArtist)
            {
                DeleteDisplayArtist(track);
            }

            DeleteSecondaryArtists(track);
        }
Ejemplo n.º 3
0
        private void CreateDisplayArtist(Track track)
        {
            var displayArtist = Artists.FirstOrDefault(p =>
                                                       p.Name.EqualsIgnoreCase(track.DisplayArtist));
            var newRelation = displayArtist == null;

            if (newRelation)
            {
                displayArtist = new Artist
                {
                    Name       = track.DisplayArtist,
                    ArtworkUri = track.ArtistArtworkUri
                };
            }
            else if (displayArtist.ArtworkUri == null)
            {
                displayArtist.ArtworkUri = track.ArtistArtworkUri;
            }

            displayArtist.Tracks.Add(track);
            if (newRelation)
            {
                Artists.Add(displayArtist);
            }
        }
Ejemplo n.º 4
0
        private async Task LoadArtists()
        {
            OnTaskStarted("artists");

            try
            {
                var artists = await ServiceLocator.LocalMusicService.GetArtists();

                if (artists.IsNullOrEmpty())
                {
                    OnTaskError("artists", ErrorResources.LoadArtistsErrorEmpty);
                }
                else
                {
                    Artists        = artists.OrderBy(a => a.Title).ToList();
                    SelectedArtist = Artists.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                OnTaskError("artists", ErrorResources.LoadArtistsErrorCommon);

                LoggingService.Log(ex);
            }

            OnTaskFinished("artists");
        }
Ejemplo n.º 5
0
        public async Task DeleteSongAsync(Song song)
        {
            // remove it from artist and albums songs
            var artist = Artists.FirstOrDefault(p => p.Songs.Contains(song));
            var album  = Albums.FirstOrDefault(p => p.Songs.Contains(song));

            if (album != null)
            {
                album.Songs.Remove(song);
                if (album.Songs.Count == 0)
                {
                    await _sqlService.DeleteItemAsync(album);

                    Albums.Remove(album);
                }
            }

            if (artist != null)
            {
                artist.Songs.Remove(song);
                if (artist.Songs.Count == 0)
                {
                    await _sqlService.DeleteItemAsync(artist);

                    Artists.Remove(artist);
                }
            }

            //good, now lets delete it from the db
            await _sqlService.DeleteItemAsync(song);

            Songs.Remove(song);
        }
Ejemplo n.º 6
0
        private void FilterArtists()
        {
            Artists = GetTrackOrAlbumArtists(true, true).ToList();

            if (SelectedArtist == null)
            {
                SelectedArtist = Artists.FirstOrDefault();
            }
        }
Ejemplo n.º 7
0
        private void DeleteDisplayArtist(Track track)
        {
            var displayArtist = Artists.FirstOrDefault(p =>
                                                       p.Name.EqualsIgnoreCase(track.DisplayArtist));

            displayArtist.Tracks.Remove(track);
            if (displayArtist.TracksThatAppearsIn.Count == 0 && displayArtist.Tracks.Count == 0)
            {
                Artists.Remove(displayArtist);
            }
        }
Ejemplo n.º 8
0
        private void CreateSecondaryArtists(Track track)
        {
            var artistAppearing = track.Artists.Split(';').Select(p => p.Trim());

            foreach (var artistName in artistAppearing
                     .Where(p => !p.EqualsIgnoreCase(track.DisplayArtist) &&
                            !p.EqualsIgnoreCase(track.AlbumArtist)))
            {
                var artist = Artists.FirstOrDefault(p =>
                                                    p.Name.EqualsIgnoreCase(artistName));
                if (artist == null)
                {
                    artist = new Artist
                    {
                        Name = artistName
                    };
                    Artists.Add(artist);
                }

                artist.TracksThatAppearsIn.Add(track);
            }
        }
Ejemplo n.º 9
0
        private void CreateRelatedObjects(Track track)
        {
            var displaySameAsAlbumArtist = track.DisplayArtist.EqualsIgnoreCase(track.AlbumArtist);

            var albumArtist = Artists.FirstOrDefault(p =>
                                                     p.Name.EqualsIgnoreCase(track.AlbumArtist));
            var newRelation = albumArtist == null;

            if (newRelation)
            {
                albumArtist = new Artist
                {
                    Name       = track.AlbumArtist,
                    ArtworkUri = track.AlbumArtist == track.DisplayArtist ? track.ArtistArtworkUri : null
                };
            }
            else if (albumArtist.ArtworkUri == null && displaySameAsAlbumArtist)
            {
                albumArtist.ArtworkUri = track.ArtistArtworkUri;
            }

            albumArtist.Tracks.Add(track);
            if (newRelation)
            {
                Artists.Add(albumArtist);
            }

            CreateAlbum(track, albumArtist);

            if (!displaySameAsAlbumArtist)
            {
                CreateDisplayArtist(track);
            }

            CreateSecondaryArtists(track);
        }
Ejemplo n.º 10
0
 public Artist GetArtist(string name)
 {
     return(Artists.FirstOrDefault(a => String.Equals(a.Name, name)));
 }
Ejemplo n.º 11
0
 public virtual ArtistForSong GetArtistLink(Artist artist)
 {
     return(Artists.FirstOrDefault(a => a.Artist != null && a.Artist.Equals(artist)));
 }
Ejemplo n.º 12
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!

            // - how many Songs start with the letter 'a' (case insensitive)
            // - how many artists end with letter 'a' (case insensitive)
            // - whats the name of the song with longest duration
            // - whats the total Duration of all Songs
            // - how many albums have Songs longer than 300 seconds
            // - print the names of the artists(separated with "--"), that have more than one album of PopRock genre
            // - print the name of the album that has highest Average duration of a song
            // - how many characters has the song that has the shortest Duration
            // - print the name and the genre of the album that has most songs
            // - print the name of the artist that has most songs
            // - print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            // - print the average song duration, of the album that has most songs

            // Bonus:
            // - print the longest song duration of the album that has least songs
            // - print the name of the album that has most songs that contain letter 'a' in the name
            // - print the name of the artist that has most songs that end with letter 'd'



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

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

            //How many Songs start with the letter 'a'(case insensitive)  ?????????????????????????
            Console.WriteLine("1.How many Songs start with the letter 'a'(case insensitive)");
            List <Song> songsStartWithA = Songs
                                          .Where(song => song.Name.ToLower()
                                                 .StartsWith("a"))
                                          .ToList();

            Console.WriteLine(songsStartWithA.Count);

            //How many artists end with letter 'a'(case insensitive)
            Console.WriteLine("2.How many artists end with letter 'a'(case insensitive)");
            List <Artist> songsEndWithA = Artists
                                          .Where(song => song.FullName.ToLower()
                                                 .EndsWith("a"))
                                          .ToList();

            Console.WriteLine(songsEndWithA.Count);

            //Whats the name of the song with longest duration
            Console.WriteLine("3.Whats the name of the song with longest duration");
            Song longestSong = Songs
                               .FirstOrDefault(song => song.Duration == Songs
                                               .Select(s => s.Duration)
                                               .Max());

            Console.WriteLine($"{longestSong.Name}");

            // whats the total Duration of all Songs
            Console.WriteLine("4.Whats the total Duration of all Songs");
            int totalDurationSong = Songs
                                    .Select(s => s.Duration)
                                    .Sum();

            Console.WriteLine(totalDurationSong);

            // how many albums have Songs longer than 300 seconds
            Console.WriteLine("5.how many albums have Songs longer than 300 seconds");
            int songsLonger = Albums
                              .Where(a => a.Songs
                                     .Any(s => s.Duration > 300))
                              .Count();

            Console.WriteLine(songsLonger);


            // Print the names of the artists separated with --, that have more than one album of PopRock genre
            Console.WriteLine("6.Print the names of the artists separated with --, that have more than one album of PopRock genre");
            List <string> namesPopRockArtists = Artists
                                                .Where(x => x.Albums.Count > 1)
                                                .Where(artist => artist.Albums
                                                       .Any(album => album.Genre == Genre.PopRock))
                                                .Select(n => n.FullName)
                                                .ToList();

            namesPopRockArtists.ForEach(artist => Console.Write($"{artist} -- "));
            Console.WriteLine("\n");

            //Print the name of the album that has highest Average duration of a song
            Console.WriteLine("7.Print the name of the album that has highest Average duration of a song");
            Album higestAverage = Albums
                                  .FirstOrDefault(album => album.Songs
                                                  .Select(song => song.Duration).Average() == Albums
                                                  .Select(a => a.Songs
                                                          .Select(s => s.Duration).Average())
                                                  .Max());

            Console.WriteLine(higestAverage.Name);

            //how many characters has the song that has the shortest Duration
            Console.WriteLine("8.how many characters has the song that has the shortest Duration");
            Song songChar = Songs
                            .FirstOrDefault(song => song.Duration == Songs
                                            .Select(s => s.Duration)
                                            .Min());

            Console.WriteLine(songChar.Name.Count());

            //print the name and the genre of the album that has most songs
            Console.WriteLine("9.Print the name and the genre of the album that has most songs");
            Album genreMostSongsAlbum = Albums
                                        .FirstOrDefault(album => album.Songs.Count == Albums
                                                        .Select(a => a.Songs.Count)
                                                        .Max());

            Console.WriteLine($"{genreMostSongsAlbum.Name} - Genre:{genreMostSongsAlbum.Genre}");

            //print the name of the artist that has most songs
            Console.WriteLine("10.Print the name of the artist that has most songs");
            Artist mostSongs = Artists
                               .FirstOrDefault(artist => artist.Albums
                                               .Select(album => album.Songs.Count).Sum() == Artists
                                               .Select(a => a.Albums
                                                       .Select(al => al.Songs.Count).Sum())
                                               .Max());

            Console.WriteLine($"{mostSongs.FullName}");

            // Print the type of the artist(SoloArtist/Band) that has most albums published before year 2000
            Console.WriteLine("11.Print the type of the artist(SoloArtist / Band) that has most albums published before year 2000");
            Artist mostOldAlbums = Artists
                                   .FirstOrDefault(artist => artist.Albums.Count(al => al.Year < 2000) == Artists
                                                   .Select(a => a.Albums.Count(alb => alb.Year < 2000))
                                                   .Max());

            Console.WriteLine($"Name: {mostOldAlbums.FullName} - type: {mostOldAlbums.ArtistType}");

            //Print the average song duration, of the album that has most songs
            Console.WriteLine("12. Print the average song duration, of the album that has most songs");
            double songAverageDuration = Albums
                                         .FirstOrDefault(album => album.Songs.Count == Albums
                                                         .Select(a => a.Songs.Count)
                                                         .Max())
                                         .Songs
                                         .Select(song => song.Duration)
                                         .Average();

            Console.WriteLine(songAverageDuration);

            //Print the longest song duration of the album that has least songs
            Console.WriteLine("13.Print the longest song duration of the album that has least songs");
            Song longestSongDuration = Albums
                                       .FirstOrDefault(album => album.Songs.Count == Albums.Select(alb => alb.Songs.Count)
                                                       .Min())
                                       .Songs.FirstOrDefault(song => song.Duration == Albums
                                                             .Where(al => al.Songs.Count() == Albums
                                                                    .Select(s => s.Songs.Count())
                                                                    .Min())
                                                             .FirstOrDefault().Songs.Select(sg => sg.Duration)
                                                             .Max());

            Console.WriteLine($"Name: {longestSongDuration.Name}, Duration: {longestSongDuration.Duration}");

            //Print the name of the album that has most songs that contain letter 'a' in the name
            Console.WriteLine("14.Print the name of the album that has most songs that contain letter 'a' in the name");
            Album songsMostA = Albums
                               .FirstOrDefault(album => album.Songs
                                               .Where(song => song.Name.ToLower().Contains('a')).Count() == Albums
                                               .Select(al => al.Songs
                                                       .Where(s => s.Name.ToLower().Contains('a')).Count())
                                               .Max());

            Console.WriteLine($"Album name: {songsMostA.Name}");

            //Print the name of the artist that has most songs that end with letter 'd'
            Console.WriteLine("15.Print the name of the artist that has most songs that end with letter 'd'");
            Artist songsEndsD = Artists
                                .FirstOrDefault(artist => artist.Albums
                                                .Select(album => album.Songs
                                                        .Where(song => song.Name.ToLower().EndsWith('d')).Count()).Sum() == Artists
                                                .Select(ar => ar.Albums
                                                        .Select(al => al.Songs
                                                                .Where(s => s.Name.ToLower().EndsWith('d')).Count())
                                                        .Sum())
                                                .Max());

            Console.WriteLine($"Name of the artist: {songsEndsD.FullName}'");

            Console.ReadLine();
        }
Ejemplo n.º 13
0
 public Artist GetArtistByName(string name)
 {
     return(Artists.FirstOrDefault(x => x.Name.Contains(name)));
 }
Ejemplo n.º 14
0
        public async Task AddSongAsync(Song song, string artworkUrl)
        {
            if (Songs.Count(p => p.ProviderId == song.ProviderId) > 0)
            {
                throw new Exception("AlreadySavedToast".FromLanguageResource());
            }

            #region create artist

            if (song.Artist.ProviderId == "lastid.")
            {
                song.Artist.ProviderId = "autc.single." + song.ProviderId;
            }

            var artist = Artists.FirstOrDefault(entry => entry.ProviderId == song.Artist.ProviderId);

            if (artist == null)
            {
                await _sqlService.InsertAsync(song.Artist);

                if (song.Album != null)
                {
                    song.Album.PrimaryArtistId = song.Artist.Id;
                }
                Artists.Insert(0, song.Artist);
            }

            else
            {
                song.Artist = artist;

                if (song.Album != null)
                {
                    song.Album.PrimaryArtistId = artist.Id;
                }
            }
            song.ArtistId = song.Artist.Id;

            #endregion

            #region create album

            if (song.Album == null)
            {
                song.Album = new Album
                {
                    PrimaryArtistId = song.ArtistId,
                    Name            = song.Name + " (Single)",
                    PrimaryArtist   = song.Artist,
                    ProviderId      = "autc.single." + song.ProviderId
                };
                await _sqlService.InsertAsync(song.Album);

                Albums.Insert(0, song.Album);
                song.Artist.Albums.Insert(0, song.Album);
            }
            else
            {
                var album = Albums.FirstOrDefault(p => p.ProviderId == song.Album.ProviderId);

                if (album != null)
                {
                    song.Album = album;
                }
                else
                {
                    await _sqlService.InsertAsync(song.Album);

                    Albums.Insert(0, song.Album);
                    song.Artist.Albums.Insert(0, song.Album);
                }
            }

            song.AlbumId = song.Album.Id;

            #endregion

            #region Download artwork

            if (artworkUrl != null)
            {
//Use the album if one is available
                var filePath = string.Format(CollectionConstant.ArtworkPath, song.Album.Id);

                //Check if the album artwork has already been downloaded
                var artworkExists = await StorageHelper.FileExistsAsync(filePath);

                if (!artworkExists)
                {
                    try
                    {
                        using (var client = new HttpClient())
                        {
                            using (var stream = await client.GetStreamAsync(artworkUrl))
                            {
                                using (
                                    var fileStream =
                                        await
                                            (await StorageHelper.CreateFileAsync(filePath)).OpenStreamForWriteAsync()
                                    )
                                {
                                    await stream.CopyToAsync(fileStream);

                                    //now set it
                                    song.Album.Artwork =
                                        new BitmapImage(new Uri(CollectionConstant.LocalStorageAppPath + filePath));
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine("Some shit happened saving the artwork, here: " + e);
                    }
                }
            }

            if (song.Album.Artwork == null)
            {
                song.Album.Artwork = CollectionConstant.MissingArtworkImage;
            }

            #endregion

            //Insert to db
            await _sqlService.InsertAsync(song);

            song.Artist.Songs.Insert(0, song);
            song.Album.Songs.Insert(0, song);
            Songs.Insert(0, song);
        }
        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!

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

            List <Song> songStartA = Songs
                                     .Where(song => song.Name.ToLower()
                                            .StartsWith("a"))
                                     .ToList();

            Console.WriteLine($"1) Number od songs that start with the letter 'a' is: {songStartA.Count}");
            Console.WriteLine("");

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

            List <Artist> artistEndA = Artists
                                       .Where(artist => artist.FullName.ToLower()
                                              .EndsWith("a"))
                                       .ToList();

            Console.WriteLine($"2) Number of artist that end with letter 'a' is: {artistEndA.Count}");
            Console.WriteLine("");

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

            Song longestSong = Songs
                               .FirstOrDefault(song => song.Duration == Songs
                                               .Select(sg => sg.Duration)
                                               .Max());

            Console.WriteLine($"3) The name of the song with the largest duration is: {longestSong.Name}");
            Console.WriteLine("");

            // - whats the total Duration of all Songs

            int totalDuration = Songs
                                .Select(song => song.Duration)
                                .Sum();

            Console.WriteLine($"4) The total duration of all songs is: {totalDuration} seconds");
            Console.WriteLine("");

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

            int longSongAlbums = Albums
                                 .Where(album => album.Songs
                                        .Any(song => song.Duration > 300))
                                 .Count();

            Console.WriteLine($"5) Number of albums that have Songs longer than 300 seconds is {longSongAlbums}");
            Console.WriteLine("");

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

            List <string> popRockArtists = Artists
                                           .Where(artist => artist.Albums
                                                  .Any(album => album.Genre == Genre.PopRock))
                                           .Where(x => x.Albums.Count() > 1)
                                           .Select(name => name.FullName)
                                           .ToList();

            Console.WriteLine("6) Names of artists with more than one PopRock album:");
            popRockArtists.ForEach(artist => Console.Write($"{artist} -- "));
            Console.WriteLine("");
            Console.WriteLine("");


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

            Album albumHigestAverage = Albums
                                       .FirstOrDefault(album => album.Songs
                                                       .Select(song => song.Duration).Average() == Albums
                                                       .Select(alb => alb.Songs
                                                               .Select(sg => sg.Duration).Average())
                                                       .Max());

            Console.WriteLine($"7) Name of the album that has highest Average duration of a song is: {albumHigestAverage.Name}");
            Console.WriteLine("");

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


            Song shortSongChar = Songs
                                 .FirstOrDefault(song => song.Duration == Songs
                                                 .Select(sg => sg.Duration)
                                                 .Min());

            Console.WriteLine($"8) The song that has the shortest Duration is called '{shortSongChar.Name}' and has {shortSongChar.Name.Count()} characters");
            Console.WriteLine("");

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

            Album mostSongsAlbun = Albums
                                   .FirstOrDefault(album => album.Songs.Count == Albums
                                                   .Select(alb => alb.Songs.Count)
                                                   .Max());

            Console.WriteLine($"9) Name of album that has most songs {mostSongsAlbun.Name} - Genre: {mostSongsAlbun.Genre}");
            Console.WriteLine("");

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

            Artist mostSongsArtist = Artists
                                     .FirstOrDefault(artist => artist.Albums
                                                     .Select(album => album.Songs.Count).Sum() == Artists
                                                     .Select(ar => ar.Albums
                                                             .Select(al => al.Songs.Count).Sum())
                                                     .Max());

            Console.WriteLine($"10) Name of artist with most songs: {mostSongsArtist.FullName}");
            Console.WriteLine("");

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

            Artist mostOldAlbums = Artists
                                   .FirstOrDefault(artist => artist.Albums.Count(alb => alb.Year < 2000) == Artists
                                                   .Select(ar => ar.Albums.Count(al => al.Year < 2000))
                                                   .Max());

            Console.WriteLine($"11) Type of the artist(SoloArtist/Band) that has most albums published before year 2000: {mostOldAlbums.ArtistType}");
            Console.WriteLine($"Name of artist(SoloArtist/Band): {mostOldAlbums.FullName}");
            Console.WriteLine("");

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

            double mostSongAlbAverDur = Albums
                                        .FirstOrDefault(album => album.Songs.Count == Albums
                                                        .Select(alb => alb.Songs.Count).Max())
                                        .Songs
                                        .Select(song => song.Duration)
                                        .Average();

            Console.WriteLine($"12) Average song duration, of the album that has most songs: {mostSongAlbAverDur}");
            Console.WriteLine("");

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

            Song longSongShortAlbum = Albums
                                      .FirstOrDefault(album => album.Songs.Count == Albums.Select(alb => alb.Songs.Count).Min())
                                      .Songs.FirstOrDefault(song => song.Duration == Albums
                                                            .Where(al => al.Songs.Count() == Albums
                                                                   .Select(x => x.Songs.Count())
                                                                   .Min())
                                                            .FirstOrDefault().Songs.Select(sg => sg.Duration).Max());


            Console.WriteLine($"13) The longest song duration of the album that has least songs is {longSongShortAlbum.Duration}");
            Console.WriteLine($"The name of the song is: '{longSongShortAlbum.Name}'");
            Console.WriteLine("");

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

            Album albumSongsMostA = Albums
                                    .FirstOrDefault(album => album.Songs
                                                    .Where(song => song.Name.ToLower().Contains('a')).Count() == Albums
                                                    .Select(alb => alb.Songs
                                                            .Where(sg => sg.Name.ToLower().Contains('a')).Count())
                                                    .Max());

            Console.WriteLine($"14) Name of the album that has most songs that contain letter 'a' in the name is '{albumSongsMostA.Name}'");
            Console.WriteLine("");


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

            Artist artistSongsEndsD = Artists
                                      .FirstOrDefault(artist => artist.Albums
                                                      .Select(album => album.Songs
                                                              .Where(song => song.Name.ToLower().EndsWith('d')).Count()).Sum() == Artists
                                                      .Select(art => art.Albums
                                                              .Select(alb => alb.Songs
                                                                      .Where(sg => sg.Name.ToLower().EndsWith('d')).Count()).Sum())
                                                      .Max());

            Console.WriteLine($"15) Name of the artist that has most songs that end with letter 'd' is '{artistSongsEndsD.FullName}'");

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

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



            Console.ReadLine();
        }
Ejemplo n.º 16
0
        //--------------------//
        // SongArtist methods //
        //--------------------//

        public Artist GetSongArtist(int id)
        {
            return(Artists.FirstOrDefault(x => x.Id == id));
        }