Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
Last active February 4, 2022 06:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chapmanjacobd/4b07d0f64b64ac6fa70056aa44ec02a7 to your computer and use it in GitHub Desktop.
Save chapmanjacobd/4b07d0f64b64ac6fa70056aa44ec02a7 to your computer and use it in GitHub Desktop.
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$|ogg$|oga$|opus$'
end
@chapmanjacobd
Copy link
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