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

Commit

Permalink
fix bug when exporting more than 30000 tracks
Browse files Browse the repository at this point in the history
Also add start input to begin download at a certain number
Fixes #66
Fixes #50
  • Loading branch information
matt-h committed Nov 17, 2015
1 parent 39485bd commit a8085e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 9 additions & 2 deletions rdio-enhancer.css
Expand Up @@ -116,13 +116,20 @@
margin: 2px 10px 0 0;
}

.section_header .exportToCSV {
.section_header .export_to_csv_box {
padding: 0 12px;
font-size: 12px;
color: #008fd5;
float:right;
margin-right:5px;
}
.section_header .export_start {
width: 50px;
margin: 0;
}
.section_header .exportToCSV {
font-size: 12px;
color: #008fd5;
}

.Dialog.unavailable_dialog .album {
margin: 0;
Expand Down
17 changes: 9 additions & 8 deletions rdio-enhancer.ts
Expand Up @@ -617,9 +617,10 @@ function injectedJs() {
b.onRendered = function() {
b.orig_onRendered.call(this);

this.$(".section_header").append('<button type="button" class="button exportToCSV with_text">Export to CSV</button>');
this.$(".section_header").append('<span class="export_to_csv_box">Start Export #: <input type="text" class="export_start" value="0"> <button type="button" class="button exportToCSV with_text">Export to CSV</button></span>');
this.$(".header").append('<span class="filter_container"><div class="TextInput filter"><input class="tags_filter unstyled" placeholder="Filter By Tag" name="" type="text" value=""></div></span>');
this.$(".exportToCSV").on("click", function(e) {
var start = parseInt( jQuery(".export_start").val() );
R.enhancer.getFavoriteTracks(function(tracks) {
var csv = [["Name", "Artist", "Album", "Track Number"].join(",")];
var keys = ["name", "artist", "album", "trackNum"];
Expand All @@ -636,7 +637,7 @@ function injectedJs() {
pom.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv.join("\n")));
pom.setAttribute('download', 'collection.csv');
pom.click();
});
}, start);
});
this.$(".tags_filter").on("keyup", _.bind(function() {
var value = this.$(".tags_filter").val().trim();
Expand Down Expand Up @@ -1094,12 +1095,12 @@ function injectedJs() {
);
},

getFavoriteTracks: function(callback) {
getFavoriteTracks: function(callback, start) {
R.enhancer.show_message('Fetching Favorites data... Please wait. If your Favorites is large this can take awhile.', true);
R.enhancer._getFavoriteTracks(callback, [], 0, 0);
R.enhancer._getFavoriteTracks(callback, [], 0, start, start);
},

_getFavoriteTracks: function(callback, tracks, offset, start) {
_getFavoriteTracks: function(callback, tracks, offset, start, origstart) {
R.Api.request({
method: "getTracksInCollection",
content: {
Expand All @@ -1108,16 +1109,16 @@ function injectedJs() {
},
success: function(success_data) {
tracks = tracks.concat(success_data.result.items);
if(success_data.result.total > tracks.length) {
if(success_data.result.total > tracks.length + origstart) {
if ( tracks.length >= 15000 ) {
callback(tracks);
var newstart = start + tracks.length;
tracks = []; // Clear out tracks to preserve memory
R.enhancer.show_message('You have a large amount of tracks, multiple CSV files will be downloaded.', true);
R.enhancer._getFavoriteTracks(callback, [], 0, newstart);
R.enhancer._getFavoriteTracks(callback, [], 0, newstart, newstart);
}
else {
R.enhancer._getFavoriteTracks(callback, tracks, tracks.length, start);
R.enhancer._getFavoriteTracks(callback, tracks, tracks.length, start, origstart);
}
}
else {
Expand Down

0 comments on commit a8085e0

Please sign in to comment.