TooTallNate / node-icy

Node.js module for parsing and/or injecting ICY metadata
MIT License
291 stars 48 forks source link

Parsing buffer is wrong for IHeartRadio #32

Closed FireController1847 closed 6 years ago

FireController1847 commented 7 years ago

Issue *Note: I am using an IHeartRadio stream. When parsing a buffer, if there is another quote in the text, it is not shown. But, instead, when doing buffer.toString(), it returns everything. Not sure if this has to do with Icy in general or IHeartRadio but it seems to be an issue.

Example Not Working:

stream.on('metadata', function(md) {
  br.metadata = icy.parse(md);
}
// br.metadata = {"StreamTitle": "Taio Cruz - text"}

Working:

stream.on('metadata', function(md) {
  br.metadata = md.toString();
}
// br.metadata = "StreamTitle='Taio Cruz - text="Dynamite" song_spot="M" MediaBaseId="1734278" itunesTrackId="0" amgTrackId="-1" amgArtistId="0" TAID="43011" TPID="7610716" cartcutId="0708213001"';"

The URL https://c3icy.prod.playlists.ihrhls.com/2385_icy

TooTallNate commented 6 years ago

Thanks for the report! Fixed in https://github.com/TooTallNate/node-icy/commit/1c7278102d66b2cb52bc6dc0b3f2101c4cfdfee6.

FireController1847 commented 6 years ago

Yay! No problem :)

FireController1847 commented 6 years ago

Hey, so it still seems to be parsing invalid (I'm using the latest github commit), as it marks "StreamTitle" but does not include the rest of the information within the object but the title.

{ 
  StreamTitle: 'Khalid - text="Location" song_spot="M" MediaBaseId="2218753" itunesTrackId="0" amgTrackId="-1" amgArtistId="0" TAID="836574" TPID="45592457" cartcutId="0400112001"' 
}

This is the fix that I've been using.

const ta = md.toString().split('"');
let taid = md.toString().split('TPID=');
taid = (taid[1] ? taid[1].split('"') : null);
if (taid) {
  taid.shift();
  taid = taid[0];
}
let cimg = this.options[key].url.split('/');
cimg = cimg[cimg.length - 1];
if (cimg) {
  cimg = cimg.replace(/_icy/g, '');
}
if (md.toString().includes('adw_ad=\'true\'') || taid < 0) {
  ta[1] = 'Advertisement';
  ta[0] = 'Advertisement';
  taid = null;
}
if (taid == 0) {
  taid = null;
}
item.metadata = {
  'title': ta[1],
  'author': ta[0].replace('StreamTitle=\'', '').replace(' - text=', ''),
  'avatar': (taid ? 'https://iscale.iheart.com/v3/catalog/track/' + taid + '?ops=fit(250%2C%20250)' : null),
  'station': this.options[key].name,
  'icon': (cimg ? 'https://iscale.iheart.com/catalog/live/' + cimg + '?ops=fit(75%2C75)' : null),
  'debug': md.toString()
};
TooTallNate commented 6 years ago

Hey there. I get what you're saying, but I think this format is a bit too specific to iheart radio, as I have not seen it in other shoutcast style streams before.

Parsing the StreamTitle string afterwards is up to you in this case.

FireController1847 commented 6 years ago

Damn, okay. I'll just stick with my current setup then :)