Skip to content

Commit

Permalink
Fix spotify connector
Browse files Browse the repository at this point in the history
Add more ad URLs to skip.

Ref #1599 (comment).
  • Loading branch information
alexesprit committed Dec 11, 2019
1 parent 160f40a commit 631dd4c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/connectors/spotify.js
@@ -1,5 +1,12 @@
'use strict';

const adUrls = [
'utm_source=display',
'ad.doubleclick.net',
'spotify:playlist',
'shrt.spotify.com'
];

Connector.playerSelector = '.Root__now-playing-bar';

Connector.artistSelector = '.track-info__artists a';
Expand All @@ -20,15 +27,14 @@ Connector.isScrobblingAllowed = () => !isAdPlaying();

Connector.isPodcast = () => artistUrlIncludes('/show/');

/*
* When ad is playing, artist URL is like "https://shrt.spotify.com/XXX",
* otherwise URL leads to:
* a) an artist page https://open.spotify.com/artist/YYY;
* b) a podcast page https://open.spotify.com/show/ZZZ.
*/

function isAdPlaying() {
return artistUrlIncludes('shrt.spotify.com');
for (const adUrl of adUrls) {
if (artistUrlIncludes(adUrl)) {

This comment has been minimized.

Copy link
@inverse

inverse Dec 11, 2019

Member

What about doing $(Connector.artistSelector).attr('href') outside the loop? is this an expensive operation?

This comment has been minimized.

Copy link
@alexesprit

alexesprit Dec 11, 2019

Author Member

Yes, it should be outside the loop. I'll fix this tomorrow.

This comment has been minimized.

Copy link
@alexesprit

alexesprit Dec 12, 2019

Author Member

I realized the way I used to skip ads is wrong. Spotify has a great variety of ad URLs, and we can't easily handle them all.

I changed a condition to check if artist URL contains "/artist/" or "/show/" strings. If it's true, we are sure no ads are playing. :)

This comment has been minimized.

Copy link
@alexesprit

alexesprit Dec 12, 2019

Author Member

See e66d736 for details.

return true;
}
}

return false;
}

function artistUrlIncludes(str) {
Expand Down

0 comments on commit 631dd4c

Please sign in to comment.