Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
fix playlists with all access tracks [#10]
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-weber committed Nov 27, 2015
1 parent ce3b2a2 commit db703ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/js/googlemusic.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ function addTracks(userIndex, playlistId, tracks, callback) {

console.log('adding', tracks.length);

// [["<sessionid>",1],["<listid>",[["<songid>",2]]]]
// [["<sessionid>",1],["<listid>",[["<store id or songid>",tracktype]]]]
const payload = [['', 1],
[
playlistId, tracks.map(track => {return [track.id, track.type];}),
playlistId, tracks.map(t => {return [Track.getPlaylistAddId(t), t.type];}),
],
];
authedGMRequest('addtrackstoplaylist', payload, userIndex, 'post', response => {
Expand All @@ -189,17 +189,19 @@ exports.setPlaylistTo = function setPlaylistTo(userIndex, playlistId, tracks, ca
const idsToAdd = {};
for (let i = 0; i < tracks.length; i++) {
const track = tracks[i];
idsToAdd[track.id] = track;
idsToAdd[Track.getPlaylistAddId(track)] = track;
}

const entriesToDelete = [];
for (let i = 0; i < gentries.length; i++) {
const gentry = gentries[i];
const entry = {id: gentry[0], entryId: gentry[43]};
if (!(entry.id in idsToAdd)) {
entriesToDelete.push(entry);
const remoteTrack = Track.fromJsproto(gentry);

if (!(Track.getPlaylistAddId(remoteTrack) in idsToAdd)) {
// tracks that can only be added with store ids can be deleted with library ids.
entriesToDelete.push({id: remoteTrack.id, entryId: gentry[43]});
} else {
delete idsToAdd[entry.id];
delete idsToAdd[Track.getPlaylistAddId(remoteTrack)];
}
}

Expand Down
16 changes: 15 additions & 1 deletion src/js/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ exports.fields = [
label: 'last played',
explanation: 'when the track was last played, eg "30 days ago" or "yesterday". Sometimes inaccurate.',
is_datetime: true}),
f([27, 'storeId', Lf.Type.STRING], {
label: 'store id'}),
f([29, 'type', Lf.Type.INTEGER], {
explanation: '1: free/purchased, 2: uploaded but not matched, 6: uploaded and matched.'}),
explanation: '1: free/purchased, 2: uploaded but not matched, 6: uploaded and matched, 7: All Access'}),
f([30, 'comment', Lf.Type.STRING]),
f([34, 'bitrate', Lf.Type.INTEGER]),
];
Expand All @@ -77,3 +79,15 @@ exports.fromJsproto = function fromJsproto(jsproto) {

return track;
};

exports.getPlaylistAddId = function getPlaylistAddId(track) {
// Return the id for this track when interacting with Google.
// For some reason Google doesn't accept AA playlist adds with library ids.
let id = track.id;

if (track.type === 7) {
id = track.storeId;
}

return id;
};

0 comments on commit db703ab

Please sign in to comment.