diff --git a/plugin/App.config b/plugin/App.config index 6b6be06..19bfcd8 100644 --- a/plugin/App.config +++ b/plugin/App.config @@ -17,10 +17,10 @@ genres;mood - + genres - + genres synthpop;synth-pop diff --git a/plugin/MusicBrainzAPI.cs b/plugin/MusicBrainzAPI.cs index 19775f2..39b524e 100644 --- a/plugin/MusicBrainzAPI.cs +++ b/plugin/MusicBrainzAPI.cs @@ -163,8 +163,7 @@ namespace plugin if (mbApiResponse.Result.IsSuccessStatusCode) { string result = await mbApiResponse.Result.Content.ReadAsStringAsync(); - Debug.WriteLine("JSON Response: " + result); - // todo: does this output to XML as well? POST requires XML for certain. + Debug.WriteLine("Response from MusicBrainz: " + result); return result; } else if (mbApiResponse.Result.StatusCode == System.Net.HttpStatusCode.Unauthorized) @@ -314,7 +313,6 @@ namespace plugin // access token should be changed regardless. mbzAccessToken = mbOAuthData.access_token; mbzAccessTokenExpiry = DateTime.Now.AddSeconds(mbOAuthData.expires_in); - System.Diagnostics.Debug.WriteLine(mbzAccessTokenExpiry); Settings.Default.Save(); MBzHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", mbzAccessToken); return true; @@ -346,22 +344,20 @@ namespace plugin } // # Rating functions - public async Task SetTrackRatings(List<(string, string)> trackRatings) + public async Task SetRatings(Dictionary mbidRatings, string entity_type) { StringWriter stringWriter = new StringWriter(); XmlWriter xmlWriter = new XmlTextWriter(stringWriter); xmlWriter.WriteStartElement("metadata"); xmlWriter.WriteAttributeString("xmlns", "http://musicbrainz.org/ns/mmd-2.0#"); - xmlWriter.WriteStartElement("recording-list"); + xmlWriter.WriteStartElement($"{entity_type}-list"); - foreach ((string,string) trackRatingPair in trackRatings) + foreach (KeyValuePair trackTagPair in mbidRatings) { - string recordingMbid = trackRatingPair.Item1; - string trackRatingString = trackRatingPair.Item2; - - float rating = (float.Parse(trackRatingString)) * 20; - xmlWriter.WriteStartElement("recording"); xmlWriter.WriteAttributeString("id", recordingMbid); - xmlWriter.WriteElementString("user-rating", rating.ToString()); - xmlWriter.WriteEndElement(); // ends individual recording XML + string mbid = trackTagPair.Key; + string rating = trackTagPair.Value.ToString(); + xmlWriter.WriteStartElement(entity_type); xmlWriter.WriteAttributeString("id", mbid); + xmlWriter.WriteElementString("user-rating", rating); + xmlWriter.WriteEndElement(); // ends individual recording XML } xmlWriter.WriteEndElement(); // ends recording-list XML xmlWriter.WriteEndElement(); // ends metadata XML @@ -371,40 +367,11 @@ namespace plugin await PostToMusicBrainz("/ws/2/rating?client=mb_MusicBrainzSync", xmlData, "application/xml"); } - public async Task SetReleaseGroupRatings(Dictionary releaseRatings) - { - StringWriter stringWriter = new StringWriter(); - XmlWriter xmlWriter = new XmlTextWriter(stringWriter); - xmlWriter.WriteStartElement("metadata"); xmlWriter.WriteAttributeString("xmlns", "http://musicbrainz.org/ns/mmd-2.0#"); - xmlWriter.WriteStartElement("release-group-list"); - - foreach (KeyValuePair releaseRatingPair in releaseRatings) - { - string releaseMbid = releaseRatingPair.Key; - string releaseRatingString = releaseRatingPair.Value; - - // Oddly enough, MusicBee actually just outputs 0-100 for the album rating, not 0-5. - int rating = int.Parse(releaseRatingString); - - if (!(rating == 0)) { - xmlWriter.WriteStartElement("release-group"); xmlWriter.WriteAttributeString("id", releaseMbid); - xmlWriter.WriteElementString("user-rating", rating.ToString()); - xmlWriter.WriteEndElement(); // ends individual release XML - } - } - - xmlWriter.WriteEndElement(); // ends release-group-list XML - xmlWriter.WriteEndElement(); // ends metadata XML - xmlWriter.Flush(); - string xmlData = stringWriter.ToString(); - Debug.WriteLine("XML Data: " + xmlData); - await PostToMusicBrainz("/ws/2/rating?client=mb_MusicBrainzSync", xmlData, "application/xml"); - } + // # Tag functions private string FindReplaceTag(string tag) { tag = tag.ToLower(); - Debug.WriteLine("Tag being processed:"+tag); if (string.IsNullOrEmpty(Settings.Default.findReplace)) { return tag; @@ -415,7 +382,6 @@ namespace plugin // convert the findReplace setting into a dictionary for easier. foreach (string line in Settings.Default.findReplace.Split(new[] { Environment.NewLine }, StringSplitOptions.None)) { - Debug.WriteLine(line); // split by the first semicolon to get the find and replace values string[] row = line.Split(new[] { ';' }, 2); if (row.Length == 2) diff --git a/plugin/Plugin.cs b/plugin/Plugin.cs index c138910..75fdcf3 100644 --- a/plugin/Plugin.cs +++ b/plugin/Plugin.cs @@ -340,7 +340,6 @@ namespace MusicBeePlugin private void mbzVerifyLabel_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { - System.Diagnostics.Debug.WriteLine("verifyWithMusicBrainz called"); if (!string.IsNullOrEmpty(mbzUserInputBox.Text)) { bool userAuthenticated = mbz.AuthenticateUser(mbzUserInputBox.Text).Result; @@ -366,28 +365,6 @@ namespace MusicBeePlugin ToggleAuthPanelsVisibility(); } - // # MusicBee standard plugin functions - - // called by MusicBee when the user clicks Apply or Save in the MusicBee Preferences screen. - // Auth process automatically saves the access and refresh tokens, and tag bindings will be handled via another GUI so no need for this at the moment. - public void SaveSettings() - { - - } - - // MusicBee is closing the plugin (plugin is being disabled by user or MusicBee is shutting down) - public void Close(PluginCloseReason reason) - { - } - - // uninstall this plugin - clean up any persisted files - public void Uninstall() - { - // todo: ask to delete settings - Settings.Default.Reset(); - // todo: ask to delete tag binding data - } - // receive event notifications from MusicBee // you need to set about.ReceiveNotificationFlags = PlayerEvents to receive all notifications, and not just the startup event public void ReceiveNotification(string sourceFileUrl, NotificationType type) @@ -424,7 +401,8 @@ namespace MusicBeePlugin } } - public async void SendTrackRatings(object sender, EventArgs args) + // # Data submission functions + public async void SendRatingData(string entity_type) { mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", out string[] files); if (files == null) @@ -433,83 +411,58 @@ namespace MusicBeePlugin } else { - mbApiInterface.MB_SetBackgroundTaskMessage("Submitting track ratings to MusicBrainz..."); + mbApiInterface.MB_SetBackgroundTaskMessage("Submitting ratings to MusicBrainz..."); try { - List<(string, string)> trackRatings = new List<(string, string)>(); + Dictionary tracksAndRatings = new Dictionary(); List tracks = files.Select(file => new MusicBeeTrack(file)).ToList(); foreach (MusicBeeTrack track in tracks) { - if (!string.IsNullOrEmpty(track.MusicBrainzTrackId) && !string.IsNullOrEmpty(track.Rating)) + string currentMbid = ""; + switch (entity_type) { - trackRatings.Add((track.MusicBrainzTrackId, track.Rating)); + // no need to handle releases, MusicBrainz doesn't allow rating of releases at the moment. + case "release-group": + currentMbid = track.MusicBrainzReleaseGroupId; + break; + default: + currentMbid = track.MusicBrainzTrackId; + break; } - } - if (trackRatings.Count == 0) - { - mbApiInterface.MB_SetBackgroundTaskMessage("Track ratings not submitted due to empty data."); - } - else - { - await mbz.SetTrackRatings(trackRatings); - mbApiInterface.MB_SetBackgroundTaskMessage("Successfully submitted track ratings to MusicBrainz."); - } - } - catch (UnsupportedFormatException e) - { - MessageBox.Show($"Error: {e.Message}", "MusicBrainz Sync", MessageBoxButtons.OK, MessageBoxIcon.Error); - mbApiInterface.MB_SetBackgroundTaskMessage("Rating submission failed due to unsupported format."); - } - } - - } - - public async void SendAlbumGroupRatings(object sender, EventArgs args) - { - mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", out string[] files); - if (files == null) - { - return; - } - else - { - mbApiInterface.MB_SetBackgroundTaskMessage("Submitting album ratings to MusicBrainz..."); - try - { - Dictionary albumRatings = new Dictionary(); - List tracks = files.Select(file => new MusicBeeTrack(file)).ToList(); - foreach (MusicBeeTrack track in tracks) - { - if (!string.IsNullOrEmpty(track.MusicBrainzReleaseGroupId)) + if (!string.IsNullOrEmpty(currentMbid)) { - if (albumRatings.ContainsKey(track.MusicBrainzReleaseGroupId)) + if (entity_type == "recording") { - // check if the rating is different to what is already logged, and error out if it is. - if (albumRatings[track.MusicBrainzReleaseGroupId] != track.AlbumRating) - { - MessageBox.Show($"Error: {track.Album} has inconsistent album ratings.\n\nGive every track on that album the exact same album rating and try to submit again.", "MusicBrainz Sync", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } + // Track ratings are out of 5, so we need to multiply by 20 to get a percentage that MusicBrainz is happy to use. + float onlineRating = float.Parse(track.Rating) * 20; + tracksAndRatings.Add(currentMbid, onlineRating); } else { - // if track actually has an album rating - if (!string.IsNullOrEmpty(track.AlbumRating)) + if (tracksAndRatings.ContainsKey(currentMbid)) + { + if (tracksAndRatings[currentMbid] != float.Parse(track.AlbumRating)) + { + MessageBox.Show($"Error: {track.Album} has inconsistent album ratings.\n\nGive every track on that album the exact same album rating and try to submit again.", "MusicBrainz Sync", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + else { - albumRatings.Add(track.MusicBrainzReleaseGroupId, track.AlbumRating); + tracksAndRatings.Add(currentMbid, float.Parse(track.AlbumRating)); } } + } } - if (albumRatings.Count == 0) + if (tracksAndRatings.Count == 0) { - mbApiInterface.MB_SetBackgroundTaskMessage("Album ratings not submitted due to empty data."); - return; + mbApiInterface.MB_SetBackgroundTaskMessage("Ratings not submitted due to empty data."); } else { - await mbz.SetReleaseGroupRatings(albumRatings); - mbApiInterface.MB_SetBackgroundTaskMessage("Successfully submitted album ratings to MusicBrainz."); + await mbz.SetRatings(tracksAndRatings, entity_type); + mbApiInterface.MB_SetBackgroundTaskMessage("Successfully submitted ratings to MusicBrainz."); } } catch (UnsupportedFormatException e) @@ -520,8 +473,6 @@ namespace MusicBeePlugin } } - // # Tag functions - public async void SendTagData(string entity_type) { mbApiInterface.Library_QueryFilesEx("domain=SelectedFiles", out string[] files); @@ -531,25 +482,21 @@ namespace MusicBeePlugin } else { - mbApiInterface.MB_SetBackgroundTaskMessage("Submitting tags to tracks on MusicBrainz..."); + mbApiInterface.MB_SetBackgroundTaskMessage("Submitting tags to MusicBrainz..."); try { Dictionary tracksAndTags = new Dictionary(); List tracks = files.Select(file => new MusicBeeTrack(file)).ToList(); foreach (MusicBeeTrack track in tracks) { - Debug.WriteLine(track.Title); string currentMbid = ""; - Debug.WriteLine($"Getting MBID {entity_type}"); switch (entity_type) { case "release": currentMbid = track.MusicBrainzReleaseId; - Debug.WriteLine("Current mbid:"+currentMbid); break; case "release-group": currentMbid = track.MusicBrainzReleaseGroupId; - Debug.WriteLine("Current mbid:" + currentMbid); break; default: currentMbid = track.MusicBrainzTrackId; @@ -560,7 +507,11 @@ namespace MusicBeePlugin List tags = track.GetAllTagsFromFile(entity_type); if (entity_type == "recording") { - tracksAndTags.Add(currentMbid, String.Join(";", tags)); + if (tags != null) + { + tracksAndTags.Add(currentMbid, String.Join(";", tags)); + } + } else { @@ -571,13 +522,17 @@ namespace MusicBeePlugin MessageBox.Show($"Error: {track.Album} has inconsistent tags.\n\nGive every track on that album the exact same tags and try to submit again.", "MusicBrainz Sync", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - } + } else { - tracksAndTags.Add(currentMbid, String.Join(";", tags)); + if (tags != null) + { + // if it's empty, we don't want to add it to the dictionary. + tracksAndTags.Add(currentMbid, String.Join(";", tags)); + } } } - + } } if (tracksAndTags.Count == 0) @@ -598,11 +553,21 @@ namespace MusicBeePlugin } } + public void SendTrackRatings(object sender, EventArgs args) + { + SendRatingData("recording"); + } + + public void SendAlbumGroupRatings(object sender, EventArgs args) + { + SendRatingData("release-group"); + } + public void SendTrackTags(object sender, EventArgs args) { SendTagData("recording"); } - + public void SendReleaseTags(object sender, EventArgs args) { SendTagData("release"); diff --git a/plugin/Properties/Settings.Designer.cs b/plugin/Properties/Settings.Designer.cs index 6270281..3da0a73 100644 --- a/plugin/Properties/Settings.Designer.cs +++ b/plugin/Properties/Settings.Designer.cs @@ -61,7 +61,7 @@ namespace plugin.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [global::System.Configuration.DefaultSettingValueAttribute("genres")] public string releaseTagBindings { get { return ((string)(this["releaseTagBindings"])); @@ -73,7 +73,7 @@ namespace plugin.Properties { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [global::System.Configuration.DefaultSettingValueAttribute("genres")] public string releaseGroupTagBindings { get { return ((string)(this["releaseGroupTagBindings"])); diff --git a/plugin/Properties/Settings.settings b/plugin/Properties/Settings.settings index ec2f4e7..a8ee698 100644 --- a/plugin/Properties/Settings.settings +++ b/plugin/Properties/Settings.settings @@ -12,10 +12,10 @@ genres;mood - + genres - + genres synthpop;synth-pop diff --git a/plugin/TagBindingConfig.Designer.cs b/plugin/TagBindingConfig.Designer.cs index 1017f4d..0e7e075 100644 --- a/plugin/TagBindingConfig.Designer.cs +++ b/plugin/TagBindingConfig.Designer.cs @@ -56,8 +56,8 @@ this.tagSubmitModeLabel = new System.Windows.Forms.Label(); this.appendRadioButton = new System.Windows.Forms.RadioButton(); this.replaceRadioButton = new System.Windows.Forms.RadioButton(); - this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.tagSubmitNote = new System.Windows.Forms.Label(); + this.mainLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); this.tagGroupBox.SuspendLayout(); this.tagTabControl.SuspendLayout(); this.trackTab.SuspendLayout(); @@ -77,9 +77,10 @@ // separateCheckBox // this.separateCheckBox.AutoSize = true; - this.separateCheckBox.Location = new System.Drawing.Point(3, 3); + this.separateCheckBox.Location = new System.Drawing.Point(6, 6); + this.separateCheckBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.separateCheckBox.Name = "separateCheckBox"; - this.separateCheckBox.Size = new System.Drawing.Size(279, 17); + this.separateCheckBox.Size = new System.Drawing.Size(558, 29); this.separateCheckBox.TabIndex = 0; this.separateCheckBox.Text = "Submit separate tags to releases and release groups. "; this.separateCheckBox.UseVisualStyleBackColor = true; @@ -89,10 +90,11 @@ // this.separateHelperLabel.AutoSize = true; this.separateHelperLabel.ForeColor = System.Drawing.SystemColors.GrayText; - this.separateHelperLabel.Location = new System.Drawing.Point(3, 23); + this.separateHelperLabel.Location = new System.Drawing.Point(6, 41); + this.separateHelperLabel.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); this.separateHelperLabel.Name = "separateHelperLabel"; - this.separateHelperLabel.Padding = new System.Windows.Forms.Padding(0, 0, 0, 6); - this.separateHelperLabel.Size = new System.Drawing.Size(267, 32); + this.separateHelperLabel.Padding = new System.Windows.Forms.Padding(0, 0, 0, 12); + this.separateHelperLabel.Size = new System.Drawing.Size(545, 62); this.separateHelperLabel.TabIndex = 1; this.separateHelperLabel.Text = "Useful if you use separate tags for whole releases (e.g. album genres)"; // @@ -100,11 +102,11 @@ // this.tagGroupBox.Controls.Add(this.tagTabControl); this.tagGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.tagGroupBox.Location = new System.Drawing.Point(2, 57); - this.tagGroupBox.Margin = new System.Windows.Forms.Padding(2); + this.tagGroupBox.Location = new System.Drawing.Point(4, 107); + this.tagGroupBox.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tagGroupBox.Name = "tagGroupBox"; - this.tagGroupBox.Padding = new System.Windows.Forms.Padding(2); - this.tagGroupBox.Size = new System.Drawing.Size(281, 319); + this.tagGroupBox.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tagGroupBox.Size = new System.Drawing.Size(562, 617); this.tagGroupBox.TabIndex = 3; this.tagGroupBox.TabStop = false; this.tagGroupBox.Text = "Tags"; @@ -115,19 +117,21 @@ this.tagTabControl.Controls.Add(this.releaseTab); this.tagTabControl.Controls.Add(this.releaseGroupTab); this.tagTabControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.tagTabControl.Location = new System.Drawing.Point(2, 15); + this.tagTabControl.Location = new System.Drawing.Point(4, 28); + this.tagTabControl.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.tagTabControl.Name = "tagTabControl"; this.tagTabControl.SelectedIndex = 0; - this.tagTabControl.Size = new System.Drawing.Size(277, 302); + this.tagTabControl.Size = new System.Drawing.Size(554, 585); this.tagTabControl.TabIndex = 0; // // trackTab // this.trackTab.Controls.Add(this.trackListBox); - this.trackTab.Location = new System.Drawing.Point(4, 22); + this.trackTab.Location = new System.Drawing.Point(8, 39); + this.trackTab.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.trackTab.Name = "trackTab"; - this.trackTab.Padding = new System.Windows.Forms.Padding(3); - this.trackTab.Size = new System.Drawing.Size(269, 276); + this.trackTab.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.trackTab.Size = new System.Drawing.Size(538, 538); this.trackTab.TabIndex = 0; this.trackTab.Text = "Tracks/Recordings"; this.trackTab.UseVisualStyleBackColor = true; @@ -136,18 +140,21 @@ // this.trackListBox.Dock = System.Windows.Forms.DockStyle.Fill; this.trackListBox.FormattingEnabled = true; - this.trackListBox.Location = new System.Drawing.Point(3, 3); + this.trackListBox.Location = new System.Drawing.Point(6, 6); + this.trackListBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.trackListBox.Name = "trackListBox"; - this.trackListBox.Size = new System.Drawing.Size(263, 270); + this.trackListBox.Size = new System.Drawing.Size(526, 526); this.trackListBox.TabIndex = 0; + this.trackListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.trackListBox_ItemCheck); // // releaseTab // this.releaseTab.Controls.Add(this.releaseListBox); - this.releaseTab.Location = new System.Drawing.Point(4, 22); + this.releaseTab.Location = new System.Drawing.Point(8, 39); + this.releaseTab.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.releaseTab.Name = "releaseTab"; - this.releaseTab.Padding = new System.Windows.Forms.Padding(3); - this.releaseTab.Size = new System.Drawing.Size(269, 276); + this.releaseTab.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.releaseTab.Size = new System.Drawing.Size(538, 538); this.releaseTab.TabIndex = 1; this.releaseTab.Text = "Releases"; this.releaseTab.UseVisualStyleBackColor = true; @@ -156,17 +163,20 @@ // this.releaseListBox.Dock = System.Windows.Forms.DockStyle.Fill; this.releaseListBox.FormattingEnabled = true; - this.releaseListBox.Location = new System.Drawing.Point(3, 3); + this.releaseListBox.Location = new System.Drawing.Point(6, 6); + this.releaseListBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.releaseListBox.Name = "releaseListBox"; - this.releaseListBox.Size = new System.Drawing.Size(263, 270); + this.releaseListBox.Size = new System.Drawing.Size(526, 526); this.releaseListBox.TabIndex = 0; + this.releaseListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.releaseListBox_ItemCheck); // // releaseGroupTab // this.releaseGroupTab.Controls.Add(this.releaseGroupListBox); - this.releaseGroupTab.Location = new System.Drawing.Point(4, 22); + this.releaseGroupTab.Location = new System.Drawing.Point(8, 39); + this.releaseGroupTab.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.releaseGroupTab.Name = "releaseGroupTab"; - this.releaseGroupTab.Size = new System.Drawing.Size(269, 276); + this.releaseGroupTab.Size = new System.Drawing.Size(538, 538); this.releaseGroupTab.TabIndex = 2; this.releaseGroupTab.Text = "Release Groups"; this.releaseGroupTab.UseVisualStyleBackColor = true; @@ -176,17 +186,20 @@ this.releaseGroupListBox.Dock = System.Windows.Forms.DockStyle.Fill; this.releaseGroupListBox.FormattingEnabled = true; this.releaseGroupListBox.Location = new System.Drawing.Point(0, 0); + this.releaseGroupListBox.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.releaseGroupListBox.Name = "releaseGroupListBox"; - this.releaseGroupListBox.Size = new System.Drawing.Size(269, 276); + this.releaseGroupListBox.Size = new System.Drawing.Size(538, 538); this.releaseGroupListBox.TabIndex = 0; + this.releaseGroupListBox.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.releaseGroupListBox_ItemCheck); // // saveNote // this.saveNote.Anchor = System.Windows.Forms.AnchorStyles.Right; this.saveNote.AutoSize = true; - this.saveNote.Location = new System.Drawing.Point(50, 29); + this.saveNote.Location = new System.Drawing.Point(95, 56); + this.saveNote.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); this.saveNote.Name = "saveNote"; - this.saveNote.Size = new System.Drawing.Size(246, 26); + this.saveNote.Size = new System.Drawing.Size(497, 50); this.saveNote.TabIndex = 6; this.saveNote.Text = "Settings are automatically saved upon clicking OK, independent from MusicBee."; this.saveNote.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -200,16 +213,18 @@ this.buttonPanel.Controls.Add(this.saveNote); this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Top; this.buttonPanel.FlowDirection = System.Windows.Forms.FlowDirection.RightToLeft; - this.buttonPanel.Location = new System.Drawing.Point(3, 419); + this.buttonPanel.Location = new System.Drawing.Point(6, 805); + this.buttonPanel.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.buttonPanel.Name = "buttonPanel"; - this.buttonPanel.Size = new System.Drawing.Size(299, 55); + this.buttonPanel.Size = new System.Drawing.Size(598, 106); this.buttonPanel.TabIndex = 5; // // cancelButton // - this.cancelButton.Location = new System.Drawing.Point(221, 3); + this.cancelButton.Location = new System.Drawing.Point(442, 6); + this.cancelButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.cancelButton.Name = "cancelButton"; - this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.Size = new System.Drawing.Size(150, 44); this.cancelButton.TabIndex = 1; this.cancelButton.Text = "Cancel"; this.cancelButton.UseVisualStyleBackColor = true; @@ -217,9 +232,10 @@ // // OKButton // - this.OKButton.Location = new System.Drawing.Point(140, 3); + this.OKButton.Location = new System.Drawing.Point(280, 6); + this.OKButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.OKButton.Name = "OKButton"; - this.OKButton.Size = new System.Drawing.Size(75, 23); + this.OKButton.Size = new System.Drawing.Size(150, 44); this.OKButton.TabIndex = 0; this.OKButton.Text = "OK"; this.OKButton.UseVisualStyleBackColor = true; @@ -227,9 +243,10 @@ // // resetButton // - this.resetButton.Location = new System.Drawing.Point(59, 3); + this.resetButton.Location = new System.Drawing.Point(118, 6); + this.resetButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.resetButton.Name = "resetButton"; - this.resetButton.Size = new System.Drawing.Size(75, 23); + this.resetButton.Size = new System.Drawing.Size(150, 44); this.resetButton.TabIndex = 2; this.resetButton.Text = "Reset"; this.resetButton.UseVisualStyleBackColor = true; @@ -241,19 +258,21 @@ this.mainTabControl.Controls.Add(this.findReplacePage); this.mainTabControl.Controls.Add(this.otherSettingsPage); this.mainTabControl.Dock = System.Windows.Forms.DockStyle.Fill; - this.mainTabControl.Location = new System.Drawing.Point(3, 3); + this.mainTabControl.Location = new System.Drawing.Point(6, 6); + this.mainTabControl.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.mainTabControl.Name = "mainTabControl"; this.mainTabControl.SelectedIndex = 0; - this.mainTabControl.Size = new System.Drawing.Size(299, 410); + this.mainTabControl.Size = new System.Drawing.Size(598, 787); this.mainTabControl.TabIndex = 1; // // tagBindingPage // this.tagBindingPage.Controls.Add(this.tagBindingLayoutPanel); - this.tagBindingPage.Location = new System.Drawing.Point(4, 22); + this.tagBindingPage.Location = new System.Drawing.Point(8, 39); + this.tagBindingPage.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.tagBindingPage.Name = "tagBindingPage"; - this.tagBindingPage.Padding = new System.Windows.Forms.Padding(3); - this.tagBindingPage.Size = new System.Drawing.Size(291, 384); + this.tagBindingPage.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.tagBindingPage.Size = new System.Drawing.Size(582, 740); this.tagBindingPage.TabIndex = 0; this.tagBindingPage.Text = "Tag Binding"; this.tagBindingPage.UseVisualStyleBackColor = true; @@ -267,7 +286,8 @@ this.tagBindingLayoutPanel.Controls.Add(this.separateHelperLabel, 0, 1); this.tagBindingLayoutPanel.Controls.Add(this.separateCheckBox, 0, 0); this.tagBindingLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; - this.tagBindingLayoutPanel.Location = new System.Drawing.Point(3, 3); + this.tagBindingLayoutPanel.Location = new System.Drawing.Point(6, 6); + this.tagBindingLayoutPanel.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.tagBindingLayoutPanel.Name = "tagBindingLayoutPanel"; this.tagBindingLayoutPanel.RowCount = 5; this.tagBindingLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -275,16 +295,17 @@ this.tagBindingLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.tagBindingLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); this.tagBindingLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tagBindingLayoutPanel.Size = new System.Drawing.Size(285, 378); + this.tagBindingLayoutPanel.Size = new System.Drawing.Size(570, 728); this.tagBindingLayoutPanel.TabIndex = 1; // // findReplacePage // this.findReplacePage.Controls.Add(this.findReplaceTable); - this.findReplacePage.Location = new System.Drawing.Point(4, 22); + this.findReplacePage.Location = new System.Drawing.Point(8, 39); + this.findReplacePage.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.findReplacePage.Name = "findReplacePage"; - this.findReplacePage.Padding = new System.Windows.Forms.Padding(3); - this.findReplacePage.Size = new System.Drawing.Size(291, 384); + this.findReplacePage.Padding = new System.Windows.Forms.Padding(6, 6, 6, 6); + this.findReplacePage.Size = new System.Drawing.Size(582, 647); this.findReplacePage.TabIndex = 1; this.findReplacePage.Text = "Find and Replace"; this.findReplacePage.UseVisualStyleBackColor = true; @@ -297,10 +318,11 @@ this.findColumn, this.replaceColumn}); this.findReplaceTable.Dock = System.Windows.Forms.DockStyle.Fill; - this.findReplaceTable.Location = new System.Drawing.Point(3, 3); + this.findReplaceTable.Location = new System.Drawing.Point(6, 6); + this.findReplaceTable.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.findReplaceTable.Name = "findReplaceTable"; this.findReplaceTable.RowHeadersWidth = 82; - this.findReplaceTable.Size = new System.Drawing.Size(285, 378); + this.findReplaceTable.Size = new System.Drawing.Size(570, 635); this.findReplaceTable.TabIndex = 0; // // findColumn @@ -318,10 +340,10 @@ // otherSettingsPage // this.otherSettingsPage.Controls.Add(this.flowLayoutPanel1); - this.otherSettingsPage.Location = new System.Drawing.Point(4, 22); - this.otherSettingsPage.Margin = new System.Windows.Forms.Padding(2); + this.otherSettingsPage.Location = new System.Drawing.Point(8, 39); + this.otherSettingsPage.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.otherSettingsPage.Name = "otherSettingsPage"; - this.otherSettingsPage.Size = new System.Drawing.Size(291, 384); + this.otherSettingsPage.Size = new System.Drawing.Size(582, 740); this.otherSettingsPage.TabIndex = 2; this.otherSettingsPage.Text = "Other Settings"; this.otherSettingsPage.UseVisualStyleBackColor = true; @@ -336,27 +358,30 @@ this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.flowLayoutPanel1.Name = "flowLayoutPanel1"; - this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(5); - this.flowLayoutPanel1.Size = new System.Drawing.Size(291, 384); + this.flowLayoutPanel1.Padding = new System.Windows.Forms.Padding(10, 10, 10, 10); + this.flowLayoutPanel1.Size = new System.Drawing.Size(582, 740); this.flowLayoutPanel1.TabIndex = 0; // // tagSubmitModeLabel // this.tagSubmitModeLabel.AutoSize = true; this.tagSubmitModeLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tagSubmitModeLabel.Location = new System.Drawing.Point(8, 5); + this.tagSubmitModeLabel.Location = new System.Drawing.Point(16, 10); + this.tagSubmitModeLabel.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); this.tagSubmitModeLabel.Name = "tagSubmitModeLabel"; - this.tagSubmitModeLabel.Size = new System.Drawing.Size(128, 13); + this.tagSubmitModeLabel.Size = new System.Drawing.Size(244, 26); this.tagSubmitModeLabel.TabIndex = 0; this.tagSubmitModeLabel.Text = "Tag submission mode"; // // appendRadioButton // this.appendRadioButton.AutoSize = true; - this.appendRadioButton.Location = new System.Drawing.Point(8, 21); + this.appendRadioButton.Location = new System.Drawing.Point(16, 42); + this.appendRadioButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.appendRadioButton.Name = "appendRadioButton"; - this.appendRadioButton.Size = new System.Drawing.Size(233, 17); + this.appendRadioButton.Size = new System.Drawing.Size(469, 29); this.appendRadioButton.TabIndex = 1; this.appendRadioButton.TabStop = true; this.appendRadioButton.Text = "Append tags to existing tags on MusicBrainz"; @@ -365,14 +390,27 @@ // replaceRadioButton // this.replaceRadioButton.AutoSize = true; - this.replaceRadioButton.Location = new System.Drawing.Point(8, 44); + this.replaceRadioButton.Location = new System.Drawing.Point(16, 83); + this.replaceRadioButton.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.replaceRadioButton.Name = "replaceRadioButton"; - this.replaceRadioButton.Size = new System.Drawing.Size(287, 17); + this.replaceRadioButton.Size = new System.Drawing.Size(583, 29); this.replaceRadioButton.TabIndex = 2; this.replaceRadioButton.TabStop = true; this.replaceRadioButton.Text = "Clear existing tags when submitting tags to MusicBrainz."; this.replaceRadioButton.UseVisualStyleBackColor = true; // + // tagSubmitNote + // + this.tagSubmitNote.AutoSize = true; + this.tagSubmitNote.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tagSubmitNote.Location = new System.Drawing.Point(16, 118); + this.tagSubmitNote.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0); + this.tagSubmitNote.Name = "tagSubmitNote"; + this.tagSubmitNote.Padding = new System.Windows.Forms.Padding(0, 10, 0, 0); + this.tagSubmitNote.Size = new System.Drawing.Size(580, 218); + this.tagSubmitNote.TabIndex = 3; + this.tagSubmitNote.Text = resources.GetString("tagSubmitNote.Text"); + // // mainLayoutPanel // this.mainLayoutPanel.ColumnCount = 1; @@ -381,32 +419,23 @@ this.mainLayoutPanel.Controls.Add(this.mainTabControl, 0, 0); this.mainLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.mainLayoutPanel.Location = new System.Drawing.Point(0, 0); + this.mainLayoutPanel.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.mainLayoutPanel.Name = "mainLayoutPanel"; this.mainLayoutPanel.RowCount = 2; this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); this.mainLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.mainLayoutPanel.Size = new System.Drawing.Size(305, 477); + this.mainLayoutPanel.Size = new System.Drawing.Size(610, 917); this.mainLayoutPanel.TabIndex = 6; // - // tagSubmitNote - // - this.tagSubmitNote.AutoSize = true; - this.tagSubmitNote.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tagSubmitNote.Location = new System.Drawing.Point(8, 64); - this.tagSubmitNote.Name = "tagSubmitNote"; - this.tagSubmitNote.Padding = new System.Windows.Forms.Padding(0, 5, 0, 0); - this.tagSubmitNote.Size = new System.Drawing.Size(284, 109); - this.tagSubmitNote.TabIndex = 3; - this.tagSubmitNote.Text = resources.GetString("tagSubmitNote.Text"); - // // TagBindingConfig // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; - this.ClientSize = new System.Drawing.Size(305, 477); + this.ClientSize = new System.Drawing.Size(610, 917); this.Controls.Add(this.mainLayoutPanel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Margin = new System.Windows.Forms.Padding(6, 6, 6, 6); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "TagBindingConfig"; diff --git a/plugin/TagBindingConfig.cs b/plugin/TagBindingConfig.cs index 339de96..1165d99 100644 --- a/plugin/TagBindingConfig.cs +++ b/plugin/TagBindingConfig.cs @@ -157,8 +157,8 @@ namespace plugin } Debug.WriteLine(string.Join(";", trackSavedTags)); - Properties.Settings.Default.separateTagBindings = separateCheckBox.Checked; Properties.Settings.Default.recordingTagBindings = string.Join(";", trackSavedTags); + Properties.Settings.Default.separateTagBindings = separateCheckBox.Checked; // this setting could have been changed so trust the check box over the setting. Either way we'll save the check box state afterwards. if (separateCheckBox.Checked) @@ -207,5 +207,40 @@ namespace plugin this.Close(); } + + private void HandleListBoxCheck(object sender, ItemCheckEventArgs listBoxItem) + { + CheckedListBox listBox = (CheckedListBox)sender; + + int checkedItemCount = listBox.CheckedItems.Count; + if (listBoxItem.NewValue == CheckState.Checked) + { + checkedItemCount++; + } + else + { + checkedItemCount--; + } + + if (checkedItemCount == 0) + { + listBoxItem.NewValue = CheckState.Checked; + } + } + + private void trackListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + HandleListBoxCheck(sender, e); + } + + private void releaseListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + HandleListBoxCheck(sender, e); + } + + private void releaseGroupListBox_ItemCheck(object sender, ItemCheckEventArgs e) + { + HandleListBoxCheck(sender, e); + } } } diff --git a/plugin/TagBindingConfig.resx b/plugin/TagBindingConfig.resx index 07c9a23..db1597a 100644 --- a/plugin/TagBindingConfig.resx +++ b/plugin/TagBindingConfig.resx @@ -117,12 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - Append is enabled by default to prevent the accidental wiping of tags you already have saved to MusicBrainz. If you are happy with replacing already existing tags, choose the second option. - -A "smart" mode is planned for a future release, which will compare the two and remove only ones that have been removed from your local tags, keeping other tags intact. - - True @@ -135,4 +129,10 @@ A "smart" mode is planned for a future release, which will compare the two and r True + + Append is enabled by default to prevent the accidental wiping of tags you already have saved to MusicBrainz. If you are happy with replacing already existing tags, choose the second option. + +A "smart" mode is planned for a future release, which will compare the two and remove only ones that have been removed from your local tags, keeping other tags intact. + + \ No newline at end of file diff --git a/plugin/TrackObject.cs b/plugin/TrackObject.cs index 2d8993d..185bff7 100644 --- a/plugin/TrackObject.cs +++ b/plugin/TrackObject.cs @@ -36,19 +36,6 @@ namespace plugin private static readonly HashSet bannedExtensions = new HashSet { ".tak", ".midi", ".mid", ".xm", ".uxm", ".mod" }; - private List GetTagsToList(string path, MetaDataType tag) - { - List tags = new List(); - // MusicBee splits multi-value tags with a semicolon, so we need to split them and trim them. - // Todo: see if this works with AAC. AAC can be really funky across the board. - foreach (string tagString in mbApiInterface.Library_GetFileTag(path, tag).Split(';').ToList()) - { - string trimmedTag = tagString.Trim(); - tags.Add(trimmedTag); - } - return tags; - } - public MusicBeeTrack(string path) { string fileExt = Path.GetExtension(path); @@ -95,49 +82,75 @@ namespace plugin { // get the tags the user has chosen to submit List tagsToSearch = new List(); + Debug.WriteLine(tagsToSearch.Count); List tagList = new List(); if (type == "recording" || !Settings.Default.separateTagBindings) { - tagsToSearch = Settings.Default.recordingTagBindings.Split(';').ToList(); + if (!string.IsNullOrEmpty(Settings.Default.recordingTagBindings)) + { + tagsToSearch = Settings.Default.recordingTagBindings.Split(';').ToList(); + } } else { switch (type) { case "release": - tagsToSearch = Settings.Default.releaseTagBindings.Split(';').ToList(); + if (!string.IsNullOrEmpty(Settings.Default.releaseTagBindings)) + { + tagsToSearch = Settings.Default.releaseTagBindings.Split(';').ToList(); + } break; case "release-group": - tagsToSearch = Settings.Default.releaseGroupTagBindings.Split(';').ToList(); + if (!string.IsNullOrEmpty(Settings.Default.releaseGroupTagBindings)) + { + tagsToSearch = Settings.Default.releaseGroupTagBindings.Split(';').ToList(); + } break; } } Debug.WriteLine("tagsToSearch: " + string.Join(", ", tagsToSearch)); - foreach (string tag in tagsToSearch) + Debug.WriteLine(tagsToSearch.Count); + if (tagsToSearch.Count > 0) { - // get tag from finding its key in the dictionary then add to get track tags. - MetaDataType tagType = listTagBindings[tag]; - Debug.Write("got tag binding!"); - // clean up tags - List tagValue = mbApiInterface.Library_GetFileTag(FilePath, tagType).Split(';').ToList(); - foreach (string tagString in tagValue) + foreach (string tag in tagsToSearch) { - // do not try to add tags if tagString is empty, otherwise it will add empty strings. - if (!string.IsNullOrEmpty(tagString)) + // get tag from finding its key in the dictionary then add to get track tags. + MetaDataType tagType = listTagBindings[tag]; + // clean up tags + List tagValue = mbApiInterface.Library_GetFileTag(FilePath, tagType).Split(';').ToList(); + foreach (string tagString in tagValue) { - string trimmedTag = tagString.Trim(); - if (!tagList.Contains(trimmedTag)) + // do not try to add tags if tagString is empty, otherwise it will add empty strings. + if (!string.IsNullOrEmpty(tagString)) { - tagList.Add(trimmedTag); + string trimmedTag = tagString.Trim(); + if (!tagList.Contains(trimmedTag)) + { + tagList.Add(trimmedTag); + } } } - } + } + if (tagList.Count > 0) + { + return tagList; + } + else + { + return null; + } + } - return tagList; + else + { + return null; + } + } }