Skip to content
Merged
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
34 changes: 34 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build .NET Framework (Dev Branch)

on:
push:
branches: [ "dev" ]

jobs:
build:
runs-on: windows-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: nuget/setup-nuget@v2
- name: Restore NuGet Packages
run: nuget restore AMDiscordRPC.sln
- name: Build
run: msbuild AMDiscordRPC.sln -property:Configuration=Release -property:platform="x64"
- name: Zip
run: powershell Compress-Archive -Path ./AMDiscordRPC/bin/x64/Release -DestinationPath Release.zip
- name: Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.run_id }}
name: Dev-Release BuildID-${{ github.run_id }}
body: |
This is a pre-release build from the dev branch.
Don't use this version if you want more stable experience.
prerelease: true
files: |
Release.zip
34 changes: 21 additions & 13 deletions AMDiscordRPC/AMDiscordRPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using static AMDiscordRPC.AppleMusic;
using static AMDiscordRPC.Covers;
using static AMDiscordRPC.Database;
using static AMDiscordRPC.Discord;
using static AMDiscordRPC.Globals;
using static AMDiscordRPC.S3;
using static AMDiscordRPC.UI;

namespace AMDiscordRPC
{
Expand All @@ -20,30 +20,33 @@ internal class AMDiscordRPC
private static string oldAlbumnArtist;
static void Main(string[] args)
{
InitRegion();
CreateUI();
ConfigureLogger();
InitializeDiscordRPC();
AttachToAppleMusic();
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 == Array.Empty<string>() || CoverThread != null)
if (httpRes.Equals(new WebSongResponse()) || CoverThread != null)
{
httpRes = await GetCover(x.ArtistandAlbumName.Split('—')[1], HttpUtility.UrlEncode(ConvertToValidString(x.ArtistandAlbumName) + $" {ConvertToValidString(x.SongName)}"));
log.Debug($"Set Cover: {((httpRes.Length > 0) ? httpRes[0] : 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;
}
};
CheckDatabaseIntegrity();
InitDBCreds();
CheckFFMpeg();
CheckFFmpeg();
InitS3();
AMEvent();
}
Expand Down Expand Up @@ -124,7 +127,7 @@ static void AMEvent()
string previousSong = string.Empty;
string previousArtistAlbum = string.Empty;
string lastFetchedArtistAlbum = string.Empty;
int audioStatus = 3;
AudioFormat format = AudioFormat.AAC;
bool resetStatus = false;
double oldValue = 0;

Expand Down Expand Up @@ -164,6 +167,7 @@ static void AMEvent()
}
else if (resetStatus == false && slider.AsSlider().Maximum != 0 && oldValue != 0 && currentSong == previousSong && currentArtistAlbum == previousArtistAlbum && startTime != endTime)
{
AMDiscordRPCTray.ChangeSongState($"{((isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray())).Split('—')[0]} - {currentSong}");
ChangeTimestamps(startTime, endTime);
oldValue = slider.AsSlider().Value;
}
Expand All @@ -180,8 +184,8 @@ static void AMEvent()
CheckAndInsertAlbum(idontknowwhatshouldinamethisbutitsaboutalbum.Split('—')[1]);
Task t = new Task(async () =>
{
httpRes = await GetCover(idontknowwhatshouldinamethisbutitsaboutalbum.Split('—')[1], HttpUtility.UrlEncode(ConvertToValidString((isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray())) + $" {ConvertToValidString(currentSong)}"));
log.Debug($"Set Cover: {((httpRes.Length > 0) ? httpRes[0] : null)}");
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)}");
});
CoverThread = t;
t.Start();
Expand All @@ -198,31 +202,35 @@ static void AMEvent()
switch (audioBadge?.Name)
{
case "Dolby Atmos":
audioStatus = 1;
format = AudioFormat.Dolby_Atmos;
break;
case "Dolby Audio":
audioStatus = 2;
format = AudioFormat.Dolby_Audio;
break;
default:
audioStatus = 0;
format = AudioFormat.Lossless;
break;
}
}
else audioStatus = 3;
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, audioStatus));
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));
}

if (playButton?.Name != null && (localizedPlay != null && localizedPlay == playButton?.Name || localizedStop != null && localizedStop != playButton?.Name))
{
localizedPlay = playButton.Name;
AMDiscordRPCTray.ChangeSongState("AMDiscordRPC");
client.ClearPresence();
resetStatus = true;
}
else if (resetStatus == true && playButton?.Name != null && localizedPlay != null && localizedPlay != playButton?.Name && slider.AsSlider().Maximum != 0)
{
AMDiscordRPCTray.ChangeSongState($"{((isSingle) ? string.Join("-", dashSplit.Take(dashSplit.Length - 1).ToArray()) : string.Join("—", currentArtistAlbum.Split('—').Take(2).ToArray())).Split('—')[0]} - {currentSong}");
ChangeTimestamps(startTime, endTime);
resetStatus = false;
}
Expand Down
Loading
Loading