コード例 #1
0
        private void AddArtistNodesToTree(List <TreeNode> artistNodes)
        {
            if (tvUploads.InvokeRequired)
            {
                var d = new AddArtistNodesToTreeDelegate(AddArtistNodesToTree);
                Invoke(d, new object[] { artistNodes });
            }
            else
            {
                tvUploads.Nodes.Add(new TreeNode
                {
                    Name = "root",
                    Text = "Artists",
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType = MusicManageTreeNodeModel.NodeTypeEnum.Root
                    }
                });

                AddChildNodesFromArtistBind(tvUploads.Nodes[1], artistNodes);

                tvUploads.Nodes[1].Text = tvUploads.Nodes[1].Text + " (" + tvUploads.Nodes[1].Nodes.Count + ")";
                tvUploads.Nodes[1].Expand();
                ResumeDrawing(tvUploads);
            }
        }
コード例 #2
0
        private void AddPlaylistsNodesToTree(List <TreeNode> playlistNodes)
        {
            if (tvUploads.InvokeRequired)
            {
                var d = new AddPlaylistsNodesToTreeDelegate(AddPlaylistsNodesToTree);
                Invoke(d, new object[] { playlistNodes });
            }
            else
            {
                tvUploads.Nodes.Clear();

                SuspendDrawing(tvUploads);
                tvUploads.Nodes.Add(new TreeNode
                {
                    Name = "playlists",
                    Text = "Playlists",
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType = MusicManageTreeNodeModel.NodeTypeEnum.Root
                    }
                });

                AddChildNodesFromArtistBind(tvUploads.Nodes[0], playlistNodes);

                tvUploads.Nodes[0].Text = tvUploads.Nodes[0].Text + " (" + tvUploads.Nodes[0].Nodes.Count + ")";
            }
        }
コード例 #3
0
        private void BindArtists(bool showFetchedMessage = true)
        {
            var artistNodes = new List <TreeNode>();

            foreach (var artist in Requests.ArtistCache.Artists)
            {
                var artistNode = new TreeNode
                {
                    Name = artist.BrowseId,
                    Text = artist.ArtistName,
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType         = MusicManageTreeNodeModel.NodeTypeEnum.Artist,
                        ArtistTitle      = artist.ArtistName,
                        EntityOrBrowseId = artist.BrowseId
                    }
                };

                artistNodes.Add(artistNode);

                // v1.4.3: This block can take too. Don't bother...

                //if (artist.AlbumSongCollection != null &&
                //    artist.AlbumSongCollection.Albums != null &&
                //    artist.AlbumSongCollection.Albums.Count > 0)
                //{
                //    BindAlbumNodesFromArtistBind(artistNode, artist.AlbumSongCollection, false, showFetchedMessage);
                //}
            }

            AddArtistNodesToTree(artistNodes);

            string artistText  = "artists";
            int    artistCount = Requests.ArtistCache.Artists.Count;

            if (artistCount == 1)
            {
                artistText = "artist";
            }

            if (showFetchedMessage)
            {
                AppendUpdatesText($"Fetched {artistCount} {artistText}.",
                                  ColourHelper.HexStringToColor("#0d5601"));
            }

            ShowPreloader(false);
            SetTreeViewEnabled(true);
            DisableAllActionButtons(false);
            ResumeDrawing(tvUploads);
        }
