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

Feature/delegating lookup #44

Merged
merged 10 commits into from
Jan 6, 2023
Merged

Conversation

dscalzi
Copy link
Contributor

@dscalzi dscalzi commented Jan 2, 2023

The DelegatedAudioLookup function allows the track lookup behavior to be injectable by the client application. This may be desired when isrc/name match lookup is not good enough, and additional logic needs to be applied.

Sample usage:

playerManager.registerSourceManager(new SpotifySourceManager(
        g.getSpotifyClientId(),
        g.getSpotifyClientSecret(),
        g.getSpotifyCountryCode(),
        playerManager,
        mirroringAudioTrack -> {
            final String ytsearch = "ytsearch:";

            // Try by isrc
            AudioItem item = AudioReference.NO_TRACK;
            if(mirroringAudioTrack.getISRC() != null) {
                item = mirroringAudioTrack.loadItem(
                        ytsearch + mirroringAudioTrack.getISRC());
                String title = null;
                if(item instanceof InternalAudioTrack casted) {
                    title = casted.getInfo().title;
                }
                else if(item instanceof AudioPlaylist casted) {
                    title = casted.getTracks().get(0).getInfo().title;
                }
                if(title != null) {
                    if(!title.toLowerCase().contains(mirroringAudioTrack.getInfo().title.toLowerCase())) {
                        log.info("Title Mismatch, Expected: {}. Actual: {}.", mirroringAudioTrack.getInfo().title, title);
                        item = AudioReference.NO_TRACK;
                    }
                }
            }
            // Try name + isrc
            if(item == AudioReference.NO_TRACK) {
                item = mirroringAudioTrack.loadItem(
                        ytsearch + mirroringAudioTrack.getInfo().title + " " + mirroringAudioTrack.getISRC());
            }

            if(item == AudioReference.NO_TRACK) {
                log.error("Failed to find track");
            }

            return item;
        }
));

@dscalzi dscalzi requested a review from topi314 January 2, 2023 22:55
@dscalzi dscalzi requested a review from topi314 January 4, 2023 02:12
Copy link
Owner

@topi314 topi314 left a comment

Choose a reason for hiding this comment

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

I moved & renamed some minor stuff. Like this it should be good to go. Let me know your thoughts

@topi314 topi314 added the enhancement New feature or request label Jan 5, 2023
@dscalzi
Copy link
Contributor Author

dscalzi commented Jan 5, 2023

I moved & renamed some minor stuff. Like this it should be good to go. Let me know your thoughts

I'm alright with the name change, but it's hard to tell what changed in the diff. Did you intend to change all the spaces to tabs?

@topi314
Copy link
Owner

topi314 commented Jan 5, 2023

yeah that was more or less intended. You can hide whitespace changes here
image

@dscalzi
Copy link
Contributor Author

dscalzi commented Jan 6, 2023

Works for me, go ahead and merge.

As a side note, 4 spaces is much more standard than using tabs, but feel free to use whatever you prefer.

@topi314 topi314 merged commit a571b9d into topi314:master Jan 6, 2023
@topi314
Copy link
Owner

topi314 commented Jan 6, 2023

ty for the contribution

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

Successfully merging this pull request may close these issues.

2 participants