0

我有音频文件元数据详细信息,例如打击 json 字符串。在这里我需要过滤基于专辑和艺术家的歌曲。现在我正在使用 for 循环来过滤列表,但我有超过 2000 首独特的歌曲。我可以使用nodejs做任何其他方式来做到这一点吗?

[{
 "title":"Kallu Kollam - TamilWire.com",
 "picture":"Kallu Kollam - TamilWire.com",
 "artist":["N.D.Rajkumar"],
 "album":"Madhubaanakadai",
 "year":"2012",
 "path":"/media/data/songs/MadhuBana Kadai/Kallu Kollam - TamilWire.com.mp3"
 },
 {"title":"Manjal Nira Bodhai - TamilWire.com",
  "picture":"Manjal Nira Bodhai - TamilWire.com",
  "artist":["N.D.Rajkumar"],
  "album":"Madhubaanakadai",
  "year":"2012",
  "path":"/media/data/songs/MadhuBana Kadai/Manjal Nira Bodhai - TamilWire.com.mp3"}, 
 .....]
4

1 回答 1

2

使用下划线库按专辑分组数据:

 var _ = require('underscore');

 var songs = [{
 "title":"Kallu Kollam - TamilWire.com",
 "picture":"Kallu Kollam - TamilWire.com",
 "artist":["N.D.Rajkumar"],
 "album":"Madhubaanakadai",
 "year":"2012",
 "path":"/media/data/songs/MadhuBana Kadai/Kallu Kollam - TamilWire.com.mp3"
 },
 {"title":"Manjal Nira Bodhai - TamilWire.com",
  "picture":"Manjal Nira Bodhai - TamilWire.com",
  "artist":["N.D.Rajkumar"],
  "album":"Madhubaanakadai",
  "year":"2012",
  "path":"/media/data/songs/MadhuBana Kadai/Manjal Nira Bodhai - TamilWire.com.mp3"} 
 ];

 var grouped = _.groupBy(songs, function(song) {return song.album;});

分组的地方是:

{
    "Madhubaanakadai": [{ 
            "title":"Kallu Kollam - TamilWire.com", 
            ... 
        }, {
            "title":"Manjal Nira Bodhai - TamilWire.com"
            ...
        }
    ]
}
于 2013-09-24T10:40:38.067 回答