コード例 #4
0
        private void BindArtistsAndPlaylists(bool showFetchedMessage = true)
        {
            var playlistNodes = new List <TreeNode>();

            foreach (var playlist in Requests.ArtistCache.Playlists)
            {
                var dbPlaylistEntry = MainForm.PlaylistFileRepo.LoadFromPlayListId(playlist.BrowseId).Result;
                var playlistNode    = new TreeNode
                {
                    Name = playlist.BrowseId,
                    Text = playlist.Title,
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType          = MusicManageTreeNodeModel.NodeTypeEnum.Playlist,
                        PlaylistTitle     = playlist.Title,
                        Duration          = playlist.Duration,
                        EntityOrBrowseId  = playlist.BrowseId,
                        CovertArtUrl      = playlist.CoverArtUrl,
                        DatabaseExistence = dbPlaylistEntry != null
                                                ? $"Exists ({dbPlaylistEntry.Id})"
                                                : "Not found or not mapped"
                    }
                };

                playlistNodes.Add(playlistNode);
            }
            AddPlaylistsNodesToTree(playlistNodes);

            var artistNodes = new List <TreeNode>();

            foreach (var artist in Requests.ArtistCache.Artists)
            {
                var artistNode = new TreeNode
                {
                    Name = artist.BrowseId,
                    Text = artist.ArtistName,
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType         = MusicManageTreeNodeModel.NodeTypeEnum.Artist,
                        ArtistTitle      = artist.ArtistName,
                        EntityOrBrowseId = artist.BrowseId
                    }
                };

                artistNodes.Add(artistNode);
            }
            AddArtistNodesToTree(artistNodes);

            string artistText  = "artists";
            int    artistCount = Requests.ArtistCache.Artists.Count;

            if (artistCount == 1)
            {
                artistText = "artist";
            }

            if (showFetchedMessage)
            {
                AppendUpdatesText($"Fetched {artistCount} {artistText}.",
                                  ColourHelper.HexStringToColor("#0d5601"));
            }

            tvUploads.Nodes[0].EnsureVisible();

            ShowPreloader(false);
            SetTreeViewEnabled(true);
            DisableAllActionButtons(false);
            ResumeDrawing(tvUploads);
        }
コード例 #5
0
        private void BindAlbumNodesFromSelect(
            TreeNode artistNode,
            AlbumSongCollection albumSongCollection,
            bool expand             = true,
            bool showFetchedMessage = true,
            bool isDeleting         = false)
        {
            if (tvUploads.InvokeRequired)
            {
                var d = new BindAlbumNodesFromSelectDelegate(BindAlbumNodesFromSelect);
                Invoke(d, new object[] { artistNode, albumSongCollection, expand, showFetchedMessage, isDeleting });
            }
            else
            {
                SetTreeViewEnabled(false);
                if (artistNode != null)
                {
                    var albumNodes = new List <TreeNode>();
                    foreach (var album in albumSongCollection.Albums)
                    {
                        var    songNodes   = new List <TreeNode>();
                        string releaseMbId = string.Empty;

                        foreach (var song in album.Songs)
                        {
                            var    musicFile             = MainForm.MusicFileRepo.LoadFromEntityId(song.EntityId).Result;
                            string databaseExistenceText = "Not found or not mapped";

                            if (musicFile != null && musicFile.Id != 0 && musicFile.Id != -1)
                            {
                                databaseExistenceText = $"Exists ({musicFile.Id})";
                                releaseMbId           = string.IsNullOrEmpty(musicFile.ReleaseMbId) ? releaseMbId : musicFile.ReleaseMbId;
                            }

                            songNodes.Add(new TreeNode
                            {
                                Name = song.EntityId,
                                Text = song.Title,
                                Tag  = Tag = new MusicManageTreeNodeModel
                                {
                                    NodeType               = MusicManageTreeNodeModel.NodeTypeEnum.Song,
                                    ArtistTitle            = ((MusicManageTreeNodeModel)artistNode.Tag).ArtistTitle,
                                    AlbumTitle             = album.Title,
                                    SongTitleOrDescription = song.Title,
                                    Duration               = song.Duration,
                                    CovertArtUrl           = song.CoverArtUrl,
                                    DatabaseExistence      = databaseExistenceText,
                                    MbId             = musicFile == null || string.IsNullOrEmpty(musicFile.MbId) ? "-" : musicFile.MbId,
                                    EntityOrBrowseId = song.EntityId,
                                    Uploaded         = musicFile == null ? "-" : musicFile.LastUpload.ToString("dd/MM/yyyy HH:mm")
                                }
                            });
                        }

                        var albumNode = new TreeNode
                        {
                            Name = Guid.NewGuid().ToString(),
                            Text = album.Title,
                            Tag  = Tag = new MusicManageTreeNodeModel
                            {
                                NodeType          = MusicManageTreeNodeModel.NodeTypeEnum.Album,
                                ArtistTitle       = ((MusicManageTreeNodeModel)artistNode.Tag).ArtistTitle,
                                AlbumTitle        = album.Title,
                                CovertArtUrl      = album.CoverArtUrl,
                                DatabaseExistence = string.IsNullOrEmpty(releaseMbId) ? "Not found or not mapped" : "Tracks exists for this album",
                                MbId             = string.IsNullOrEmpty(releaseMbId) ? "-" : releaseMbId,
                                EntityOrBrowseId = album.EntityId,
                                Uploaded         = "-"
                            }
                        };

                        albumNode.Nodes.AddRange(songNodes.ToArray());
                        albumNode.Text = albumNode.Text + " (" + songNodes.Count + ")";
                        albumNodes.Add(albumNode);
                    }
                    ;

                    AddChildNodes(artistNode, albumNodes);

                    int albumCount = albumSongCollection.Albums.Count;
                    int songCount  = albumSongCollection.Songs.Count;

                    string albumText = "albums";
                    string songText  = "tracks";

                    if (albumCount == 1)
                    {
                        albumText = "album";
                    }

                    if (songCount == 1)
                    {
                        songText = "track";
                    }

                    if (showFetchedMessage)
                    {
                        AppendUpdatesText($"Fetched {albumCount} {albumText}, {songCount} {songText}.",
                                          ColourHelper.HexStringToColor("#0d5601"));
                    }

                    artistNode.Text = artistNode.Text + " (" + artistNode.Nodes.Count + ")";
                    if (expand)
                    {
                        artistNode.Expand();
                    }

                    if (artistNode.Checked)
                    {
                        CheckAllChildNodes(artistNode, true);
                    }

                    if (!isDeleting)
                    {
                        SetMusicDetails((MusicManageTreeNodeModel)artistNode.Tag);
                    }
                }

                if (!isDeleting)
                {
                    ShowPreloader(false);
                    SetTreeViewEnabled(true);
                    DisableAllActionButtons(false);
                }
            }
        }
