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
27 changes: 12 additions & 15 deletions AMDiscordRPC/AMDiscordRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ internal class AMDiscordRPC
private static string oldAlbumnArtist;
static void Main(string[] args)
{
ConfigureLogger();
InitRegion();
CreateUI();
ConfigureLogger();
InitializeDiscordRPC();
AttachToAppleMusic();
InitDiscordRPC();
AttachToAM();
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)
Expand All @@ -43,9 +43,9 @@ static void Main(string[] args)
SetPresence(x, httpRes);
oldAlbumnArtist = x.ArtistandAlbumName;
}
};
};
CheckDatabaseIntegrity();
InitDBCreds();
ConfigureFromDB();
CheckFFmpeg();
InitS3();
AMEvent();
Expand Down Expand Up @@ -88,7 +88,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 @@ -144,7 +144,7 @@ static void AMEvent()
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 @@ -181,7 +181,6 @@ 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}"));
Expand Down Expand Up @@ -214,8 +213,6 @@ 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));
Expand Down Expand Up @@ -249,20 +246,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 +269,7 @@ static void AMEvent()
{
while (!AMAttached)
{
AttachToAppleMusic();
AttachToAM();
Thread.Sleep(1000);
}
AMEvent();
Expand Down
21 changes: 21 additions & 0 deletions AMDiscordRPC/AMDiscordRPC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<ApplicationIcon>Resources\Logo Black.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup />
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<ItemGroup>
<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>
Expand Down Expand Up @@ -138,6 +141,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 @@ -250,6 +262,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 Down Expand Up @@ -279,6 +294,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 +329,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>
4 changes: 4 additions & 0 deletions AMDiscordRPC/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.4.0" newVersion="4.2.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Win32.Registry" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
Expand Down
4 changes: 2 additions & 2 deletions AMDiscordRPC/AppleMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace AMDiscordRPC
{
internal class AppleMusic
{
public static void AttachToAppleMusic()
public static void AttachToAM()
{
try
{
AppleMusicProc = Application.Attach("AppleMusic.exe");
AMAttached = true;
log.Info($"Attached to Process Id: {AppleMusicProc.ProcessId}");
log.Info($"Attached to PID: {AppleMusicProc.ProcessId}");
}
catch (Exception e)
{
Expand Down
26 changes: 19 additions & 7 deletions AMDiscordRPC/Covers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AngleSharp.Html.Dom;
using AngleSharp.Dom;
using AngleSharp.Html.Dom;
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
Expand Down Expand Up @@ -30,9 +31,10 @@ private static async Task<WebSongResponse> AsyncFetchiTunes(string album, string
(
imageRes["results"][0]["artworkUrl100"].ToString(),
imageRes["results"][0]["trackViewUrl"].ToString(),
imageRes["results"][0]["collectionName"].ToString()
imageRes["results"][0]["collectionName"].ToString(),
imageRes["results"][0]["artistViewUrl"].ToString()
);
Database.UpdateAlbum(new Database.SQLCoverResponse(album, webRes.artworkURL, webRes.trackURL));
InsertAlbum(new SQLCoverResponse(album, webRes.artworkURL, webRes.trackURL, null, null, null, webRes.artistURL));
CoverThread = null;
return webRes;
}
Expand All @@ -58,21 +60,30 @@ private static async Task<WebSongResponse> AsyncFetchiTunes(string album, string
}
}

public static async Task<string> AsyncArtistProfileFetch(string url)
{
return null;
}

public static async Task<WebSongResponse> AsyncAMFetch(string album, string searchStr)
{
log.Debug($"https://music.apple.com/{AMRegion.ToLower()}/search?term={searchStr}");
try
{
HttpResponseMessage AMRequest = await hclient.GetAsync($"https://music.apple.com/{AMRegion.ToLower()}/search?term={searchStr}");
if (AMRequest.IsSuccessStatusCode)
{
string DOMasAString = await AMRequest.Content.ReadAsStringAsync();
IHtmlDocument document = parser.ParseDocument(DOMasAString);

WebSongResponse webRes = new WebSongResponse(
document.DocumentElement.QuerySelectorAll("div.top-search-lockup__artwork > div > picture > source")[1].GetAttribute("srcset").Split(' ')[0],
document.DocumentElement.QuerySelector("div.top-search-lockup__action > a").GetAttribute("href")
document.DocumentElement.QuerySelectorAll("div.track-lockup__artwork-wrapper > div > picture > source")[1].GetAttribute("srcset").Split(',')[1].Split(' ')[0],
document.DocumentElement.QuerySelectorAll("div.track-lockup__clamp-wrapper > a")[0].GetAttribute("href"),
null,
document.DocumentElement.QuerySelectorAll("div.track-lockup__clamp-wrapper > span > a")[0].GetAttribute("href")
);
CoverThread = null;
Database.UpdateAlbum(new Database.SQLCoverResponse(album, webRes.artworkURL, webRes.trackURL));
InsertAlbum(new Database.SQLCoverResponse(album, webRes.artworkURL, webRes.trackURL, null, null, null, webRes.artistURL));
return webRes;
}
else
Expand All @@ -93,6 +104,7 @@ public static async Task CheckAnimatedCover(string album, string url, Cancellati
try
{
var appleMusicDom = await hclient.GetAsync(url);
log.Debug($"Animated Cover Request: {url}");
if (appleMusicDom.IsSuccessStatusCode)
{
string DOMasAString = await appleMusicDom.Content.ReadAsStringAsync();
Expand All @@ -117,7 +129,7 @@ public static async Task<WebSongResponse> GetCover(string album, string searchSt
{
try
{
log.Debug($"https://music.apple.com/us/search?term={searchStr}");
log.Debug($"https://music.apple.com/{AMRegion.ToLower()}/search?term={searchStr}");
SQLCoverResponse cover = GetAlbumDataFromSQL(album);
if (cover != null)
{
Expand Down
Loading