Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd chapmanjacobd/music.md
Last active Apr 28, 2020

Embed
What would you like to do?
minimalist music player
~ $ type mp
mp is a function with definition
function mp
    mpv --input-ipc-server=/tmp/mpvsocket --shuffle --no-video /home/xk/Music/
end
~ $ type trash
trash is a function with definition
function trash
    kioclient move (echo $argv | sed 's/^-\w\+//') trash:/
end
function nextSong
   set song (echo '{ "command": ["get_property", "path"] }' | socat - /tmp/mpvsocket | jq .data | sed -e 's/^"//' -e 's/"$//')
              
   echo 'playlist_next' | socat - /tmp/mpvsocket
   incrFileSuffix $song
end
function incrFileSuffix
    for file in $argv
        set match (string match -e -r '(.+)\.(\d+)\.([^.]+)' $file)
        if test $status -eq 0
            set root $match[-3]
            set n (math $match[-2] + 1)
            set ext $match[-1]
        else
            set match (string match -e -r '(.+)\.([^.]+)' $file)
            if test $status -ne 0
                # file does not have a dot. what to do?
                return
            end
            set root $match[-2]
            set n 1
            set ext $match[-1]
        end
        if test $n -gt 30
            trash $file
        else
            mv -iv $file $root.$n.$ext
        end
    end
end

play specific

function playSomething -a genre manyMult
      set many (default $manyMult 1)
      cd ~/Music/
      set files (filesDeep | fileTypeAudio | shuf -n (math "100*$many") | filterByGenre $genre)
      mpv --input-ipc-server=/tmp/mpvsocket --shuffle --no-audio-display $files
end
function default
    for val in $argv
        if test "$val" != ""
            echo $val
            break
        end
    end
end
function filesDeep
    find . -not -type d -exec du -h {} + | sort -h $argv | cut -f2
end
function filterByGenre
    while read file
        if ffprobe "$file" 2>&1 | sed -E -n 's/^ *GENRE *: (.*)/\1/p' | grep -q "$argv"
            echo "$file"
        else
        end
    end
end
function fileTypeAudio
    grep -E 'flac$|mp3$|m4a$|wav$|[.]og[g|a]$'
end
@chapmanjacobd

This comment has been minimized.

Copy link
Owner Author

chapmanjacobd commented Apr 17, 2020

set up a custom shortcut such that alt-f will trigger nextSong. it will keep track how many times you skipped a song by renaming the file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.