Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎵Artwork Rendering #6

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

joaoprp
Copy link

@joaoprp joaoprp commented Jun 21, 2023

Added Artwork on RPC Status Bar coming from SBApplication

MusicTrack has a method that returns one album cover whenever it is available

Added new search endpoint

GET /lookup is a more reliable source of collecting data, once if you have the album ID, it should be one and only. Once playerInfo moves, if it's a song pulled from Apple Music that is available to buy on iTunes, an itmss:// url appears that we can pluck album ID

Improved search URL

searching by entity=album returns albums, but it was all over the place. using the term=\(artist) and attribute=artistTerm we can guarantee that all the data returned is from the specific artists, leaving us to find the right album through the app

Caveats

  • while working on this, I removed the condition preventing request/replace a cover from the same album. I'll try to get this sorted out before you get to review this, but as of now every new song is a request to iTunes and the icon flashes on Discord. I kept the query, but I fixed the flickering. iTunes allows 20 requests/minute, it shouldn't be a problem for most users.

  • you'll need to put your developer id back to build (but you might know that). Opening through Xcode to run/debug forces you to change into your own dev id and I pushed it to you as it was "mine".

Copy link
Owner

@sunsetsonwheels sunsetsonwheels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the PR! I've found a few lines that needs changing before this can be merged.

By the way, since we still have to fetch the artwork URL from iTunes to set it for Discord, I don't think getting the artwork from MusicTrack to display in the UI is very useful since it might not match the one we got from iTunes, confusing users. Don't get me wrong, it's great that you got it working, I just feel like there's little utility to it.

@@ -121,11 +121,13 @@ class DiscordRPCObservable: ObservableObject {
self.artwork.album = album
// if no artworks embbeded to the file, it returns nil so RPCStatusView can render no artwork
self.artwork.url = artworks?.first?.data ?? nil

self.rpc.setPresence(presence)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this does anything, since the presence setting happens inside the dataTask closure after we've fetched the artwork from iTunes.

self.artwork.url = nil
}
self.rpc.setPresence(presence)
self.artwork.url = nil
Copy link
Owner

@sunsetsonwheels sunsetsonwheels Jun 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated on the main thread. Also, presence.assets.largeImage should be set to applemusic_large so there's no empty box on Discord.

@@ -49,7 +55,8 @@ class DiscordRPCObservable: ObservableObject {

private let logger: Logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "DiscordRPCObservable")
private let jsond: JSONDecoder = JSONDecoder()

private var albumId: Int = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be moved to the DiscordRPCData struct.

}

@Published var musicArt: Data?;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unused, should be removed.

@joaoprp
Copy link
Author

joaoprp commented Jun 30, 2023

Hey, thanks for the PR! I've found a few lines that needs changing before this can be merged.

By the way, since we still have to fetch the artwork URL from iTunes to set it for Discord, I don't think getting the artwork from MusicTrack to display in the UI is very useful since it might not match the one we got from iTunes, confusing users. Don't get me wrong, it's great that you got it working, I just feel like there's little utility to it.

Hey, thanks for reviewing it!

It makes sense your train of thoughts and I indeed did think in just update the URL request and avoid everything else over the code. It was intentional on my part to capture the artwork for a few main reasons:

  1. Anything that comes from Apple Music should have the same cover, so for the most part it wouldn't have any differences
  2. Someone with local MP3 files would be the ones affected, for the most part
  3. It'll save us some time for one extra update, passing MusicTrack image as a base64 blob data.

My original plan was to do the point 3, but the request seems to be too large, due to the base64 size. SwordRPC being discontinued didn't help as much because it discards any exceptions to http requests for me to tinker and get the payload 100%. My plan is to fork it, make sure I could send any blob data properly and then get rid of http requests entirely.

If you prefer, I can keep this PR out for a while and update the fetch just for improved search on start + lookup on every other request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants