Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Google Play Music: add favorites support #220

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/plugins/web/googleplaymusic/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function getButtons() {
playpause: document.getElementById("player-bar-play-pause"),
skip: document.getElementById("player-bar-forward"),
back: document.getElementById("player-bar-rewind"),
thumbUp: document.querySelector('#player .player-rating-container [icon^="sj:thumb-"][data-rating="5"]'),
seekBar: document.getElementById('progressContainer')
};
}
Expand Down Expand Up @@ -132,12 +133,25 @@ function update() {

var canSeek = getButtons().seekBar != null && duration != 0;

// Adapted from gmusic.js
// please see https://github.com/gmusic-utils/gmusic.js/blob/master/src/namespaces/RatingNamespace.js
// and https://github.com/gmusic-utils/gmusic.js/blob/master/src/constants/selectors.js

elm = getButtons().thumbUp;
var canAddToFavorites = elm != null && playbackStatus != mellowplayer.PlaybackStatus.STOPPED;
var isFavorite = false;
try {
isFavorite = elm.__data__.icon === 'thumb-up';
} catch (e) {
canAddToFavorites = false;
}

return {
"playbackStatus": playbackStatus,
"canSeek": canSeek,
"canGoNext": true,
"canGoPrevious": true,
"canAddToFavorites": false,
"canAddToFavorites": canAddToFavorites,
"volume": 1,
"duration": duration,
"position": position,
Expand All @@ -146,7 +160,7 @@ function update() {
"artistName": artistName,
"albumTitle": albumTitle,
"artUrl": artUrl,
"isFavorite": false
"isFavorite": isFavorite
}
}

Expand Down Expand Up @@ -183,13 +197,13 @@ function setVolume(volume) {

function addToFavorites() {

// not currently supported
getButtons().thumbUp.click();

}

function removeFromFavorites() {

// not currently supported
getButtons().thumbUp.click();

}

Expand Down