try to detect the encoding for id3 headers. need to try this on some mp3s from the wild
parent
efe701af9b
commit
63c9b1a6b8
|
|
@ -3,9 +3,9 @@
|
||||||
USING: sequences io io.encodings.binary io.files io.pathnames
|
USING: sequences io io.encodings.binary io.files io.pathnames
|
||||||
strings kernel math io.mmap io.mmap.uchar accessors syntax
|
strings kernel math io.mmap io.mmap.uchar accessors syntax
|
||||||
combinators math.ranges unicode.categories byte-arrays
|
combinators math.ranges unicode.categories byte-arrays
|
||||||
io.encodings.string io.encodings.utf8 assocs math.parser
|
io.encodings.string io.encodings.utf16 assocs math.parser
|
||||||
combinators.short-circuit fry namespaces multiline
|
combinators.short-circuit fry namespaces multiline
|
||||||
combinators.smart splitting ;
|
combinators.smart splitting io.encodings.ascii ;
|
||||||
IN: id3
|
IN: id3
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
@ -205,13 +205,18 @@ TUPLE: id3-info title artist album year comment genre ;
|
||||||
|
|
||||||
! read whole frames
|
! read whole frames
|
||||||
|
|
||||||
|
: decode-text ( string -- string' )
|
||||||
|
dup 2 short head
|
||||||
|
{ { HEX: ff HEX: fe } { HEX: fe HEX: ff } } member?
|
||||||
|
utf16 ascii ? decode ; inline
|
||||||
|
|
||||||
: (read-frame) ( mmap -- frame )
|
: (read-frame) ( mmap -- frame )
|
||||||
[ <frame> ] dip
|
[ <frame> ] dip
|
||||||
{
|
{
|
||||||
[ read-frame-id utf8 decode >>frame-id ]
|
[ read-frame-id decode-text >>frame-id ]
|
||||||
[ read-frame-flags >byte-array >>flags ]
|
[ read-frame-flags >byte-array >>flags ]
|
||||||
[ read-frame-size >28bitword >>size ]
|
[ read-frame-size >28bitword >>size ]
|
||||||
[ read-frame-data utf8 decode >>data ]
|
[ read-frame-data decode-text >>data ]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
: read-frame ( mmap -- frame/f )
|
: read-frame ( mmap -- frame/f )
|
||||||
|
|
@ -270,11 +275,11 @@ TUPLE: id3-info title artist album year comment genre ;
|
||||||
: (read-v1-tag-data) ( seq -- mp3-file )
|
: (read-v1-tag-data) ( seq -- mp3-file )
|
||||||
[ <id3-info> ] dip
|
[ <id3-info> ] dip
|
||||||
{
|
{
|
||||||
[ read-title utf8 decode filter-text-data >>title ]
|
[ read-title decode-text filter-text-data >>title ]
|
||||||
[ read-artist utf8 decode filter-text-data >>artist ]
|
[ read-artist decode-text filter-text-data >>artist ]
|
||||||
[ read-album utf8 decode filter-text-data >>album ]
|
[ read-album decode-text filter-text-data >>album ]
|
||||||
[ read-year utf8 decode filter-text-data >>year ]
|
[ read-year decode-text filter-text-data >>year ]
|
||||||
[ read-comment utf8 decode filter-text-data >>comment ]
|
[ read-comment decode-text filter-text-data >>comment ]
|
||||||
[ read-genre number>string >>genre ]
|
[ read-genre number>string >>genre ]
|
||||||
} cleave ; inline
|
} cleave ; inline
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue