Must... scrobble... branes
Let's say you have a bunch of Ogg Vorbis files that you've tagged with tp_tagger, and you want to extract the relevant information so you can somehow submit it to last.fm via Audioscrobbler 1.1. ogginfo has lousy output for machine parsing, but that's okay.
#!/bin/zsh setopt extendedglob zmodload -i zsh/datetime || exit 1 parse_ogginfo() { local output album artist mbid title len tstamp output=(${(f)"$(ogginfo $1)"}) album=${${(M)output:#*ALBUM=*}#*ALBUM=} artist=${${(M)output:#*ARTIST=*}#*ARTIST=} mbid=${${(M)output:#*MUSICBRAINZ_TRACKID=*}#*MUSICBRAINZ_TRACKID=} title=${${(M)output:#*TITLE=*}#*TITLE=} len=${${(M)output:#*Playback length:*}#*Playback length: } if [[ "$len" == (#b)([0-9]##)m:([0-9.]##)s ]] then (( len = $match[1] * 60 + $match[2] + 1 )) else (( len = 0 )) fi typeset -i len tstamp=$(export TZ=UTC; strftime "%Y-%m-%d %H:%M:%S" ${EPOCHSECONDS}) print "${(qqq)artist} ${(qqq)title} ${(qqq)album} ${(qqq)mbid} ${(qqq)len} ${(qqq)tstamp}" } for i in "$@" do parse_ogginfo $i done
There's an off-by-one error if you should happen to have a track whose length is an exact number of seconds, and obviously the timestamps are useless if you don't run it on exactly one file at the correct time.
Sample output:
"Too Much Joy" "Making Fun of Bums" "Son of Sam I Am" "0077f5e2-ffe8-4f5c-83c5-d2a7bdc79776" "172" "2005-11-18 17:00:10" "Too Much Joy" "Song for a Girl Who Has One" "Son of Sam I Am" "af48111b-27e3-4c2b-8c42-927864b0e1f4" "209" "2005-11-18 17:00:10" "Too Much Joy" "Clowns" "Son of Sam I Am" "5cc2cf9c-2c68-48d4-be2c-ff0cbbae17e6" "219" "2005-11-18 17:00:10" "Too Much Joy" "My Past Lives" "Son of Sam I Am" "abd67bc7-1813-421b-9145-d072e58e62e5" "241" "2005-11-18 17:00:10" "Too Much Joy" "That's a Lie (remix)" "Son of Sam I Am" "dc22b8b2-7965-4c27-9cbc-9e529b2b1c87" "143" "2005-11-18 17:00:10" "Too Much Joy" "Hugo!" "Son of Sam I Am" "e0bba321-f654-4512-b052-66d605f96194" "144" "2005-11-18 17:00:10" "Too Much Joy" "Kicking (That Gone Fishing Song)" "Son of Sam I Am" "f9a3deb2-1b99-4fab-a32f-d594606bc1df" "244" "2005-11-18 17:00:10" "Too Much Joy" "Life is Flowers" "Son of Sam I Am" "053c11b7-577d-48d0-94cd-182af0b0cc84" "218" "2005-11-18 17:00:10" "Too Much Joy" "Connecticut" "Son of Sam I Am" "ad34c9c0-08bb-482b-aa75-41f7422e8fc7" "196" "2005-11-18 17:00:10" "Too Much Joy" "Bad Dog" "Son of Sam I Am" "c0641c0f-6357-47ae-a967-f39c57546236" "196" "2005-11-18 17:00:10" "Too Much Joy" "1964" "Son of Sam I Am" "0e56e785-75ec-4fa6-adb6-5fc2e58ffb7f" "223" "2005-11-18 17:00:10" "Too Much Joy" "Worse" "Son of Sam I Am" "2e4ccf4c-ba42-4206-8e38-758105475f06" "147" "2005-11-18 17:00:10" "Too Much Joy" "Seasons in the Sun" "Son of Sam I Am" "61d7f977-ef05-4648-b913-c4826c12e425" "212" "2005-11-18 17:00:10" "Too Much Joy" "If I Was a Mekon" "Son of Sam I Am" "7ca27d50-bc12-43c8-83b7-e28cd3a3be1d" "172" "2005-11-18 17:00:10" "Too Much Joy" "Train in Vain" "Son of Sam I Am" "14b48a3e-e448-47e5-850c-b9e3e01a1d10" "108" "2005-11-18 17:00:10"
Posted on 2005-11-18
Tags: quanks