Ejemplo n.º 1
0
 public string GetAlbumArtUrl()
 {
     if (m_track != null && m_track.Album != null && m_track.Album.Images != null)
     {
         SpotifyAPI.Web.Models.Image i = m_track.Album.Images.FirstOrDefault();
         return(i.Url);
     }
     return(null);
 }
        private void OpenBtn_OnClick(object sender, RoutedEventArgs e)
        {
            //handles opening a file (song) to later edit its metadata
            //reading the files metadata and if they are not null showing them

            Song?.Dispose();
            SpotifyImage = null;

            var ofd = new OpenFileDialog
            {
                Multiselect = false, //can only select one song to edit
                //limiting file selection to supported formats
                Filter = "Music Files (*.mp3,*.wav,etc.)|*.aa;*.aax;*.aac;*.aiff;*.ape;*.dsf;*.flac;*.m4a;*.m4b;*.m4p;*.mp3;*.mpc;*.mpp;*.ogg;*.oga;*.wav;*.wma;*.wv;*.webm"
            };

            if (ofd.ShowDialog().GetValueOrDefault(false))
            {
                Song = TagLib.File.Create(ofd.FileName);
            }
            else
            {
                return; //returning if OpenFileDialog is cancelled
            }

            _songFilePos = ofd.FileName;

            //In version 8 of C# this sentence could be shorted to: FileNameTextBox.Text = ofd.FileName.Split('\\')[^1];
            FileNameTextBox.Text = ofd.FileName.Split('\\')[ofd.FileName.Split('\\').Length - 1];

            //could have used ?: expression but that wouldn't be so future proofing! (i'm not going to comment the same text for all of this type of things)
            if (!string.IsNullOrWhiteSpace(Song.Tag.Title))
            {
                TitleTextBox.Text = Song.Tag.Title;
            }
            else
            {
                TitleTextBox.Text = string.Empty;
            }

            if (!string.IsNullOrWhiteSpace(Song.Tag.Album))
            {
                AlbumTextBox.Text = Song.Tag.Album;
            }
            else
            {
                AlbumTextBox.Text = string.Empty;
            }

            if (Song.Tag.Performers != null && Song.Tag.Performers.Length != 0)
            {
                var str = string.Empty;
                if (Song.Tag.Performers.Length > 1)
                {
                    for (int i = 0; i < Song.Tag.Performers.Length - 1; i++)
                    {
                        str += Song.Tag.Performers[i] + ", ";
                    }
                }

                str += Song.Tag.Performers[Song.Tag.Performers.Length - 1];

                SongArtistsTextBox.Text = str;
            }
            else
            {
                SongArtistsTextBox.Text = string.Empty;
            }

            if (Song.Tag.AlbumArtists != null && Song.Tag.AlbumArtists.Length != 0)
            {
                var str = string.Empty;
                if (Song.Tag.AlbumArtists.Length > 1)
                {
                    for (int i = 0; i < Song.Tag.AlbumArtists.Length - 1; i++)
                    {
                        str += Song.Tag.AlbumArtists[i] + ", ";
                    }
                }

                str += Song.Tag.AlbumArtists[Song.Tag.AlbumArtists.Length - 1];

                AlbumArtistsTextBox.Text = str;
            }
            else
            {
                AlbumArtistsTextBox.Text = string.Empty;
            }

            if (Song.Tag.Year > 0)
            {
                YearTextBox.Text = Song.Tag.Year.ToString();
            }
            else
            {
                YearTextBox.Text = string.Empty;
            }

            if (Song.Tag.Track > 0)
            {
                TrackNumberTextBox.Text = Song.Tag.Track.ToString();
            }
            else
            {
                TrackNumberTextBox.Text = string.Empty;
            }

            //using dynamic type to use the same variable as "From" for the background changing animation
            //and yes, i used ?: expression here. could have used if else statement but "too much effort"!
            var brush = OldImageSource != null
                ? (dynamic) new ImageBrush(OldImageSource)
                : new SolidColorBrush(Color.FromRgb(30, 30, 30));

            if (Song.Tag.Pictures != null && Song.Tag.Pictures.Length != 0)
            {
                image.ImageSource = IPictureToBitmapImage(Song.Tag.Pictures[0]); //changing format of the TagLib picture to BitmapImage

                bgRectangle.BeginAnimation(Shape.FillProperty, new BrushAnimation
                {
                    Duration = new Duration(TimeSpan.FromSeconds(2)),
                    From     = brush,
                    To       = new ImageBrush(image.ImageSource)
                });
                OldImageSource = image.ImageSource;
            }
            else
            {
                OldImageSource    = null;
                image.ImageSource = new BitmapImage(new Uri(@"PlaceholderImage.png", UriKind.Relative));
                bgRectangle.BeginAnimation(Shape.FillProperty, new BrushAnimation
                {
                    Duration = new Duration(TimeSpan.FromSeconds(2)),
                    From     = brush,
                    To       = new SolidColorBrush(Color.FromRgb(30, 30, 30))
                });
            }

            if (Song.Tag.Genres != null && Song.Tag.Genres.Length != 0)
            {
                var str = string.Empty;
                if (Song.Tag.Genres.Length > 1)
                {
                    for (int i = 0; i < Song.Tag.Genres.Length - 1; i++)
                    {
                        str += Song.Tag.Genres[i] + ", ";
                    }
                }

                str += Song.Tag.Genres[Song.Tag.Genres.Length - 1];

                GenresTextBox.Text = str;
            }
            else
            {
                GenresTextBox.Text = string.Empty;
            }

            if (!string.IsNullOrWhiteSpace(Song.Tag.Lyrics))
            {
                LyricTextBox.Text = Song.Tag.Lyrics;
            }
            else
            {
                LyricTextBox.Text = string.Empty;
            }
        }
        private void Spotify_OnClick(object sender, RoutedEventArgs e)
        {
            //places the available metadata from Spotify selected music

            if (listBox.SelectedItems.Count == 0)
            {
                return; //returning if no song is selected
            }

            //selecting first item selected. because "SelectionMode" property on ListBox is set to Single we know it's the only and the actual selected item
            var selectedMusic = (MusicInfo)listBox.SelectedItems[0];

            if (selectedMusic.Title != null)
            {
                TitleTextBox.Text = selectedMusic.Title;
            }

            if (selectedMusic.Album != null)
            {
                AlbumTextBox.Text = selectedMusic.Album;
            }

            if (selectedMusic.SongArtists != null && selectedMusic.SongArtists.Count != 0)
            {
                var str = string.Empty;
                if (selectedMusic.SongArtists.Count > 1)
                {
                    for (int i = 0; i < selectedMusic.SongArtists.Count - 1; i++)
                    {
                        str += selectedMusic.SongArtists[i] + ", ";
                    }
                }

                str += selectedMusic.SongArtists[selectedMusic.SongArtists.Count - 1];

                SongArtistsTextBox.Text = str;
            }

            if (selectedMusic.AlbumArtists != null && selectedMusic.AlbumArtists.Count != 0)
            {
                var str = string.Empty;
                if (selectedMusic.AlbumArtists.Count > 1)
                {
                    for (int i = 0; i < selectedMusic.AlbumArtists.Count - 1; i++)
                    {
                        str += selectedMusic.AlbumArtists[i] + ", ";
                    }
                }

                str += selectedMusic.AlbumArtists[selectedMusic.AlbumArtists.Count - 1];

                AlbumArtistsTextBox.Text = str;
            }

            if (selectedMusic.Year > 0)
            {
                YearTextBox.Text = selectedMusic.Year.ToString();
            }

            if (selectedMusic.TrackNumber > 0)
            {
                TrackNumberTextBox.Text = selectedMusic.TrackNumber.ToString();
            }

            //read line 132
            var brush = OldImageSource != null
                ? (dynamic) new ImageBrush(OldImageSource)
                : new SolidColorBrush(Color.FromRgb(30, 30, 30));

            SpotifyImage = null;
            if (selectedMusic.Image != null)
            {
                image.ImageSource = selectedMusic.ImageSource;
                SpotifyImage      = selectedMusic.Image;
                bgRectangle.BeginAnimation(Shape.FillProperty, new BrushAnimation
                {
                    Duration = new Duration(TimeSpan.FromSeconds(2)),
                    From     = brush,
                    To       = new ImageBrush(image.ImageSource)
                });
                OldImageSource = selectedMusic.ImageSource;
            }

            if (selectedMusic.Genres != null && selectedMusic.Genres.Count != 0)
            {
                var str = string.Empty;
                if (selectedMusic.Genres.Count > 1)
                {
                    for (int i = 0; i < selectedMusic.Genres.Count - 1; i++)
                    {
                        str += selectedMusic.Genres[i] + ", ";
                    }
                }

                str += selectedMusic.Genres[selectedMusic.Genres.Count - 1];

                GenresTextBox.Text = str;
            }
        }