Skip to content

Instantly share code, notes, and snippets.

@garlic0x1
Created July 27, 2023 10:44
Show Gist options
  • Save garlic0x1/1fe800e207b0dfee88c552d99c40e47b to your computer and use it in GitHub Desktop.
Save garlic0x1/1fe800e207b0dfee88c552d99c40e47b to your computer and use it in GitHub Desktop.
tag mp3s based on directory convention
(import (garlic base)
(garlic sys)
(garlic strings))
(define (tag-file dir file data)
(sh (string-append "id3v2 '" dir file "' -A " (car data) " -a " (cdr data))))
(define (escape-unix-filename-spaces name)
(string-replace " " "\\ " name))
(define (dir-album name)
(let* ([slash-split (string-split-all #\/ name)]
[short (last slash-split)]
[dot-split (string-split-all #\. short)]
[artist (car dot-split)]
[album (cadr dot-split)])
(cons artist album)))
(define (tag-dir dir)
(->> (sh-lines (string-append "ls -a " dir))
(stream-map (lambda (file) (tag-file dir file (dir-album dir))))
(stream->list)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment