Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- name: Restore NuGet Packages
run: nuget restore AMDiscordRPC.sln
- name: Build
run: msbuild AMDiscordRPC.sln -property:Configuration=Release -property:platform="x64"
run: msbuild AMDiscordRPC.sln -property:Configuration=Debug -property:platform="x64"
- name: Zip
run: powershell Compress-Archive -Path ./AMDiscordRPC/bin/x64/Release -DestinationPath Release.zip
run: powershell Compress-Archive -Path ./AMDiscordRPC/bin/x64/Debug -DestinationPath Dev-Release.zip
- name: Release
uses: softprops/action-gh-release@v2
with:
Expand All @@ -31,4 +31,4 @@ jobs:
Don't use this version if you want more stable experience.
prerelease: true
files: |
Release.zip
Dev-Release.zip
87 changes: 50 additions & 37 deletions AMDiscordRPC/AMDiscordRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,44 @@ internal class AMDiscordRPC
private static string oldAlbumnArtist;
static void Main(string[] args)
{
ConfigureLogger();
// SetToken();
InitRegion();
CreateUI();
ConfigureLogger();
InitializeDiscordRPC();
AttachToAppleMusic();
InitDiscordRPC();
AttachToAM();
// ListBuckets();
AMSongDataEvent.SongChanged += async (sender, x) =>
{
log.Info($"Song: {x.SongName} \\ Artist and Album: {x.ArtistandAlbumName}");
AMDiscordRPCTray.ChangeSongState($"{x.ArtistandAlbumName.Split('—')[0]} - {x.SongName}");
if (x.ArtistandAlbumName == oldAlbumnArtist && oldData.Assets.LargeImageKey != null)
{
SetPresence(x);
}
else
{
if (httpRes.Equals(new WebSongResponse()) || CoverThread != null)
{
httpRes = await GetCover(x.ArtistandAlbumName.Split('—')[1], Uri.EscapeDataString(x.ArtistandAlbumName + $" {x.SongName}"));
log.Debug($"Set Cover: {((httpRes.artworkURL != null) ? httpRes.artworkURL : null)}");
}
SetPresence(x, httpRes);
oldAlbumnArtist = x.ArtistandAlbumName;
}
};
{
log.Info($"Song: {x.SongName} \\ Artist and Album: {x.ArtistandAlbumName}");
AMDiscordRPCTray.ChangeSongState($"{x.ArtistandAlbumName.Split('—')[0]} - {x.SongName}");
if (x.ArtistandAlbumName == oldAlbumnArtist && oldData.Assets.LargeImageKey != null)
{
SetPresence(x);
}
else
{
if (httpRes.Equals(new SQLRPCResponse()) || CoverThread != null)
{
httpRes = await GetCover(
new AppleMusicScrapedData(
x.ArtistandAlbumName.Split(new string[] { " — " }, StringSplitOptions.None)[0],
x.SongName,
x.ArtistandAlbumName.Split(new string[] { " — " }, StringSplitOptions.None)[1],
(x.isSingle) ? SecondaryType.Single : (x.IsMV) ? SecondaryType.MV : (x.ArtistandAlbumName.Contains(" - EP") ? SecondaryType.EP : SecondaryType.Album)
));
log.Debug($"Set Cover: {((httpRes.coverURL != null) ? httpRes.coverURL : null)}");
}
SetPresence(x, httpRes);
oldAlbumnArtist = x.ArtistandAlbumName;
}
};
CheckDatabaseIntegrity();
InitDBCreds();
ConfigureFromDB();
CheckFFmpeg();
InitS3();
AMEvent();
}