コード例 #6
0
        private void BindPlaylistNodesFromSelect(
            TreeNode playlistNode,
            OnlinePlaylist playlist,
            bool expand             = true,
            bool showFetchedMessage = true,
            bool isDeleting         = false)
        {
            if (tvUploads.InvokeRequired)
            {
                var d = new BindPlaylistNodesFromSelectDelegate(BindPlaylistNodesFromSelect);
                Invoke(d, new object[] { playlistNode, playlist, expand, showFetchedMessage, isDeleting });
            }
            else
            {
                SetTreeViewEnabled(false);
                if (playlistNode != null)
                {
                    var dbPlaylistEntry = MainForm.PlaylistFileRepo.LoadFromPlayListId(playlist.BrowseId).Result;
                    playlistNode.Tag = new MusicManageTreeNodeModel
                    {
                        NodeType               = MusicManageTreeNodeModel.NodeTypeEnum.Playlist,
                        PlaylistTitle          = playlist.Title,
                        Duration               = playlist.Duration,
                        EntityOrBrowseId       = playlist.BrowseId,
                        CovertArtUrl           = playlist.CoverArtUrl,
                        SongTitleOrDescription = playlist.Description,
                        DatabaseExistence      = dbPlaylistEntry != null
                                                ? $"Exists ({dbPlaylistEntry.Id})"
                                                : "Not found or not mapped"
                    };

                    var playlistItems = new List <TreeNode>();
                    foreach (var song in playlist.Songs)
                    {
                        var playlistItem = new TreeNode
                        {
                            Name = Guid.NewGuid().ToString(),
                            Text = song.Title,
                            Tag  = Tag = new MusicManageTreeNodeModel
                            {
                                NodeType               = MusicManageTreeNodeModel.NodeTypeEnum.PlaylistItem,
                                ArtistTitle            = song.ArtistTitle,
                                AlbumTitle             = song.AlbumTitle,
                                CovertArtUrl           = song.CoverArtUrl,
                                Duration               = song.Duration,
                                SongTitleOrDescription = song.Title,
                                MbId              = "-",
                                EntityOrBrowseId  = song.VideoId,
                                DatabaseExistence = "-",
                                AltEntityId       = song.SetVideoId,
                                Uploaded          = "-"
                            }
                        };

                        playlistItems.Add(playlistItem);
                    }

                    playlistNode.Nodes.AddRange(playlistItems.ToArray());
                    playlistNode.Text = playlistNode.Text + " (" + playlistNode.Nodes.Count + ")";

                    if (showFetchedMessage)
                    {
                        AppendUpdatesText($"Fetched {playlistItems.Count} playlist items.",
                                          ColourHelper.HexStringToColor("#0d5601"));
                    }
                    if (expand)
                    {
                        playlistNode.Expand();
                    }

                    if (playlistNode.Checked)
                    {
                        CheckAllChildNodes(playlistNode, true);
                    }

                    if (!isDeleting)
                    {
                        SetMusicDetails((MusicManageTreeNodeModel)playlistNode.Tag);
                    }
                }

                if (!isDeleting)
                {
                    ShowPreloader(false);
                    SetTreeViewEnabled(true);
                    DisableAllActionButtons(false);
                }
            }
        }
