Skip to content

Commit

Permalink
chore: deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
NextFire committed Nov 16, 2024
1 parent cd18815 commit c429ac3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@ name: CI
on:
push:
branches: ["main", "renovate/*"]
tags: ["*"]
pull_request:
branches: ["main"]
workflow_dispatch:

jobs:
check:
if: startsWith(github.ref, 'refs/tags/') != true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
- run: deno fmt --check
- run: deno lint
if: always()
- run: deno check --allow-import music-rpc.ts
if: always()

compile:
runs-on: ubuntu-latest
env:
Expand Down
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["denoland.vscode-deno"]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"deno.enable": true,
"deno.unstable": true
"deno.unstable": ["kv"],
"[markdown][typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# apple-music-discord-rpc

**[Deno](https://deno.com) + JavaScript for Automation (JXA) Discord Rich Presence Client for the macOS Apple Music app (Catalina and later) and legacy iTunes.**
**[Deno](https://deno.com) + JavaScript for Automation (JXA) Discord Rich
Presence Client for the macOS Apple Music app (Catalina and later) and legacy
iTunes.**

Works with local tracks and Apple Music streaming service.

Expand All @@ -10,14 +12,17 @@ Works with local tracks and Apple Music streaming service.
- No status bar icon clutter
- Small and (quite) easy to understand script
- Presence is only enabled when actually playing something
- Apple Music matching ([#5](https://github.com/NextFire/apple-music-discord-rpc/pull/5))
- MusicBrainz artwork fallback ([#66](https://github.com/NextFire/apple-music-discord-rpc/pull/66))
- Apple Music matching
([#5](https://github.com/NextFire/apple-music-discord-rpc/pull/5))
- MusicBrainz artwork fallback
([#66](https://github.com/NextFire/apple-music-discord-rpc/pull/66))

<img width="350" alt="Screenshot 2024-08-29 at 20 05 10" src="https://github.com/user-attachments/assets/dbfd53ab-a958-431a-b2bc-34ea3e835d25">

## Getting Started

Follow one of the two sections below to download the script and enable the macOS launch agent that will start it at login.
Follow one of the two sections below to download the script and enable the macOS
launch agent that will start it at login.

### Homebrew (Recommended)

Expand Down Expand Up @@ -51,15 +56,17 @@ brew untap nextfire/tap

#### Install

Install [Deno](https://deno.com) (v2+), clone the repository and execute [`install.sh`](/scripts/install.sh):
Install [Deno](https://deno.com) (v2+), clone the repository and execute
[`install.sh`](/scripts/install.sh):

```
git clone https://github.com/NextFire/apple-music-discord-rpc.git
cd apple-music-discord-rpc/
./scripts/install.sh
```

It will copy the [launch agent](/scripts/moe.yuru.music-rpc.plist) into `~/Library/LaunchAgents/` and edit it accordingly.
It will copy the [launch agent](/scripts/moe.yuru.music-rpc.plist) into
`~/Library/LaunchAgents/` and edit it accordingly.

#### Uninstall

Expand Down
14 changes: 7 additions & 7 deletions music-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AppleMusicDiscordRPC {
public readonly appName: iTunesAppName,
public readonly rpc: Client,
public readonly kv: Deno.Kv,
public readonly defaultTimeout: number
public readonly defaultTimeout: number,
) {}

async run(): Promise<void> {
Expand Down Expand Up @@ -101,7 +101,7 @@ class AppleMusicDiscordRPC {
await this.rpc.setActivity(activity);
return Math.min(
(delta ?? this.defaultTimeout) + 1000,
this.defaultTimeout
this.defaultTimeout,
);
}

Expand Down Expand Up @@ -200,7 +200,7 @@ async function fetchTrackExtras(props: iTunesProps): Promise<TrackExtras> {
result = json.results.find(
(r) =>
r.collectionName.toLowerCase().includes(props.album.toLowerCase()) &&
r.trackName.toLowerCase().includes(props.name.toLowerCase())
r.trackName.toLowerCase().includes(props.name.toLowerCase()),
);
} else if (props.album.match(/\(.*\)$/)) {
// If there are no results, try to remove the part
Expand All @@ -219,7 +219,7 @@ async function fetchTrackExtras(props: iTunesProps): Promise<TrackExtras> {

async function iTunesSearch(
{ name, artist, album }: iTunesProps,
retryCount: number = 3
retryCount: number = 3,
): Promise<iTunesSearchResponse | undefined> {
// Asterisks tend to result in no songs found, and songs are usually able to be found without it
const query = `${name} ${artist} ${album}`.replace("*", "");
Expand All @@ -238,7 +238,7 @@ async function iTunesSearch(
resp.statusText,
url,
i + 1,
retryCount
retryCount,
);
resp.body?.cancel();
await sleep(200);
Expand All @@ -258,7 +258,7 @@ async function musicBrainzArtwork({
const queryTerms = [];
if (!MB_EXCLUDED_NAMES.every((elem) => artist.includes(elem))) {
queryTerms.push(
`artist:"${luceneEscape(removeParenthesesContent(artist))}"`
`artist:"${luceneEscape(removeParenthesesContent(artist))}"`,
);
}
if (!MB_EXCLUDED_NAMES.every((elem) => album.includes(elem))) {
Expand All @@ -280,7 +280,7 @@ async function musicBrainzArtwork({
for (const release of json.releases) {
const resp = await fetch(
`https://coverartarchive.org/release/${release.id}/front`,
{ method: "HEAD" }
{ method: "HEAD" },
);
await resp.body?.cancel();
if (resp.ok) {
Expand Down

0 comments on commit c429ac3

Please sign in to comment.