mirror of
https://github.com/Royce551/FRESHMusicPlayer.git
synced 2025-01-22 19:02:19 -05:00
stuff
This commit is contained in:
parent
c056adc5a9
commit
30d7c503be
5 changed files with 71 additions and 61 deletions
|
@ -15,10 +15,10 @@ namespace FRESHMusicPlayer.Forms.TagEditor.Integrations
|
|||
private readonly string Secret = "TaUMdjJnmmcjGttJbegdmRyOHyqQxljK";
|
||||
|
||||
public bool NeedsInternetConnection => true;
|
||||
public DiscogsIntegration()
|
||||
public bool Worked { get; set; } = true;
|
||||
public DiscogsIntegration(HttpClient httpClient)
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("FRESHMusicPlayer/8.2.0 (https://github.com/Royce551/FRESHMusicPlayer)");
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public TagEditorRelease Fetch(string id)
|
||||
|
@ -49,7 +49,14 @@ namespace FRESHMusicPlayer.Forms.TagEditor.Integrations
|
|||
public List<(string Name, string Id)> Search(string query)
|
||||
{
|
||||
var releases = new List<(string Name, string Id)>();
|
||||
var json = JObject.Parse(httpClient.GetStringAsync($"https://api.discogs.com/database/search?q={{{query}}}&{{track}}&per_page=1&key={Key}&secret={Secret}").Result);
|
||||
string jsonString;
|
||||
try { jsonString = httpClient.GetStringAsync($"https://api.discogs.com/database/search?q={{{query}}}&{{track}}&per_page=1&key={Key}&secret={Secret}").Result; }
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
Worked = false;
|
||||
return releases;
|
||||
}
|
||||
var json = JObject.Parse(jsonString);
|
||||
var z = json.SelectToken("results"); // Format for searching: https://www.discogs.com/developers#page:database,header:database-search
|
||||
foreach (var x in z)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace FRESHMusicPlayer.Forms.TagEditor.Integrations
|
|||
interface IReleaseIntegration
|
||||
{
|
||||
bool NeedsInternetConnection { get; }
|
||||
bool Worked { get; set; }
|
||||
List<(string Name, string Id)> Search(string query);
|
||||
TagEditorRelease Fetch(string id);
|
||||
}
|
||||
|
|
|
@ -13,11 +13,11 @@ namespace FRESHMusicPlayer.Forms.TagEditor.Integrations
|
|||
{
|
||||
private readonly HttpClient httpClient;
|
||||
public bool NeedsInternetConnection => true;
|
||||
public bool Worked { get; set; } = true;
|
||||
|
||||
public MusicBrainzIntegration()
|
||||
public MusicBrainzIntegration(HttpClient httpClient)
|
||||
{
|
||||
httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("FRESHMusicPlayer/8.2.0 (https://github.com/Royce551/FRESHMusicPlayer)");
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
public TagEditorRelease Fetch(string id)
|
||||
|
@ -45,7 +45,14 @@ namespace FRESHMusicPlayer.Forms.TagEditor.Integrations
|
|||
public List<(string Name, string Id)> Search(string query)
|
||||
{
|
||||
var releases = new List<(string Name, string Id)>();
|
||||
var json = JObject.Parse(httpClient.GetStringAsync($"https://musicbrainz.org/ws/2/release/?query={query}&fmt=json").Result);
|
||||
string jsonString;
|
||||
try { jsonString = httpClient.GetStringAsync($"https://musicbrainz.org/ws/2/release/?query={query}&fmt=json").Result; }
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
Worked = false;
|
||||
return releases;
|
||||
}
|
||||
var json = JObject.Parse(jsonString);
|
||||
var z = json.SelectToken("releases");
|
||||
foreach (var x in z)
|
||||
{
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Net.Http;
|
||||
using Winforms = System.Windows.Forms;
|
||||
using System.Windows.Shapes;
|
||||
using FRESHMusicPlayer.Forms.TagEditor.Integrations;
|
||||
|
@ -22,9 +23,11 @@ namespace FRESHMusicPlayer.Forms.TagEditor
|
|||
private List<string> filePathsToSaveInBackground = new List<string>();
|
||||
List<string> Displayfilepaths = new List<string>();
|
||||
private bool unsavedChanges = false;
|
||||
private HttpClient httpClient = new HttpClient();
|
||||
public TagEditor(List<string> filePaths)
|
||||
{
|
||||
InitializeComponent();
|
||||
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("FRESHMusicPlayer/8.2.0 (https://github.com/Royce551/FRESHMusicPlayer)");
|
||||
FilePaths = filePaths;
|
||||
MainWindow.Player.SongChanged += Player_SongChanged;
|
||||
InitFields();
|
||||
|
@ -177,50 +180,49 @@ namespace FRESHMusicPlayer.Forms.TagEditor
|
|||
InitFields();
|
||||
}
|
||||
|
||||
private void DiscogsSourceMenuItem_Click(object sender, RoutedEventArgs e) => OpenAlbumIntegration(new DiscogsIntegration());
|
||||
private void MusicBrainzSourceMenuItem_Click(object sender, RoutedEventArgs e) => OpenAlbumIntegration(new MusicBrainzIntegration());
|
||||
private void DiscogsSourceMenuItem_Click(object sender, RoutedEventArgs e) => OpenAlbumIntegration(new DiscogsIntegration(httpClient));
|
||||
private void MusicBrainzSourceMenuItem_Click(object sender, RoutedEventArgs e) => OpenAlbumIntegration(new MusicBrainzIntegration(httpClient));
|
||||
private void OpenAlbumIntegration(IReleaseIntegration integration)
|
||||
{
|
||||
var dialog = new FMPTextEntryBox("Album", AlbumBox.Text);
|
||||
|
||||
var dialog = new FMPTextEntryBox(Properties.Resources.TRACKINFO_ALBUM, AlbumBox.Text);
|
||||
dialog.ShowDialog();
|
||||
if (!dialog.OK) return;
|
||||
|
||||
try
|
||||
string query = dialog.Response;
|
||||
var results = integration.Search(query);
|
||||
|
||||
var index = 0;
|
||||
if (!integration.Worked && integration.NeedsInternetConnection)
|
||||
{
|
||||
string query = dialog.Response;
|
||||
var results = integration.Search(query);
|
||||
|
||||
var index = 0;
|
||||
if (results.Count == 0)
|
||||
{
|
||||
MessageBox.Show("No results were found for this album :(", "FRESHMusicPlayer Tag Editor", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
if (results.Count > 1)
|
||||
{
|
||||
var disambiguation = new IntegrationDisambiguation(results);
|
||||
disambiguation.ShowDialog();
|
||||
if (disambiguation.OK) index = disambiguation.SelectedIndex;
|
||||
else return;
|
||||
}
|
||||
|
||||
var filePath = FilePaths[0];
|
||||
var release = integration.Fetch(results[index].Id);
|
||||
var editor = new ReleaseIntegrationPage(release, new Track(filePath), filePath);
|
||||
editor.ShowDialog();
|
||||
if (editor.OK)
|
||||
{
|
||||
ArtistBox.Text = editor.TrackToSave.Artist;
|
||||
TitleBox.Text = editor.TrackToSave.Title;
|
||||
AlbumBox.Text = editor.TrackToSave.Album;
|
||||
GenreBox.Text = editor.TrackToSave.Genre;
|
||||
YearBox.Text = editor.TrackToSave.Year.ToString();
|
||||
TrackNumBox.Text = editor.TrackToSave.TrackNumber.ToString();
|
||||
}
|
||||
MessageBox.Show("Looks like you aren't connected to the internet", "FRESHMusicPlayer Tag Editor", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
catch (System.Net.Http.HttpRequestException)
|
||||
if (results.Count == 0)
|
||||
{
|
||||
MessageBox.Show("No results were found for this album :(", "FRESHMusicPlayer Tag Editor", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
if (results.Count > 1)
|
||||
{
|
||||
var disambiguation = new IntegrationDisambiguation(results);
|
||||
disambiguation.ShowDialog();
|
||||
if (disambiguation.OK) index = disambiguation.SelectedIndex;
|
||||
else return;
|
||||
}
|
||||
|
||||
var filePath = FilePaths[0];
|
||||
var release = integration.Fetch(results[index].Id);
|
||||
var editor = new ReleaseIntegrationPage(release, new Track(filePath), filePath);
|
||||
editor.ShowDialog();
|
||||
if (editor.OK)
|
||||
{
|
||||
ArtistBox.Text = editor.TrackToSave.Artist;
|
||||
TitleBox.Text = editor.TrackToSave.Title;
|
||||
AlbumBox.Text = editor.TrackToSave.Album;
|
||||
GenreBox.Text = editor.TrackToSave.Genre;
|
||||
YearBox.Text = editor.TrackToSave.Year.ToString();
|
||||
TrackNumBox.Text = editor.TrackToSave.TrackNumber.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -583,24 +583,17 @@ namespace FRESHMusicPlayer
|
|||
{
|
||||
if (Environment.OSVersion.Version.Major >= 10 && App.Config.IntegrateSMTC)
|
||||
{
|
||||
try
|
||||
{
|
||||
var smtcInterop = (WindowsInteropUtils.ISystemMediaTransportControlsInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(SystemMediaTransportControls));
|
||||
Window window = GetWindow(this);
|
||||
var wih = new WindowInteropHelper(window);
|
||||
IntPtr hWnd = wih.Handle;
|
||||
Smtc = smtcInterop.GetForWindow(hWnd, new Guid("99FA3FF4-1742-42A6-902E-087D41F965EC"));
|
||||
Smtc.IsPlayEnabled = true;
|
||||
Smtc.IsPauseEnabled = true;
|
||||
Smtc.IsNextEnabled = true;
|
||||
Smtc.IsStopEnabled = true;
|
||||
Smtc.IsPreviousEnabled = true;
|
||||
Smtc.ButtonPressed += Smtc_ButtonPressed;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// TODO: HACK - ignored; the way i'm detecting windows 10 currently does not work
|
||||
}
|
||||
var smtcInterop = (WindowsInteropUtils.ISystemMediaTransportControlsInterop)WindowsRuntimeMarshal.GetActivationFactory(typeof(SystemMediaTransportControls));
|
||||
Window window = GetWindow(this);
|
||||
var wih = new WindowInteropHelper(window);
|
||||
IntPtr hWnd = wih.Handle;
|
||||
Smtc = smtcInterop.GetForWindow(hWnd, new Guid("99FA3FF4-1742-42A6-902E-087D41F965EC"));
|
||||
Smtc.IsPlayEnabled = true;
|
||||
Smtc.IsPauseEnabled = true;
|
||||
Smtc.IsNextEnabled = true;
|
||||
Smtc.IsStopEnabled = true;
|
||||
Smtc.IsPreviousEnabled = true;
|
||||
Smtc.ButtonPressed += Smtc_ButtonPressed;
|
||||
}
|
||||
else Smtc = null;
|
||||
if (App.Config.IntegrateDiscordRPC) Player.InitDiscordRPC("656678380283887626");
|
||||
|
|
Loading…
Reference in a new issue