コード例 #7
0
        private void SetMusicDetails(MusicManageTreeNodeModel nodeTag)
        {
            if (lblArtistTitle.InvokeRequired ||
                lblAlbumTitle.InvokeRequired ||
                lblSongTitle.InvokeRequired ||
                lblDuration.InvokeRequired ||
                lblDatabaseExistence.InvokeRequired ||
                lblMbId.InvokeRequired ||
                lblUploaded.InvokeRequired ||
                pbCoverArt.InvokeRequired)
            {
                var d = new SetMusicDetailsDelegate(SetMusicDetails);
                Invoke(d, new object[] { nodeTag });
            }
            else
            {
                if (nodeTag.NodeType == MusicManageTreeNodeModel.NodeTypeEnum.Playlist)
                {
                    lblAlbumTitle.Text  = nodeTag.PlaylistTitle;
                    lblArtistTitle.Text = "Playlist";
                }
                else
                {
                    lblArtistTitle.Text = nodeTag.ArtistTitle;
                    lblAlbumTitle.Text  = nodeTag.AlbumTitle;
                }

                lblSongTitle.Text         = nodeTag.SongTitleOrDescription;
                lblDuration.Text          = nodeTag.Duration;
                lblDatabaseExistence.Text = nodeTag.DatabaseExistence;
                lblMbId.Text = nodeTag.MbId;

                if (nodeTag.NodeType == MusicManageTreeNodeModel.NodeTypeEnum.Album)
                {
                    lblMbId.Tag = "https://musicbrainz.org/release/" + nodeTag.MbId;
                }
                else if (nodeTag.NodeType == MusicManageTreeNodeModel.NodeTypeEnum.Song)
                {
                    lblMbId.Tag = "https://musicbrainz.org/recording/" + nodeTag.MbId;
                }
                else
                {
                    lblMbId.Tag = string.Empty;
                }

                lblUploaded.Text = nodeTag.Uploaded;

                if (nodeTag.NodeType == MusicManageTreeNodeModel.NodeTypeEnum.Artist ||
                    nodeTag.NodeType == MusicManageTreeNodeModel.NodeTypeEnum.Root)
                {
                    pbCoverArt.Image = Properties.Resources.default_artwork_60;
                }
                else
                {
                    if (string.IsNullOrEmpty(nodeTag.CovertArtUrl))
                    {
                        pbCoverArt.Image = Properties.Resources.default_artwork_60;
                    }
                    else
                    {
                        ThreadPool.QueueUserWorkItem(delegate
                        {
                            byte[] imageBytes = MusicDataFetcher.GetImageBytesFromUrl(nodeTag.CovertArtUrl);
                            if (imageBytes == null)
                            {
                                pbCoverArt.Image = Properties.Resources.default_artwork_60;
                            }
                            else
                            {
                                using (var ms = new MemoryStream(imageBytes))
                                {
                                    var image = Image.FromStream(ms);
                                    if (image.Width != 60)
                                    {
                                        image = ImageHelper.ResizeBitmap((Bitmap)image, 60, 60);
                                    }

                                    SetCovertArtImage(image);
                                }
                            }
                        });
                    }
                }
            }
        }
