Reading mp3 Tag


#1

Hi,
I am taking a free course on Ruby and encountered a behavior i don`t
understand…

this code produces jibberish on standard output

f1 = File.open(“song.mp3”,‘r’)
tag = f1.read[-128…-1]

puts tag.dump

produces
“]o\254\fM\301s\245\256\264\365\211r\201\251U\334’\016\325\340\274q\341\311\222\312\025M\222\210\234v0V\002M^\324\226W\023mQ\311\037\242\305(XT\353\236w\372\023c\275\254\241\267\277\374\306cd\036\356\204\026}?Z\016\003\275\016L\311j\217{h\242\016\253+\326vQ\305J\235\351\372)L\222HI%$\333/Q\303\274\220\247Td\000)\342\026\024\035\364\220\027\253\021\312E\341;”

This code however produces proper output.
Can someone explain why the first code doesn`t work for the TAG and the
seccond does???

f1 = File.open(“song.mp3”,‘r’)
id3 = f1.read[0…300]
tag = f1.read[-128…-1]

puts id3.dump
puts ‘-------------------’
puts tag.dump

produces
“ID3\003\000\000\000\000#vCOMM\000\000\000#\000\000\000eng\000#100%-Free-MP3s(Dalnet)
Annie
TRCK\000\000\000\003\000\000\00013TYER\000\000\000\005\000\000\0002000PRIV\000\000\000’\000\000WM/MediaClassPrimaryID\000\274}`\321#\343\342K\206\241H\244*(D\036PRIV\000\000\000)\000\000WM/MediaClassSecondaryID\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000PRIV\000\000\000\037\000\000WM/WMContentID\000FX;n\231\201HD\206kL\234>\306Z\350TPUB\000\000\000\023\000\000\000Music
For
PleasureTCON\000\000\000\005\000\000\000(24)TALB\000\000\000\027\000\000\000(SUMMER
HOLIDAY 1963)”

“TAGDancing
Shoes\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000Cliff
Richard and The Shadows\000(SUMMER HOLIDAY
1963)\000\000\000\000\000\000\000\0002000#100%-Free-MP3s(Dalnet)
Anni\000\r\030”

Catsquotl


#2

Hi,

2009/5/10 Catsquotl removed_email_address@domain.invalid:


HOLIDAY 1963)"

“TAGDancing
Shoes\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000Cliff
Richard and The Shadows\000(SUMMER HOLIDAY
1963)\000\000\000\000\000\000\000\0002000#100%-Free-MP3s(Dalnet)
Anni\000\r\030”

I guess you are using Ruby on Windows and the song.mp3 contains
“0x1a”(end of file marker).
Try File.open(“song.mp3”,‘rb’) instead of File.open(“song.mp3”,‘r’)

Regards,
Park H.


#3

Heesob P. schreef:

I guess you are using Ruby on Windows and the song.mp3 contains
“0x1a”(end of file marker).
Try File.open(“song.mp3”,‘rb’) instead of File.open(“song.mp3”,‘r’)

Regards,
Park H.

That worked thanks.
I did see the b flag in the IO documentation. Just didn`t find the right
way to use it…
I still am puzzeled though why in my first example the Tagline did get
read if i first read the first 100 characters…

Eelco