Skip to content

Commit

Permalink
Audioaddict url (web-scrobbler#4260)
Browse files Browse the repository at this point in the history
* add getOriginUrl to retrive url for track when on player page for audioaddict sites

* fix lint errors

* last lint

* prettier

* better variable names

* prettierfix
  • Loading branch information
reubot authored Nov 16, 2023
1 parent ef50ee7 commit 256f1ef
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/connectors/radiotunes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const filter = MetadataFilter.createFilter({ artist: removeTrailingDash });

Connector.playerSelector = playerBar;

Connector.artistSelector = '.artist-name';
const artistSelector = '.artist-name';
Connector.artistSelector = artistSelector;

Connector.trackSelector = '.track-name';
const trackSelector = '.track-name';
Connector.trackSelector = trackSelector;

Connector.playButtonSelector = '.icon-play';

Expand Down Expand Up @@ -43,3 +45,32 @@ Connector.applyFilter(filter);
function removeTrailingDash(text: string) {
return text.replace(/\s-\s$/, '');
}

Connector.getOriginUrl = () => {
let playerArtist = Util.getTextFromSelectors(artistSelector);
const playerTitle = Util.getTextFromSelectors(trackSelector);
// track info from page area
const pageArtist = Util.getTextFromSelectors(
'.now-playing-component__artist',
);
const pageTitle = Util.getTextFromSelectors(
'.now-playing-component__title',
);
if (playerArtist !== null) {
playerArtist = playerArtist.trim();
if (playerArtist.endsWith(' -')) {
playerArtist = playerArtist.substring(0, playerArtist.length - 2);
}
}
// compare with player to make sure we are still on the page where the track originates
if (playerArtist === pageArtist && playerTitle === pageTitle) {
const url = new URL(document.location.href);
return (
url.origin +
Util.getAttrFromSelectors('.now-playing-component__title', 'href')
);
}
return document.location.href;
// for testing:
// + playerArtist + playerTitle + (playerArtist === pageArtist && playerTitle === pageTitle) + pageArtist + pageTitle;
};

0 comments on commit 256f1ef

Please sign in to comment.