Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NR<=2 { next }
- /^ *dict entry\(/ { ++l; next }
- /^ *\)$/ {
- if (typeof(b[l][2]) == "unassigned") {
- for (k in b[l+1])
- b[l][b[l][1]][k] = b[l+1][k]
- delete b[l+1]
- }
- else if (isarray(b[l][2]))
- for (k in b[l][2])
- b[l][b[l][1]][k] = b[l][2][k]
- else
- b[l][b[l][1]]=b[l][2];
- delete b[l][1]
- delete b[l][2]
- n[l] = 0
- --l
- next
- }
- /^ *\]$/ { n[l] = 0; --l; next }
- /^ *variant/ { gsub(/^ *variant/, "") }
- {
- match($0, / *(object path|[^ ]+) +(.*)/, a);
- switch (a[1]) {
- case "array": ++l; delete b[l][0]; next
- case "string":
- case "object path":
- strings_to_decode[++sdl][0]=gensub(/"(.*)"/,"\\1",1,a[2])
- v="\a"sdl
- break
- default:
- v=a[2]
- }
- b[l][++n[l]] = v
- }
- function id(s) { return s }
- function decode_string(s) {
- return typeof(s) == "string" && substr(s,1,1) == "\a" \
- ? strings_to_decode[strtonum(substr(s,2))][1] \
- : s
- }
- function cp(a, b, k, f) {
- if (isarray(a)) {
- b[k][0] = 0; delete b[k][0]
- for (k_ in a)
- cp(a[k_], b[k], @f(k_), f)
- } else
- b[k] = @f(a)
- }
- function p(i, a, o) {
- if (isarray(a)) {
- if (!o) print ":"
- for (k in a) {
- printf "%s[%s]", i, k
- p("\t"i, a[k])
- }
- }
- else
- printf " [%s]\n", a
- }
- function decode_strings() { if (length(strings_to_decode) == 0) return
- decode_cmd = "bash -c 'while IFS= read -r s; do printf %b\\\\n \"${s//%/\\\\x}\"; done'"
- for (i in strings_to_decode)
- print strings_to_decode[i][0] |& decode_cmd
- close(decode_cmd, "to")
- i = 0
- while ((decode_cmd |& getline s) > 0)
- strings_to_decode[++i][1] = s
- close(decode_cmd)
- }
- END {
- decode_strings()
- cp(b[1], dbus, 0, "decode_string")
- # uncomment this to see what dbus gives you
- #p("", dbus, 1)
- # uncomment this to see what mediainfo gives you
- #p("", mediainfo, 1)
- # example
- title = dbus[0]["xesam:title"]
- artist = dbus[0]["xesam:artist"][1]
- rating = dbus[0]["xesam:userRating"] == "1" ? "luv" : dbus[0]["xesam:userRating"]
- MAX_TITLE_LENGTH = 40
- # TRUNCATION_STRING = "..."
- TRUNCATION_STRING = "…"
- if (length(title) > MAX_TITLE_LENGTH)
- title = substr(title, 1, MAX_TITLE_LENGTH - length(TRUNCATION_STRING)) TRUNCATION_STRING
- printf "%s / %s / %s\n", title, artist, rating
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement