1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
# parsemedium: ZOMG functions for parsing media files
# Copyright (C) 2005-2025 Clint Adams
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
parse_ogginfo_or_opusinfo() {
local output album artist mbid title len tstamp
output=(${(f)"$($1 $2)"})
album=${${(M)output:#(#i)*ALBUM=*}#(#i)*ALBUM=}
artist=${${(M)output:#(#i)*ARTIST=*}#(#i)*ARTIST=}
mbid=${${(M)output:#(#i)*MUSICBRAINZ_TRACKID=*}#(#i)*MUSICBRAINZ_TRACKID=}
title=${${(M)output:#(#i)*TITLE=*}#(#i)*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})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len}")
}
parse_zomghelper() {
local output album artist mbid title len tstamp
output=(${(f)"$(zomghelper $1)"})
album=${${(M)output:#(#i)ALBUM=*}#(#i)ALBUM=}
artist=${${(M)output:#(#i)ARTIST=*}#(#i)ARTIST=}
mbid=${${(M)output:#(#i)MUSICBRAINZ_TRACKID=*}#(#i)MUSICBRAINZ_TRACKID=}
title=${${(M)output:#(#i)TITLE=*}#(#i)TITLE=}
len=${${(M)output:#ZOMGSECS:*}#ZOMGSECS: }
typeset -i len
tstamp=$(export TZ=UTC; strftime "%Y-%m-%d %H:%M:%S" ${EPOCHSECONDS})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len}")
}
parse_eyeD3() {
local output album artist mbid title len tstamp
output=(${(f)"$(eyeD3 --no-color $1)"})
album=${${${(M)output:#album: *}#album: }%% *}
artist=${${(M)output:#* artist: *}#* artist: }
mbid=${${(M)output:#Unique File ID: \[http://musicbrainz.org\] *}#Unique File ID: \[http://musicbrainz.org\] }
title=${${${(M)output:#title: *}#title: }%% *}
len=${${(M)output:#Time: *}#Time: }
if [[ "$len" == (#b)([0-9]##):([0-9]##):([0-9]##)[^0-9]* ]]
then
(( len = $match[1] * 3600 + $match[2] * 60 + $match[3] + 1 ))
elif [[ "$len" == (#b)([0-9]##):([0-9]##)[^0-9]* ]]
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})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len:-0}")
}
parse_mutagen() {
local output album artist mbid title len tstamp
output=(${(f)"$(mutagen-inspect --no-apev2 --no-flac $1)"})
album=${${(M)output:#TALB=*}#TALB=}
artist=${${(M)output:#TPE1=*}#TPE1=}
mbid=${${(M)output:#UFID=http://musicbrainz.org=*}#UFID=http://musicbrainz.org=}
title=${${(M)output:#TIT2=*}#TIT2=}
len=${${(M)output:#- MPEG*seconds*}/- MPEG*(#b) ([0-9.]##) seconds*/$match[1]}
typeset -i len
tstamp=$(export TZ=UTC; strftime "%Y-%m-%d %H:%M:%S" ${EPOCHSECONDS})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len:-0}")
[[ "${len}" -eq 0 ]] && return 1 || return 0
}
parse_mutagenflac() {
local output album artist mbid title len tstamp
output=(${(f)"$(mutagen-inspect --no-apev2 --no-mp3 $1)"})
album=${${(M)output:#(#i)album=*}#(#i)album=}
artist=${${(M)output:#(#i)artist=*}#(#i)artist=}
mbid=${${(M)output:#(#i)musicbrainz_trackid=*}#(#i)musicbrainz_trackid=}
title=${${(M)output:#(#i)title=*}#(#i)title=}
len=${${(M)output:#- FLAC,*seconds*Hz*}/- FLAC,(#b) ([0-9.]##) seconds*/$match[1]}
typeset -i len
tstamp=$(export TZ=UTC; strftime "%Y-%m-%d %H:%M:%S" ${EPOCHSECONDS})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len}")
}
parse_mutagenape() {
local output album artist mbid title len tstamp
output=(${(f)"$(mutagen-inspect --no-flac --no-mp3 $1)"})
album=${${(M)output:#(#i)Album=*}#(#i)Album=}
artist=${${(M)output:#(#i)Artist=*}#(#i)Artist=}
mbid=${${(M)output:#(#i)musicbrainz_trackid=*}#(#i)musicbrainz_trackid=}
title=${${(M)output:#(#i)Title=*}#(#i)Title=}
len=${${(M)output:#- Monkey\'s Audio*seconds*Hz*}/- Monkey\'s Audio*,(#b) ([0-9.]##) seconds*/$match[1]}
typeset -i len
tstamp=$(export TZ=UTC; strftime "%Y-%m-%d %H:%M:%S" ${EPOCHSECONDS})
reply=("${artist}" "${title}" "${album}" "${mbid}" "${len}")
}
|