2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								! Copyright (C) 2009 Tim Wawrzynczak, Doug Coleman.
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								! See http://factorcode.org/license.txt for BSD license.
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 18:54:44 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								USING: sequences io io.encodings.binary io.files io.pathnames
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								strings kernel math io.mmap io.mmap.uchar accessors syntax
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								combinators math.ranges unicode.categories byte-arrays
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 23:33:43 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								io.encodings.string io.encodings.utf16 assocs math.parser
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								combinators.short-circuit fry namespaces combinators.smart
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-02 20:41:58 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								splitting io.encodings.ascii arrays io.files.info unicode.case
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								io.directories.search ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								IN: id3
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-18 22:32:31 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								<PRIVATE
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								CONSTANT: genres
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        "Blues" "Classic Rock" "Country" "Dance" "Disco" "Funk" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Grunge" "Hip-Hop" "Jazz" "Metal" "New Age" "Oldies" "Other" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Pop" "R&B" "Rap" "Reggae" "Rock" "Techno" "Industrial" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Alternative" "Ska" "Death Metal" "Pranks" "Soundtrack" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Euro-Techno" "Ambient" "Trip-Hop" "Vocal" "Jazz+Funk" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Fusion" "Trance" "Classical" "Instrumental" "Acid" "House" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Game" "Sound Clip" "Gospel" "Noise" "AlternRock" "Bass" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Soul" "Punk" "Space" "Meditative" "Instrumental Pop" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Instrumental Rock" "Ethnic" "Gothic" "Darkwave" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Techno-Industrial" "Electronic" "Pop-Folk" "Eurodance" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Dream" "Southern Rock" "Comedy" "Cult" "Gangsta" "Top 40" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Christian Rap" "Pop/Funk" "Jungle" "Native American" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Cabaret" "New Wave" "Psychedelic" "Rave" "Showtunes" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Trailer" "Lo-Fi" "Tribal" "Acid Punk" "Acid Jazz" "Polka" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Retro" "Musical" "Rock & Roll" "Hard Rock" "Folk" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Folk-Rock" "National Folk" "Swing" "Fast Fusion" "Bebop" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Latin" "Revival" "Celtic" "Bluegrass" "Avantgarde" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Gothic Rock" "Progressive Rock" "Psychedelic Rock" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Symphonic Rock" "Slow Rock" "Big Band" "Chorus" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Easy Listening" "Acoustic" "Humour" "Speech" "Chanson" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Opera" "Chamber Music" "Sonata" "Symphony" "Booty Bass" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Primus" "Porn Groove" "Satire" "Slow Jam" "Club" "Tango" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Samba" "Folklore" "Ballad" "Power Ballad" "Rhythmic Soul" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Freestyle" "Duet" "Punk Rock" "Drum Solo" "A capella" 
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        "Euro-House" "Dance Hall"
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    }
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								TUPLE: header version flags size ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								TUPLE: frame frame-id flags size data ;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-18 22:32:31 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: id3v2-info header frames ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:27:39 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								TUPLE: id3v1-info title artist album year comment genre ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: <id3v1-info> ( -- object ) id3v1-info new ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: <id3v2-info> ( header frames -- object )
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ [ frame-id>> ] keep ] H{ } map>assoc id3v2-info boa ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: <header> ( -- object ) header new ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: <frame> ( -- object ) frame new ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: id3v2? ( mmap -- ? ) "ID3" head? ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: id3v1? ( mmap -- ? )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    { [ length 128 >= ] [ 128 tail-slice* "TAG" head? ] } 1&& ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: id3v1-frame ( string key -- frame )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    <frame>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        swap >>frame-id
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        swap >>data ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: id3v1>id3v2 ( id3v1 -- id3v2 )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ title>> "TIT2" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ artist>> "TPE1" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ album>> "TALB" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ year>> "TYER" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ comment>> "COMM" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ genre>> "TCON" id3v1-frame ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } cleave
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    ] output>array f swap <id3v2-info> ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: >28bitword ( seq -- int )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    0 [ [ 7 shift ] dip bitor ] reduce ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: filter-text-data ( data -- filtered )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ printable? ] filter ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: valid-frame-id? ( id -- ? )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ { [ digit? ] [ LETTER? ] } 1|| ] all? ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: read-frame-data ( frame mmap -- frame data )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ 10 over size>> 10 + ] dip <slice> filter-text-data ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 23:33:43 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: decode-text ( string -- string' )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup 2 short head
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    { { HEX: ff HEX: fe } { HEX: fe HEX: ff } } member?
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    utf16 ascii ? decode ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: (read-frame) ( mmap -- frame )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ <frame> ] dip
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ 4 head-slice decode-text >>frame-id ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 4 8 ] dip subseq >28bitword >>size ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 8 10 ] dip subseq >byte-array >>flags ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 23:33:43 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ read-frame-data decode-text >>data ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } cleave ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: read-frame ( mmap -- frame/f )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    dup 4 head-slice valid-frame-id?
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ (read-frame) ] [ drop f ] if ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: remove-frame ( mmap frame -- mmap )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    size>> 10 + tail-slice ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: read-frames ( mmap -- frames )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ dup read-frame dup ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ [ remove-frame ] keep ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    produce 2nip ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: read-v2-header ( seq -- id3header )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ <header> ] dip
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ [ 3 5 ] dip <slice> >array >>version ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 5 ] dip nth >>flags ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 6 10 ] dip <slice> >28bitword >>size ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } cleave ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: read-v2-tag-data ( seq -- id3v2-info )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    10 cut-slice
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ read-v2-header ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ read-frames ] bi* <id3v2-info> ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-18 22:32:31 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: skip-to-v1-data ( seq -- seq ) 125 tail-slice* ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: (read-v1-tag-data) ( seq -- mp3-file )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:27:39 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    [ <id3v1-info> ] dip
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    {
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-27 01:23:04 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        [ 30 head-slice decode-text filter-text-data >>title ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 30 60 ] dip subseq decode-text filter-text-data >>artist ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 60 90 ] dip subseq decode-text filter-text-data >>album ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 90 94 ] dip subseq decode-text filter-text-data >>year ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 94 124 ] dip subseq decode-text filter-text-data >>comment ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        [ [ 124 ] dip nth number>string >>genre ]
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    } cleave ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: read-v1-tag-data ( seq -- mp3-file )
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    skip-to-v1-data (read-v1-tag-data) ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: parse-genre ( string -- n/f )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup "(" ?head-slice drop ")" ?tail-slice drop
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    string>number dup number? [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        genres ?nth swap or
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        drop
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] if ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: (mp3>id3) ( path -- id3v2-info/f )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            { [ dup id3v2? ] [ read-v2-tag-data ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            { [ dup id3v1? ] [ read-v1-tag-data id3v1>id3v2 ] }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            [ drop f ]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        } cond
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    ] with-mapped-uchar-file ;
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								PRIVATE>
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: mp3>id3 ( path -- id3v2-info/f )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    dup file-info size>> 0 <= [ drop f ] [ (mp3>id3) ] if ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: find-id3-frame ( id3 name -- obj/f )
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 19:10:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    swap frames>> at* [ data>> ] when ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-09 22:50:04 -05:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: title ( id3 -- title/f ) "TIT2" find-id3-frame ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: artist ( id3 -- artist/f ) "TPE1" find-id3-frame ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: album ( id3 -- album/f ) "TALB" find-id3-frame ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: year ( id3 -- year/f ) "TYER" find-id3-frame ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-26 22:39:53 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: comment ( id3 -- comment/f ) "COMM" find-id3-frame ; inline
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: genre ( id3 -- genre/f )
							 | 
						
					
						
							
								
									
										
										
										
											2009-04-06 19:10:49 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    "TCON" find-id3-frame parse-genre ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								: find-mp3s ( path -- seq )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ >lower ".mp3" tail? ] find-all-files ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-02 13:05:36 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: mp3-paths>id3s ( seq -- seq' )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    [ dup mp3>id3 ] { } map>assoc ; inline
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-02 20:41:58 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-03-28 17:35:08 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								: parse-mp3-directory ( path -- seq )
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    find-mp3s mp3-paths>id3s ;
							 |