Created
July 31, 2024 14:22
-
-
Save DaWe35/e96220ca6e8b86025506d3b27e29b556 to your computer and use it in GitHub Desktop.
Play random songs from a folder with VLC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Directory containing your music files | |
# It will NOT search subfolders, you can change that by removing -maxdepth 1 | |
MUSIC_DIR="/you/music/folder" | |
# Number of random songs to play | |
NUM_SONGS=100 | |
# Check if VLC is installed | |
if ! command -v vlc &> /dev/null | |
then | |
echo "VLC is not installed. Please install VLC to use this script." | |
exit 1 | |
fi | |
# Check if the directory exists | |
if [ ! -d "$MUSIC_DIR" ]; then | |
echo "Directory $MUSIC_DIR does not exist." | |
exit 1 | |
fi | |
# Find all music files in the directory (excluding subdirectories) and select random ones | |
mapfile -t MUSIC_FILES < <(find "$MUSIC_DIR" -maxdepth 1 -type f \( -iname "*.mp3" -o -iname "*.wav" -o -iname "*.flac" -o -iname "*.ogg" \) | shuf -n $NUM_SONGS) | |
echo $MUSIC_FILES | |
# Check if enough files were found | |
if [ ${#MUSIC_FILES[@]} -lt $NUM_SONGS ]; then | |
echo "Not enough music files found in the directory." | |
exit 1 | |
fi | |
# Play the random songs with VLC | |
vlc "${MUSIC_FILES[@]}" --play-and-exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment