Skip to content

Commit

Permalink
Merge pull request #2 from randing89/master
Browse files Browse the repository at this point in the history
Add ability to read/update lyrics
  • Loading branch information
saschagehlich committed May 9, 2014
2 parents c55887e + c1ccc09 commit 74941f7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 9 deletions.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -20,16 +20,21 @@ Make sure you have `eyeD3` installed.
// Meta contains a hash with the following properties:
// artist, title, album, comment
})

eyed3.readLyrics('file.mp3', function (err, lyrics) {
// lyrics will be returned as a string
})

var meta = {
artist: "MyArtist",
title: "MyTitle",
album: "MyAlbum",
comment: "MyComment"
comment: "MyComment",
lyrics: "MyLyrics"
}
eyed3.updateMeta('file.mp3', meta, function (err) {
// file.mp3 now has updated meta data
})
})
```

## Running tests
Expand Down
34 changes: 32 additions & 2 deletions index.js
Expand Up @@ -17,7 +17,7 @@ EyeD3.prototype.readMeta = function(file, callback) {
var args = ['--no-color', '--rfc822', file]
, p = spawn(this.options.eyed3_path, args)
, allData = ''

p.stdout.on('data', function (data) {
allData += data
})
Expand All @@ -41,6 +41,35 @@ EyeD3.prototype.readMeta = function(file, callback) {
})
}

/**
* Reads the lyrics of the given file
*
* @param {String} file
* @param {Function} callback
*/
EyeD3.prototype.readLyrics = function(file, callback) {
var args = ['--no-color', '--verbose', file]
, p = spawn(this.options.eyed3_path, args)
, allData = ''

p.stdout.on('data', function (data) {
allData += data
})

p.on('exit', function (exitCode) {
if(exitCode !== 0)
return callback(new Error('eyeD3 exit code: ' + exitCode))

var response = '';

if(match = allData.match(/<.*lyric\/text.*:\s(.*)\s\[Lang:[^\]]*\]\s*\[Desc:[^\]]*\]>/im)) {
response = match[1]
}

callback(null, response)
})
}

/**
* Updates the meta data of the given file
*
Expand Down Expand Up @@ -73,7 +102,8 @@ EyeD3.prototype.buildArgs = function(meta) {
if(meta.title) args.push('-t', meta.title)
if(meta.album) args.push('-A', meta.album)
if(meta.comment) args.push('-c', '::' + meta.comment)

if(meta.lyrics) args.push('-L', '::' + meta.lyrics)

return args
}

Expand Down
Binary file modified test/assets/test.mp3
Binary file not shown.
Binary file modified test/assets/tmptest.mp3
Binary file not shown.
31 changes: 26 additions & 5 deletions test/eyed3.test.js
Expand Up @@ -8,7 +8,8 @@ var EyeD3 = require('../index.js')
artist: 'TestArtist',
title: 'TestTitle',
album: 'TestAlbum',
comment: 'TestComment'
comment: 'TestComment',
lyrics: 'TestLyrics'
}

describe('EyeD3', function () {
Expand All @@ -19,7 +20,8 @@ describe('EyeD3', function () {
'-a', 'TestArtist',
'-t', 'TestTitle',
'-A', 'TestAlbum',
'-c', '::TestComment'
'-c', '::TestComment',
'-L', '::TestLyrics'
]))
done()
})
Expand All @@ -33,6 +35,18 @@ describe('EyeD3', function () {
meta.album.should.equal(testMeta.album)
meta.comment.should.equal(testMeta.comment)


done()
})
})

it('should correctly read the lyrics from an .mp3 file', function (done) {
eyed3.readLyrics(testFile, function (err, lyrics) {
if (err) throw err

lyrics.should.equal(testMeta.lyrics)


done()
})
})
Expand All @@ -44,7 +58,8 @@ describe('EyeD3', function () {
title: testMeta.title + "New",
artist: testMeta.artist + "New",
album: testMeta.album + "New",
comment: testMeta.comment + "New"
comment: testMeta.comment + "New",
lyrics: testMeta.lyrics + "New"
}

eyed3.updateMeta(tmpTestFile, newMeta, function (err) {
Expand All @@ -57,8 +72,14 @@ describe('EyeD3', function () {
meta.title.should.equal(newMeta.title)
meta.album.should.equal(newMeta.album)
meta.comment.should.equal(newMeta.comment)

done()

eyed3.readLyrics(tmpTestFile, function (err, lyrics) {
if (err) throw err

lyrics.should.equal(newMeta.lyrics)

done()
})
})
})
})
Expand Down

0 comments on commit 74941f7

Please sign in to comment.