Something went wrong. Try again.
Small nushell script for managing local playlists of songs in the same directory as the script.
Something went wrong. Try again.
1.6 kB · 45 lines · Created 4mo ago
Nushell
123456789101112131415161718192021222324252627282930313233343536373839404142434445#!/usr/bin/env nu
const SELF = path self;
def main [playlist: path] { if ($playlist | path exists | not $in) { print $"Making New Playlist: ($playlist)"; "" | save $playlist; }
let parent = $SELF | path dirname;
let songs = open --raw $playlist | lines | where {is-empty | not $in};
print $"Loaded ($songs | length) songs from list"; let action = ["Add Songs" "Remove Songs" "Prune" "Quit"] | input list "What would you like to do?";
match $action { "Add Songs" => { let songs_not_present = ls ...(glob "**/*.{flac,mp3}") | get name | each {path relative-to $parent} | where {$in not-in $songs}; let choices = $songs_not_present | input list --multi --fuzzy "Select songs to add"; print $"Adding ($choices | length) new songs to ($playlist)"; $songs | append $choices | str join "\n" | save -f $playlist; print "Done."; } "Remove Songs" => { let choices = $songs | input list --multi --fuzzy "Select songs to remove"; print $"Removing ($choices | length) songs from ($playlist)"; $songs | where $it not-in $choices | save -f $playlist; print "Done."; } "Prune" => { print "Pruning songs not present on FS"; let present_songs = $songs | where {path exists}; let missing = $songs | length | $in - ($present_songs | length); if $missing == 0 { print "No Songs Missing."; } else { print $"Found ($missing) songs missing, removing"; $present_songs | save -f $playlist; print "Done."; } } }}