]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/id3/id3.factor
pcre2: fix un-named capture groups
[factor.git] / extra / id3 / id3.factor
index 6a14280e6e8b7915864562d409af1d757d06a010..6de42598670549d0cd7e96eec812181bc7cefbbb 100644 (file)
@@ -1,12 +1,10 @@
 ! Copyright (C) 2009 Tim Wawrzynczak, Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: sequences io io.encodings.binary io.files io.pathnames
-strings kernel math io.mmap accessors combinators math.ranges
-unicode.categories byte-arrays io.encodings.string
-io.encodings.utf16 assocs math.parser combinators.short-circuit
-fry namespaces combinators.smart splitting io.encodings.ascii
-arrays io.files.info unicode.case io.directories.search literals
-math.functions continuations ;
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors arrays assocs byte-arrays
+combinators combinators.short-circuit combinators.smart
+continuations io.directories io.encodings.ascii
+io.encodings.string io.encodings.utf16 io.mmap kernel math
+math.functions math.parser sequences splitting unicode ;
 FROM: alien.c-types => uchar ;
 IN: id3
 
@@ -14,30 +12,30 @@ IN: id3
 
 CONSTANT: genres
     {
-        "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" 
+        "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" "Goa" "Drum & Bass" "Club-House"
         "Hardcore" "Terror" "Indie" "BritPop" "Negerpunk"
         "Polsk Punk" "Beat" "Christian Gangsta Rap" "Heavy Metal"
@@ -101,12 +99,12 @@ CONSTANT: id3v1+-length 227
         } cleave
     ] output>array sift ;
 
-: seq>synchsafe ( seq -- n )
+: sequence>synchsafe ( seq -- n )
     0 [ [ 7 shift ] dip bitor ] reduce ;
 
-: synchsafe>seq ( n -- seq )
+: synchsafe>sequence ( n -- seq )
     dup 1 + log2 1 + 7 / ceiling
-    [ [ -7 shift ] keep HEX: 7f bitand  ] replicate nip reverse ;
+    [ [ -7 shift ] keep 0x7f bitand  ] replicate nip reverse ;
 
 : filter-text-data ( data -- filtered )
     [ printable? ] filter ;
@@ -118,15 +116,15 @@ CONSTANT: id3v1+-length 227
     [ 10 over size>> 10 + ] dip <slice> filter-text-data ;
 
 : decode-text ( string -- string' )
-    dup 2 short head
-    { { HEX: ff HEX: fe } { HEX: fe HEX: ff } } member?
+    dup 2 index-or-length head
+    { { 0xff 0xfe } { 0xfe 0xff } } member?
     utf16 ascii ? decode ;
 
 : (read-frame) ( seq -- frame )
     [ <frame> ] dip
     {
         [ 4 head-slice decode-text >>tag ]
-        [ [ 4 8 ] dip subseq seq>synchsafe >>size ]
+        [ [ 4 8 ] dip subseq sequence>synchsafe >>size ]
         [ [ 8 10 ] dip subseq >byte-array >>flags ]
         [ read-frame-data decode-text >>data ]
     } cleave ;
@@ -143,17 +141,17 @@ CONSTANT: id3v1+-length 227
 
 : read-frames ( seq -- assoc )
     [ dup read-frame dup ] [ [ remove-frame ] keep ] produce 2nip ;
-    
+
 : read-v2-header ( seq -- header )
     [ <header> ] dip
     {
         [ [ 3 5 ] dip <slice> >array >>version ]
         [ [ 5 ] dip nth >>flags ]
-        [ [ 6 10 ] dip <slice> seq>synchsafe >>size ]
+        [ [ 6 10 ] dip <slice> sequence>synchsafe >>size ]
     } cleave ;
 
 : merge-frames ( id3 assoc -- id3 )
-    [ dup frames>> ] dip update ;
+    [ dup frames>> ] dip assoc-union! drop ;
 
 : merge-id3v1 ( id3 -- id3 )
     dup id3v1>frames frames>assoc merge-frames ;
@@ -162,7 +160,7 @@ CONSTANT: id3v1+-length 227
     10 cut-slice
     [ read-v2-header >>header ]
     [ read-frames frames>assoc merge-frames ] bi* ;
-    
+
 : extract-v1-tags ( id3 seq -- id3 )
     {
         [ 30 head-slice decode-text filter-text-data >>title ]
@@ -233,7 +231,7 @@ PRIVATE>
 : genre ( id3 -- string/f )
     "TCON" find-id3-frame parse-genre ;
 
-: find-mp3s ( path -- seq ) ".mp3" find-by-extension ;
+: find-mp3s ( path -- seq ) ".mp3" find-files-by-extension ;
 
 ERROR: id3-parse-error path error ;