Skip to content
Open
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
31 changes: 27 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ <h4 class="modal-title">Extra Settings</h4>
<input type="text" class="form-control input-md" id="request-delay" placeholder="0" rv-value="request_delay">
<p class="help-block">(milliseconds, default 0) how long to wait between making requests</p>
</div>
<div class="form-group form-inline">
<input type="checkbox" class="form-control" name="lastfm-include-headers" id="lastfm-include-headers" checked="false">

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just a suggestion, feel free to ignore)

It may be possible to use Rivets rv-checked, to automatically bind this value.

Suggested change
<input type="checkbox" class="form-control" name="lastfm-include-headers" id="lastfm-include-headers" checked="false">
<input type="checkbox" class="form-control" name="lastfm-include-headers" rv-checked="include_headers">

Then in the code later you could access this value through the state:

var includeHeaders = state.include_headers;

……… However, I've no idea what version of Rivets this is using, and if there are any issues with the different options, so feel free to ignore this and I could take a look later.

<label for="lastfm-include-headers">Include column headers</label>
</div>
<div class="form-group form-inline">
<input type="checkbox" class="form-control" name="lastfm-include-mbid" id="lastfm-include-mbid" checked="false">
<label for="lastfm-include-mbid">Include MusicBrainz ID</label>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -176,18 +184,33 @@ <h4 class="modal-title">Extra Settings</h4>
}
})

var headers = ['artist', 'album', 'name', 'date'];
var includeMBID = $('#lastfm-include-mbid').prop('checked');
var includeHeaders = $('#lastfm-include-headers').prop('checked');

if(includeMBID) {
headers.push('mbid', 'artist_mbid', 'album_mbid');
}

async.eachSeries(requests, function(item, callback){
if(state.cancelled) return callback(false);

state.status = "fetching page " + (item.i) + "/" + page_count;
lastFM(item.data)
.then(extractTracks)
.then(function(tracks){
var r = tracks.map(function(d){
if(includeMBID) {
return row(headers, d)
}
return row(headers, d)
Comment on lines +203 to +206

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if statement doesn't seem necessary here now that headers is pulled out above.

Suggested change
if(includeMBID) {
return row(headers, d)
}
return row(headers, d)
return row(headers, d)

})
.map(csv).join('\n') + '\n';

var blb = new Blob([
tracks.map(function(d){
return row(['artist', 'album', 'name', 'date'], d)
})
.map(csv).join('\n') + '\n']);
includeHeaders ? (headers.join(',') + '\n' + r) : r

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 will this add the headers for every page of the output?

It might be easier to add the headers at the download handler instead:

var b = new Blob(data, {type: 'text/csv'})

⬆️ , could be something along the lines of ⬇️

const header = includeHeaders ? [headers.join(',') + '\n'] : [];
var b = new Blob(header.concat(data), {type: 'text/csv'})

(though maybe there's a neater way to do it…)

]);

data[item.i] = blb;
bytes+= blb.size;
state.kb = Math.round(bytes/1024);
Expand Down
8 changes: 8 additions & 0 deletions js/lastfm-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function extractTracks(doc){
for (var i = track.childNodes.length - 1; i >= 0; i--) {
child = track.childNodes[i];
obj[child.tagName] = child.textContent;

if (child.tagName) {
var mbid = child.getAttribute('mbid');

if (mbid) {
obj[`${child.tagName}_mbid`] = mbid;
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎 cool!

};
arr.push(obj)
}
Expand Down