aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
752 stars 128 forks source link

tags'title is gibberish character #134

Closed jonahzheng closed 4 years ago

jonahzheng commented 4 years ago

source code

`var jsmediatags = require("jsmediatags");

new jsmediatags.Reader("https://api.zanmeishi.com/song/p/27090.mp3") //.setTagsToRead(["title", "artist"]) .read({ onSuccess: function (tag) { console.log(JSON.stringify(tag)); }, onError: function (error) { console.log(':(', error.type, error.info); } });`

result: {"type":"ID3","version":"2.3.0","major":3,"revision":0,"flags":{"unsynchronisation":false,"extended_header":false,"experimental_indicator":false,"footer_present":false},"size":81,"tags":{"title":"¹ú¶ÈÒѽµÁÙ","artist":"çÑÃ÷ƽ","album":"ÐÅÍû°®","genre":"Other","TPE1":{"id":"TPE1","size":7,"description":"Lead performer(s)/Soloist(s)","data":"çÑÃ÷ƽ"},"TALB":{"id":"TALB","size":7,"description":"Album/Movie/Show title","data":"ÐÅÍû°®"},"TCON":{"id":"TCON","size":6,"description":"Content type","data":"Other"},"TIT2":{"id":"TIT2","size":11,"description":"Title/songname/content description","data":"¹ú¶ÈÒѽµÁÙ"}}}

thank you!

zxkfall commented 4 years ago

I have this problem ,too.Did you solve this problem?

zxkfall commented 4 years ago

It seems I have found a ssolution. You can use Mp3tag software to change the track number to 1. Probably because the track number is not specified,the encoding is GBK,which leads to garbled characters.

jonahzheng commented 4 years ago

@Fallofleaf thank you, but the MP3 file is on the server and I can't modify it.

I tried iconv-Lite to decode the output, but it also turned out to be a gibberish.

Borewit commented 4 years ago

The issue is indeed with the track, probably caused by a wrong encoding specification.

In other words, the title of the track is set to: ¹ú¶ÈÒѽµÁÙ, which looks like Mojibake.

const fetch = require('node-fetch');
const musicMetadata = require('music-metadata');

const url = 'https://api.zanmeishi.com/song/p/27090.mp3';

(async () => {
  const response = await fetch(url);
  const metadata = await musicMetadata.parseStream(response.body);
  console.log(metadata.common);
})();
{
  track: { no: null, of: null },
  disk: { no: null, of: null },
  artists: [ 'çÑÃ÷ƽ' ],
  artist: 'çÑÃ÷ƽ',
  album: 'ÐÅÍû°®',
  genre: [ 'Other' ],
  title: '¹ú¶ÈÒѽµÁÙ'
}
jonahzheng commented 4 years ago

@Borewit thank you, similar url, https://api.zanmeishi.com/song/p/22228.mp3, https://api.zanmeishi.com/song/p/39515.mp3, I'm not sure, what code does it use. I tried iconv-Lite to decode the json output,but it is mojibake.

Borewit commented 4 years ago

Regarding the first track, I think the original character encoding is GB2312:

const fetch = require('node-fetch');
const musicMetadata = require('music-metadata');
const iconv = require('iconv-lite');

const url = 'https://api.zanmeishi.com/song/p/27090.mp3';
(async () => {
  const response = await fetch(url);
  const metadata = await musicMetadata.parseStream(response.body);

  ['artist', 'title', 'album'].forEach(tag => {
    const mojibake = metadata.common[tag];
    console.log(`${tag}: ${iconv.decode(mojibake,'GB2312')}`);
  });
})();
artist: 缪明平
title: 国度已降临
album: 信望爱
Borewit commented 4 years ago

Or using jsmediatags, same story:

const jsmediatags = require('jsmediatags');
const iconv = require('iconv-lite');

function readMetadata(url) {
  return new Promise((resolve, reject) => {
    jsmediatags.read(url, {
      onSuccess: result => resolve(result),
      onError: error => reject(error)})
  });
}

const url = 'https://api.zanmeishi.com/song/p/27090.mp3';
(async () => {
  const metadata = await readMetadata(url);

  ['artist', 'title', 'album'].forEach(tag => {
    const mojibake = metadata.tags[tag];
    console.log(`${tag}: ${iconv.decode(mojibake,'GB2312')}`);
  });
})();
artist: 缪明平
title: 国度已降临
album: 信望爱
jonahzheng commented 4 years ago

@Borewit thank you very mush, you'er so cool.