static void AMEvent()
{
using (var automation = new UIA3Automation())
Expand Down Expand Up @@ -88,7 +95,7 @@ static void AMEvent()
{
for (var i = 0; i < windows.Length; i++)
{
if (windows[i].Name == "Apple Music") window = windows[i];
if (windows[i].Name == "Apple Music" && windows[i].FindFirstChild().Name == "Non Client Input Sink Window") window = windows[i];
}
}
else if (windows.Length == 1)
Expand Down Expand Up @@ -127,6 +134,7 @@ static void AMEvent()
string previousSong = string.Empty;
string previousArtistAlbum = string.Empty;
string lastFetchedArtistAlbum = string.Empty;
string lastFetchedSong = string.Empty;
AudioFormat format = AudioFormat.AAC;
bool resetStatus = false;
double oldValue = 0;
Expand All @@ -137,14 +145,14 @@ static void AMEvent()
{
try
{
var currentSong = listeningInfo[0].Name;
var currentSong = (listeningInfo[0].Properties.Name.IsSupported == true && listeningInfo[0].Name != "Connecting…") ? listeningInfo[0].Name : lastFetchedSong;
var currentArtistAlbum = (listeningInfo[1].Properties.Name.IsSupported == true) ? listeningInfo[1].Name : lastFetchedArtistAlbum;
var dashSplit = currentArtistAlbum.Split('-');
var subractThis = TimeSpan.FromSeconds(slider.AsSlider().Value + 1);
if (oldValue == 0) oldValue = slider.AsSlider().Value;
DateTime currentTime = DateTime.UtcNow;
DateTime startTime = currentTime.Subtract(subractThis);
DateTime endTime = currentTime.AddSeconds(slider.AsSlider().Maximum).Subtract(subractThis);
DateTime endTime = startTime.AddSeconds(slider.AsSlider().Maximum);
DateTime oldEndTime = DateTime.MinValue;
DateTime oldStartTime = DateTime.MinValue;
bool isSingle = dashSplit[dashSplit.Length - 1].Contains("Single");
Expand Down Expand Up @@ -172,7 +180,7 @@ static void AMEvent()
oldValue = slider.AsSlider().Value;
}

if (currentArtistAlbum != lastFetchedArtistAlbum)
if (currentArtistAlbum != lastFetchedArtistAlbum || currentSong != lastFetchedSong)
{
if (CoverThread != null)
{
Expand All @@ -181,15 +189,22 @@ static void AMEvent()
}
else log.Debug("Continue");
string idontknowwhatshouldinamethisbutitsaboutalbum = (isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray());
CheckAndInsertAlbum(idontknowwhatshouldinamethisbutitsaboutalbum.Split('—')[1]);
Task t = new Task(async () =>
{
httpRes = await GetCover(idontknowwhatshouldinamethisbutitsaboutalbum.Split('—')[1], Uri.EscapeDataString((isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray()) + $" {currentSong}"));
log.Debug($"Set Cover: {((httpRes.artworkURL != null) ? httpRes.artworkURL : null)}");
httpRes = await GetCover(
new AppleMusicScrapedData(
idontknowwhatshouldinamethisbutitsaboutalbum.Split(new string[] { " — " }, StringSplitOptions.None)[0],
currentSong,
idontknowwhatshouldinamethisbutitsaboutalbum.Split(new string[] { " — " }, StringSplitOptions.None)[1],
(isSingle) ? SecondaryType.Single : (idontknowwhatshouldinamethisbutitsaboutalbum.Split('—').Length <= 1) ? SecondaryType.MV : (idontknowwhatshouldinamethisbutitsaboutalbum.Contains(" - EP") ? SecondaryType.EP : SecondaryType.Album)
)
);
log.Debug($"Set Cover: {((httpRes.coverURL != null) ? httpRes.coverURL : null)}");
});
CoverThread = t;
t.Start();
lastFetchedArtistAlbum = currentArtistAlbum;
lastFetchedSong = currentSong;
}

if (slider.AsSlider().Maximum != 0 && slider.AsSlider().Value != 0 && endTime != startTime && (currentSong != previousSong || currentArtistAlbum != previousArtistAlbum) && oldEndTime != endTime && oldStartTime != startTime)
Expand All @@ -214,11 +229,9 @@ static void AMEvent()
}
else format = AudioFormat.AAC;
oldValue = 0;
startTime = currentTime.Subtract(subractThis);
endTime = currentTime.AddSeconds(slider.AsSlider().Maximum).Subtract(subractThis);
oldStartTime = startTime;
oldEndTime = endTime;
AMSongDataEvent.ChangeSong(new SongData(currentSong, (isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray()), currentArtistAlbum.Split('—').Length <= 1, startTime, endTime, format));
AMSongDataEvent.ChangeSong(new SongData(currentSong, (isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray()), currentArtistAlbum.Split('—').Length <= 1, startTime, endTime, format, isSingle));
}

