Cuesheet Maker Bookmarklet for Discogs.com

Yesterday I discovered I had a few albums that had been ripped as a single track. I prefer having individual tracks and usually head on over to cuesheet heaven to look for the appropriate file that allows me to split them up with the awesome Medieval Cue Splitter. However I had a few tracks that had I could not find the appropriate cuesheet file for. I find myself in this situation fairly regularly and have also noticed that these albums usually have an entry at discogs.com, which has all the details including track lengths.

This got me thinking that it would be awesome to be able to create cue files from discogs.com. So I created the following – a bookmarklet to do just that.

Disclaimer: it is pretty rough and I cannot guarantee that it will work with all discogs.com entries and there is hardly any error checking. I have only used this in Firefox so I cannot guarantee it will work in any other browser. It only pops up a dialogue with the cuesheet contents on it but that was adequate for me to copy and paste it into a text file and tweak it so that it was a valid cuesheet.

The important thing is that it gathers the track names and artists and works out the index times. It also attempts to cope with double cds and also single tracks that are two different records playing at once (common with DJ mixes). Here is the bookmarklet (drag it into your bookmarks tookbar), followed by the code itself:

Drag this to your bookmark toolbar: Create Cue

The code itself:

javascript:(function(){var s=document.createElement('SCRIPT');
s.type='text/javascript';
s.src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js';
s.onload=function() {
	var title = jQuery.trim(jQuery('div.profile h1').text()),
		performer = jQuery.trim(title.substring(0,title.indexOf('-'))),
		file = title + '.mp3', secCount = 0, trkCount = 0, cues = [], cdNo = 1;
	title = jQuery.trim(title.substring(title.indexOf('-')+1));
	tracks = [];
	jQuery('div.tracklist .section_content > table tr').each(function(ix, el) {
		var trackCd = jQuery.trim(jQuery('td.track_pos',this).text());
		if (trackCd && trackCd != '') {
			var track = {}, tracktime = [], isDouble = false;
			trackCd = trackCd.split('-');
			if (trackCd.length > 1) {
				if (jQuery.trim(trackCd[0]) != cdNo) {
					createCue();
					cdNo = trackCd[0];
				} else {
					if (parseInt(trackCd[1]) == trkCount) {
						isDouble = true;
					}
				}
			}
			if (!isDouble) {
				trkCount+=1;
				track['trackno'] = trkCount;
				track['artist']= jQuery.trim(jQuery('td.track_artists',this).text()).replace(/\s-$/g, '').replace(/\n/g, '').replace(/\s+/g,' ');
				track['artist'] = jQuery.trim(track['artist']);
				track['artist'] = (track['artist'] == '') ? performer : track['artist'];
				track['title'] = jQuery.trim(jQuery('td.track',this).text()); 
				tracktime =jQuery.trim(jQuery('td.track_duration',this).text()).split(':'); 
				track['index'] = secondsToMinSec(secCount);
				secCount += (tracktime[0] * 60) + (tracktime[1] * 1);
				tracks[tracks.length] = track;	
			}
		}
 
	});
 
	createCue();
 
	//print it out
	var output = '';
	jQuery.each(cues,function(ix, cue) {
		output += cue + '\n\n\n';
	});
 
	alert(output);
 
	function createCue() {
		var quo = unescape('%22'),
			cue = 'TITLE '+quo+title+quo+'\n';
		cue += 'PERFORMER '+quo+performer+quo+'\n';
		cue += 'FILE '+quo+file+quo+' MP3\n';
		jQuery.each(tracks,function(ix, track) {
			cue += '  TRACK '+track.trackno+' AUDIO\n';
			cue += '    TITLE '+quo+track.title+quo+'\n';
			cue += '    PERFORMER '+quo+track.artist+quo+'\n';
			cue += '    INDEX 01 '+quo+track.index+quo+'\n';
		});
		cues[cues.length] = cue;
		//reset
		secCount = 0; trkCount = 0; tracks = [];
	}
 
	function secondsToMinSec(totsec) {
		var min = Math.floor(totsec / 60), 
			sec = (totsec - (min * 60));
		if (min < 10) {
			min = '0' + min.toString();
		}
		if (sec < 10) {
			sec = '0' + sec.toString();
		}
		return min.toString() + ':' + sec.toString() + ':00';
	}
};
document.getElementsByTagName('head')[0].appendChild(s);})();

I hope this helps some people, as it has me. Feel free to improve on it but if you make any changes, please let me know so that I can improve my version too.

Enjoy

Edit: Well it was not long until discogs changed their layout. I have update the code to reflect this. All should be well again.

Edit2: Bjørn Tore pointed out the titles were not being picked up. I have fixed this.

 

12 thoughts on “Cuesheet Maker Bookmarklet for Discogs.com

  1. Hi

    This seems to be a good idea. But I am not sure how to use it. I have added the tool to my Bookmarks (Firefox). But when I start it the I only get an empty Screen with the following comments:

    TITLE “”
    PERFORMER “”
    FILE “.mp3” MP3

    Can someone explain a bit more in detail how to use this?

  2. Thanks for the script.

    But one suggestion. Can you remove the quotes around the Track index field since foobar2000 cannot parse the Cue sheet with the qotes…

    cue += ‘ INDEX 01 ‘+quo+track.index+quo+’\n’;

    would be changed to:

    cue += ‘ INDEX 01 ‘+track.index+’\n’;

  3. Sry Dan, I was to fast with my judgement.
    It does create a proper cue sheet for the second disc too.
    My bad.

    Great pieve of code!!

    Thanks again!

  4. Thank you Dan for this Bookmarklet.

    It works pretty well. One need to adjust the cue sheet a little bit after copy and paste but that is not that much work.

    The only thing that you could improve is building cue files for multiple CD releases.

    Like Phool said it only generates a proper cue for the first disc.

  5. Thanks Bjorn, its a bit of a moving target as they keep changing their markup. I shall have a look when I get a chance and see if I can fix the issue.

  6. Almost perfect!

    Can not copy in Google Chrome, but in Firefox.

    Does not pick the title of the song though – any chance you can help fix this?

    Example:
    TITLE “Dark Side Of The Moon”
    PERFORMER “Pink Floyd”
    FILE “Pink Floyd – Dark Side Of The Moon.mp3” MP3
    TRACK 1 AUDIO
    TITLE “”
    PERFORMER “Pink Floyd”
    INDEX 01 “00:00:00”
    TRACK 2 AUDIO
    TITLE “”
    PERFORMER “Pink Floyd”
    INDEX 01 “01:13:00”

    Bjørn Tore

  7. This thing is freaking magical, awesome work! It had a little difficult parsing a multiple disc release though, it would only generate a cue for the first disc.

Leave a Reply

Your email address will not be published. Required fields are marked *