コード例 #8
0
        private void BindAlbumNodesFromArtistBind(
            TreeNode artistNode,
            AlbumSongCollection albumSongCollection,
            bool expand             = true,
            bool showFetchedMessage = true)
        {
            var albumNodes = new List <TreeNode>();

            foreach (var album in albumSongCollection.Albums)
            {
                var    songNodes   = new List <TreeNode>();
                string releaseMbId = string.Empty;

                album.Songs.AsParallel().ForAllInApproximateOrder(song =>
                {
                    var musicFile = MainForm.MusicFileRepo.LoadFromEntityId(song.EntityId).Result;
                    string databaseExistenceText = "Not found or not mapped";

                    if (musicFile != null && musicFile.Id != 0 && musicFile.Id != -1)
                    {
                        databaseExistenceText = $"Exists ({musicFile.Id})";
                        releaseMbId           = string.IsNullOrEmpty(musicFile.ReleaseMbId) ? releaseMbId : musicFile.ReleaseMbId;
                    }

                    songNodes.Add(new TreeNode
                    {
                        Name = song.EntityId,
                        Text = song.Title,
                        Tag  = Tag = new MusicManageTreeNodeModel
                        {
                            NodeType          = MusicManageTreeNodeModel.NodeTypeEnum.Song,
                            ArtistTitle       = ((MusicManageTreeNodeModel)artistNode.Tag).ArtistTitle,
                            AlbumTitle        = album.Title,
                            SongTitle         = song.Title,
                            Duration          = song.Duration,
                            CovertArtUrl      = song.CoverArtUrl,
                            DatabaseExistence = databaseExistenceText,
                            MbId             = musicFile == null || string.IsNullOrEmpty(musicFile.MbId) ? "-" : musicFile.MbId,
                            EntityOrBrowseId = song.EntityId,
                            Uploaded         = musicFile == null ? "-" : musicFile.LastUpload.ToString("dd/MM/yyyy HH:mm")
                        }
                    });
                });

                var albumNode = new TreeNode
                {
                    Name = Guid.NewGuid().ToString(),
                    Text = album.Title,
                    Tag  = Tag = new MusicManageTreeNodeModel
                    {
                        NodeType          = MusicManageTreeNodeModel.NodeTypeEnum.Album,
                        ArtistTitle       = ((MusicManageTreeNodeModel)artistNode.Tag).ArtistTitle,
                        AlbumTitle        = album.Title,
                        CovertArtUrl      = album.CoverArtUrl,
                        DatabaseExistence = string.IsNullOrEmpty(releaseMbId) ? "Not found or not mapped" : "Tracks exists for this album",
                        MbId             = string.IsNullOrEmpty(releaseMbId) ? "-" : releaseMbId,
                        EntityOrBrowseId = album.EntityId,
                        Uploaded         = "-"
                    }
                };

                albumNode.Nodes.AddRange(songNodes.ToArray());
                albumNode.Text = albumNode.Text + " (" + songNodes.Count + ")";
                albumNodes.Add(albumNode);
            }

            AddChildNodesFromArtistBind(artistNode, albumNodes);

            int albumCount = albumSongCollection.Albums.Count;
            int songCount  = albumSongCollection.Songs.Count;

            string albumText = "albums";
            string songText  = "tracks";

            if (albumCount == 1)
            {
                albumText = "album";
            }

            if (songCount == 1)
            {
                songText = "track";
            }

            if (showFetchedMessage)
            {
                AppendUpdatesText($"Fetched {albumCount} {albumText}, {songCount} {songText}.",
                                  ColourHelper.HexStringToColor("#0d5601"));
            }

            artistNode.Text = artistNode.Text + " (" + artistNode.Nodes.Count + ")";
            if (expand)
            {
                artistNode.Expand();
            }

            if (artistNode.Checked)
            {
                CheckAllChildNodes(artistNode, true);
            }
        }