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

artist top tracks to playlist feature, closes #60 #62

Merged
merged 1 commit into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions rdio-enhancer.css
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,20 @@
.Menu li.share.copy_link {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAMAAABFNRROAAAABGdBTUEAALGPC/xhBQAAAIpQTFRFuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJuMPJAAAAuMPJkvC3mwAAAC10Uk5T9mM8pbFOrqKZZsMVVPAzVznb4QN7YPPG3kKE+fzn5Ku0Gx4MvVF4JAYJdY0A/S76QAAAAHtJREFUCNctzFcWwjAMRFHRO6Gmh1Q7sa3Z//YQEfq7R+cNsV4Xdn5iUmQxgONTdYqx2qQ4qNw6Z15gP8tsE+tcAv+TlYaWA9Je9ELhvRnwGWXToohq+QqY2rI8u3BB3UlDBg3zGNp5m26orlmFt4oHadBMf/Xhcc8V/AVvFxghUQadAAAAAABJRU5ErkJggg==);
}

.artist_tracks_to_playlist {
float: right;
margin-right: 10px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAUCAMAAAC+oj0CAAAABGdBTUEAALGPC/xhBQAAAD9QTFRFlJmclJiclJmclJmclJmdlJmclJiclJmclJmclJmclJiclJmclJmclJmclJmclJmcAAAAlJmdlZmdlJiclJmcCxAmtwAAABF0Uk5TmhBwEJkP9O7075n1ynEGywDZOPyuAAAAd0lEQVQY05WO4RKDIAyDcc6pQy2SvP+zruDJUXV3ml/la0jjQhYZKoFuH2rMHTNe4z9uXOJDNhzBlUXFjfTKC51w8+SjgrDuaN3LPH2G6XUI6UQLxVTJ1Z+/pb/BPUCc8ZiR7laD3xtWanArW7I0BmtB8V7mJfwAFT8ct1xKBKUAAAAASUVORK5CYII=);
height: 28px;
width: 28px;
border-radius: 50%;
border: 1px solid #c9cccd;
background-size: auto 10px;
background-position: center center;
background-repeat: no-repeat;
cursor: pointer;
}
.artist_tracks_to_playlist:hover {
border-color: #94999c;
}
94 changes: 89 additions & 5 deletions rdio-enhancer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ function injectedJs() {
return parent_get_attributes;
}
}
if(a == "Dialog.EditPlaylistDialog") {
}
if(a == "TrackList") {

}

if(a == "ActionMenu") {
b.orig_getMenuOptions = b.getMenuOptions;
Expand Down Expand Up @@ -746,6 +741,95 @@ function injectedJs() {
}
}

// Create playlists based on an artist's top tracks
if(a == "Catalog.Artist.Songs") {
b.orig_events = b.events || null;
b.events = function() {
var local_events = b.orig_events ? b.orig_events.call(this) : {};
local_events["click .artist_tracks_to_playlist"] = "onArtistTracksToPlaylistClicked";
return local_events;
};

b.onArtistTracksToPlaylistClicked = function(event) {
this.artistTracksToPlaylistMenu.open();
R.Utils.stopEvent(event);
};

b.onArtistTracksToPlaylistOptionSelected = function(menuItem) {
var count = menuItem.get('value'),
artistKey = this.model.get('key'),
maxArtistTracks = this.model.get('length'),
playlistName = this.model.get('name') + ' Top Tracks',
tracksToAdd,
getTracks,
createPlaylist;
createPlaylist = (tracksToAdd) => {
return R.Api.request({
method: "createPlaylist",
content: { name: playlistName, description: playlistName, tracks: tracksToAdd },
success: function() {
R.enhancer.show_message('Playlist created.', true);
},
error: function() {
R.enhancer.show_message('There was an error creating an artist playlist.', true);
}
});
}
R.Api.request({
method: "getTracksForArtist",
content: { artist: artistKey, count: count, extras: ['-*', 'key'] },
success: (response) => {
if(response.status != 'ok') {
R.enhancer.show_message('There was an error getting tracks for this artist.', true);
return;
}
tracksToAdd = _.pluck(response.result.items, 'key');
createPlaylist(tracksToAdd);
},
error: () => {
R.enhancer.show_message('There was an error getting tracks for this artist.', true);
}
});
};

b.getMenuOptions = (maxTracks) => {
var sizeChoices = _.filter([10, 100, 250, 500, 1000], (num) => { return num <= maxTracks }),
menuOptions = new Backbone.Collection([]),
cur,
createMenuItem;
createMenuItem = (val) => {
return {
label: 'Add Top ' + val,
value: val,
callback: b.onArtistTracksToPlaylistOptionSelected,
extraClassNames: 'playlist'
};
};
while (sizeChoices.length) {
cur = sizeChoices.shift();
menuOptions.push(createMenuItem(cur));
}
menuOptions.push(createMenuItem(maxTracks));
return menuOptions;
};

b.orig_onRendered = b.onRendered || R.doNothing;
b.onRendered = function() {
b.orig_onRendered.call(this);
this.$(".SortControls").append('<div class="artist_tracks_to_playlist"></div>');
var $artistTracksToPlaylistMenuEl = this.$(".artist_tracks_to_playlist"),
artistMaxTracks = this.model.get('length'),
menuOptionsModel = b.getMenuOptions(artistMaxTracks);

this.artistTracksToPlaylistMenu = this.addChild(new R.Components.Menu({
positionOverEl: $artistTracksToPlaylistMenuEl,
positionUnder: false,
model: menuOptionsModel,
defaultContext: this
}));
};
}

return R.Component.orig_create.call(this, a,b,c);
};
},
Expand Down