Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
1.0.0.2
Browse files Browse the repository at this point in the history
Improved Song sharing
Added autostart option
Added Genius search
  • Loading branch information
Nils Kleinert committed Jun 9, 2021
1 parent 048fc0b commit 2404fd9
Show file tree
Hide file tree
Showing 8 changed files with 1,145 additions and 957 deletions.
7 changes: 6 additions & 1 deletion APMDC/APMDC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icons8-music-512.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DiscordRPC, Version=1.0.175.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\DiscordRichPresence.1.0.175\lib\net35\DiscordRPC.dll</HintPath>
Expand Down Expand Up @@ -119,6 +122,8 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="icons8-music-512.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
14 changes: 7 additions & 7 deletions APMDC/Class/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand Down Expand Up @@ -36,14 +37,13 @@ await client.SendAsync(request)
var share = JsonConvert.DeserializeObject<ShareRequest>(result);

if (share?.Share != null)
foreach (var canShare in share?.Share)
if (canShare.TrackTimeMillis / 1000 == currentTrack.Duration)
{
Process.Start("https://song.link/i/" + canShare.TrackId);
return;
}
foreach (var canShare in (share?.Share).Where(canShare => canShare.TrackTimeMillis / 1000 == currentTrack.Duration))
{
Process.Start("https://song.link/i/" + canShare.TrackId);
return;
}

Main.taskIcon.ShowBalloonTip(3000, "Error", "Could not find the Song!", ToolTipIcon.Error);
Main.taskbarNotify.ShowBalloonTip(3000, "Error", "Could not find the Song!", ToolTipIcon.Error);
});
}
}
Expand Down
121 changes: 81 additions & 40 deletions APMDC/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions APMDC/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using APMDC.Class;
using System.Windows.Forms.VisualStyles;
using DiscordRPC;
using iTunesLib;
using Microsoft.Win32;
using static iTunesLib.ITPlayerState;
using WebRequest = APMDC.Class.WebRequest;

namespace APMDC
{
public partial class Main : Form
{
private readonly DiscordRpcClient discordRpc;
internal static iTunesApp iTunes;
internal static NotifyIcon taskbarNotify;
private readonly DiscordRpcClient discordRpc;
private readonly WebRequest webRequest;

public Main()
Expand All @@ -32,6 +35,7 @@ public Main()
iTunes.OnPlayerStopEvent += UpdateRichPresence;

webRequest = new WebRequest();
taskbarNotify = taskIcon;
}

private void UpdateRichPresence(object track)
Expand All @@ -40,11 +44,6 @@ private void UpdateRichPresence(object track)

var song = (IITTrack) track;

Debug.WriteLine(song.trackID);
Debug.WriteLine(song.Artist);
Debug.WriteLine(song.Name);
Debug.WriteLine(song.Album);

var timestamp = new Timestamps(DateTime.UtcNow.AddSeconds(-iTunes.PlayerPosition),
DateTime.UtcNow.AddSeconds(song.Duration - iTunes.PlayerPosition));

Expand Down Expand Up @@ -80,12 +79,18 @@ private void Main_Load(object sender, EventArgs e)
State = "Waiting for music 🎶"
});
UpdateRichPresence(iTunes?.CurrentTrack);

//Load user settings
var startup = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", false);
autostart.Checked = !string.IsNullOrEmpty((string)startup.GetValue(Application.ProductName));
}

private void Main_Closed(object sender, EventArgs e)
{
discordRpc.ClearPresence();
discordRpc?.Dispose();
Marshal.ReleaseComObject(iTunes);
Marshal.FinalReleaseComObject(iTunes);
}

private void generateIssue_Click(object sender, EventArgs e)
Expand All @@ -95,7 +100,7 @@ private void generateIssue_Click(object sender, EventArgs e)
var windows =
$"{Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "")}%20{Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DisplayVersion", "")}%20%28{Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuildNumber", "")}%29";
var para =
$"%2A%2AiTunes%20Version%3A%2A%2A%20{iTunes.Version}%0A%2A%2AWindows%3A%2A%2A%20{windows}%0A%2A%2AAPMDC%20Version%3A%2A%2A%20{Application.ProductVersion}%0A%20%20%0A%2A%2AiTunes%20location%3A%2A%2A%20{Path.GetDirectoryName(iTunesPath)}%0A%2A%2AIs%20UWP%20iTunes%3A%2A%2A%20{iTunesPath.Contains("WindowsApps")}%0A%0A%2A%2ADescribe%20your%20problem%3A%2A%2A";
$"%2A%2AiTunes%20Version%3A%2A%2A%20{iTunes.Version}%0A%2A%2AWindows%3A%2A%2A%20{windows}%0A%2A%2AAPMDC%20Version%3A%2A%2A%20{Application.ProductVersion}%0A%20%20%0A%2A%2AiTunes%20location%3A%2A%2A%20{WebUtility.UrlEncode(Path.GetDirectoryName(iTunesPath))}%0A%2A%2AIs%20UWP%20iTunes%3A%2A%2A%20{iTunesPath.Contains("WindowsApps")}%0A%0A%2A%2ADescribe%20your%20problem%3A%2A%2A";
Process.Start($"https://github.com/nils-kt/APMDC/issues/new?body={para}");
}

Expand All @@ -113,6 +118,13 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)

private void save_Click(object sender, EventArgs e)
{
var startup = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

if (autostart.Checked)
startup?.SetValue(Application.ProductName, Application.ExecutablePath);
else
startup?.DeleteValue(Application.ProductName, false);

ShowInTaskbar = false;
TopMost = false;
Hide();
Expand All @@ -123,5 +135,11 @@ private void shareToolStripMenuItem_Click(object sender, EventArgs e)
var song = iTunes?.CurrentTrack;
Task.Run(async () => { await webRequest.SearchSongAsync(); });
}

private void geniusToolStripMenuItem_Click(object sender, EventArgs e)
{
var song = iTunes?.CurrentTrack;
Process.Start($"https://genius.com/search?q={WebUtility.UrlEncode(song.Artist)}%20{WebUtility.UrlEncode(song.Name)}");
}
}
}
Loading

0 comments on commit 2404fd9

Please sign in to comment.