if (playButton?.Name != null && (localizedPlay != null && localizedPlay == playButton?.Name || localizedStop != null && localizedStop != playButton?.Name))
Expand Down Expand Up @@ -249,20 +262,20 @@ static void AMEvent()
client.ClearPresence();
while (!AMAttached)
{
AttachToAppleMusic();
AttachToAM();
Thread.Sleep(1000);
}
AMEvent();
}
Thread.Sleep(20);
}
if (!AMAttached & AppleMusicProc.HasExited != true)
if (!AMAttached && AppleMusicProc.HasExited != true)
{
log.Info("Something happened which needs to reattach");
client.ClearPresence();
while (!AMAttached)
{
AttachToAppleMusic();
AttachToAM();
Thread.Sleep(1000);
}
AMEvent();
Expand All @@ -272,7 +285,7 @@ static void AMEvent()
{
while (!AMAttached)
{
AttachToAppleMusic();
AttachToAM();
Thread.Sleep(1000);
}
AMEvent();
Expand Down
33 changes: 29 additions & 4 deletions AMDiscordRPC/AMDiscordRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<WarningLevel>0</WarningLevel>
<WarningLevel>1</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
Expand Down Expand Up @@ -100,7 +100,11 @@
<ApplicationIcon>Resources\Logo Black.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="AngleSharp, Version=1.3.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>..\packages\AngleSharp.1.3.0\lib\net472\AngleSharp.dll</HintPath>
</Reference>
Expand All @@ -110,8 +114,8 @@
<Reference Include="AWSSDK.S3, Version=4.0.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604, processorArchitecture=MSIL">
<HintPath>..\packages\AWSSDK.S3.4.0.6.2\lib\net472\AWSSDK.S3.dll</HintPath>
</Reference>
<Reference Include="DiscordRPC, Version=1.5.0.51, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DiscordRichPresence.1.5.0.51\lib\net45\DiscordRPC.dll</HintPath>
<Reference Include="DiscordRPC, Version=1.6.1.70, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\DiscordRichPresence.1.6.1.70\lib\net45\DiscordRPC.dll</HintPath>
</Reference>
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.5.1\lib\net45\EntityFramework.dll</HintPath>
Expand All @@ -138,6 +142,15 @@
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=9.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.9.0.7\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.3595.46, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.3595.46\lib\net462\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.WinForms, Version=1.0.3595.46, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.3595.46\lib\net462\Microsoft.Web.WebView2.WinForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Wpf, Version=1.0.3595.46, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.3595.46\lib\net462\Microsoft.Web.WebView2.Wpf.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Registry.5.0.0\lib\net461\Microsoft.Win32.Registry.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -174,6 +187,7 @@
<Reference Include="System.Drawing.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Drawing.Common.9.0.7\lib\net462\System.Drawing.Common.dll</HintPath>
</Reference>
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Pipelines, Version=9.0.0.7, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.Pipelines.9.0.7\lib\net462\System.IO.Pipelines.dll</HintPath>
</Reference>
Expand All @@ -189,6 +203,7 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Security.AccessControl, Version=6.0.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.AccessControl.6.0.1\lib\net461\System.Security.AccessControl.dll</HintPath>
Expand Down Expand Up @@ -233,6 +248,7 @@
<ItemGroup>
<Compile Include="AMDiscordRPC.cs" />
<Compile Include="AppleMusic.cs" />
<Compile Include="Cloudflare.cs" />
<Compile Include="Database.cs" />
<Compile Include="Discord.cs" />
<Compile Include="Globals.cs" />
Expand All @@ -250,6 +266,9 @@
<Compile Include="UIComponents\InputWindow.xaml.cs">
<DependentUpon>InputWindow.xaml</DependentUpon>
</Compile>
<Compile Include="UIComponents\OptionsWindow.xaml.cs">
<DependentUpon>OptionsWindow.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
Expand All @@ -270,7 +289,7 @@
<ItemGroup>
<EmbeddedResource Include="log4netconf.xml" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
Expand All @@ -279,6 +298,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UIComponents\OptionsWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\AWSSDK.S3.4.0.6.2\analyzers\dotnet\cs\AWSSDK.S3.CodeAnalysis.dll" />
Expand Down Expand Up @@ -310,8 +333,10 @@
<Error Condition="!Exists('..\packages\EntityFramework.6.5.1\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.5.1\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.5.1\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.5.1\build\EntityFramework.targets'))" />
<Error Condition="!Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3595.46\build\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3595.46\build\Microsoft.Web.WebView2.targets'))" />
</Target>
<Import Project="..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('..\packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" />
<Import Project="..\packages\EntityFramework.6.5.1\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.5.1\build\EntityFramework.targets')" />
<Import Project="..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets" Condition="Exists('..\packages\System.ValueTuple.4.6.1\build\net471\System.ValueTuple.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3595.46\build\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3595.46\build\Microsoft.Web.WebView2.targets')" />
</Project>
Loading