Various Linux scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

5 years ago
#!/usr/bin/env tclsh
#Создан: пт 19 июн 2020 15:42:10
#Изменён: Сб 10 окт 2020 18:20:25
# Сценарий удаления треков с указанной оценкой из mpd
proc mpd {args} {
set mpd [socket 127.0.0.1 6600]
foreach command $args {
puts $mpd $command
}
puts $mpd close
flush $mpd
set mpd_answer [split [read $mpd] "\n"]
set mpd_status [lindex $mpd_answer 0]
set answer_code [lindex $mpd_answer 1]
if {[string match "OK MPD *" $mpd_status]} {
if {![string match "ACK*" $answer_code]} {
return [lrange $mpd_answer 1 end-2]
} else {
return [list 1 $answer_code]
}
} else {
return [list 1 $mpd_answer]
}
}
set playlistlength [regsub {^[^:]*:\s+} [lindex [mpd status] 6] {}]
set commented {}
for {set pos 0} {$pos <= $playlistlength} {incr pos} {
array unset song
set info [mpd "playlistinfo $pos"]
foreach metadata $info {
regexp -expanded {^([^:]+):\s+(.*)$} $metadata match key value
set song([string tolower $key]) $value
}
if {[info exists song(comment)] && [regexp {^[1-5]\+?$} $song(comment)]} {
lappend commented $song(id)
}
}
mpd {*}[lmap id $commented {list deleteid $id}]