Skip to content

the13thing/PowerShellAudioScripts

Repository files navigation

PowerShell Audio Scripts

A collection of PowerShell scripts for audio file management and playlist generation.

Scripts

RandomSongs.ps1

A PowerShell script that copies a random subset of audio files from a source library with advanced features like FLAC to MP3 conversion, artist limits, and flexible renaming schemes.

PlaylistGen.ps1

A PowerShell script that searches for audio files based on a CSV file containing song names and artists, creating playlists from found matches using fuzzy string matching. Always creates a full paths file for use with CopyFromList.ps1.

CopyFromList.ps1

A PowerShell script that copies audio files from a list of full file paths while preserving folder structure. Supports FLAC to MP3 conversion and multiple file renaming schemes based on audio metadata.

Features

RandomSongs.ps1

  • Random Selection: Pick random audio files from your music library
  • Two Modes:
    • Total Mode: Select a specific total number of files across entire library
    • Per-Folder Mode: Select a specific number of files from each folder
  • Artist Limits: Limit maximum files per artist to ensure variety
  • FLAC to MP3 Conversion: Convert FLAC files to MP3 with metadata and cover art preservation
  • Flexible Renaming: Multiple file naming schemes
  • Dry Run: Preview actions without actually copying files
  • Interactive Mode: GUI-like prompts when run without parameters
  • Preserves Structure: Maintains original folder hierarchy in output

PlaylistGen.ps1

  • CSV Input: Reads song and artist names from CSV file
  • Fuzzy Matching: Intelligent string matching for both artist names and song titles
  • Configurable Thresholds: Adjustable similarity percentages for matching
  • Multiple Formats: Supports M3U, PLS, and WPL playlist formats
  • Path Type Control: Generate playlists with relative or absolute file paths
  • Full Paths File: Always creates a companion file with full file paths for use with CopyFromList.ps1
  • Interactive Mode: GUI-like prompts when run without parameters
  • Dry Run: Preview matches without creating playlist
  • Metadata Reading: Uses ffprobe for accurate metadata extraction

CopyFromList.ps1

  • Full Path Input: Reads file paths from text files (typically generated by PlaylistGen.ps1)
  • Structure Preservation: Maintains artist/album folder hierarchy starting from artist folder
  • FLAC to MP3 Conversion: Convert FLAC files to MP3 with metadata and cover art preservation
  • Metadata-Based Renaming: Multiple file naming schemes using extracted audio metadata
  • Interactive Mode: GUI-like prompts when run without parameters
  • Dry Run: Preview actions without actually copying files
  • Progress Reporting: Shows detailed progress and success rates

Supported Audio Formats

  • FLAC
  • MP3
  • WAV
  • AAC
  • OGG
  • M4A
  • WMA

Requirements

Workflow Integration

The scripts are designed to work together in a complete audio management workflow:

Typical Workflow

  1. PlaylistGen.ps1: Search your music library using a CSV file and create playlists

    • Generates standard playlists (M3U/PLS/WPL) for media players
    • Creates full paths file (PlaylistName-FullPaths.txt) for use with CopyFromList.ps1
  2. CopyFromList.ps1: Copy and organize the found files

    • Uses the full paths file from PlaylistGen.ps1
    • Preserves folder structure (Artist/Album hierarchy)
    • Optionally converts FLAC to MP3
    • Optionally renames files using metadata

Example Complete Workflow

# Find songs from CSV and create playlist
.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "wishlist.csv" -PlaylistName "MyWishlist"

# Copy found songs with conversion and renaming  
.\CopyFromList.ps1 -Src "MyWishlist-FullPaths.txt" -Dest "E:\Portable" -ConvertToMp3 -RenameScheme "TrackArtistSong"

This workflow allows you to:

  • Maintain your original music library untouched
  • Create organized, converted copies for different devices
  • Use CSV files to batch-process song collections
  • Preserve folder structure while applying consistent naming

CSV Format (PlaylistGen.ps1)

The CSV file should contain songs in the following format:

Song Title,Artist Name
Always Be (feat. Kaya Thomas-Dyke),Alfa Mist
In The Stars,Melody's Echo Chamber
Dålig teve,Dina Ögon

Compiling

ps2exe -inputFile RandomSongs.ps1 -outputFile RandomSongs.exe
ps2exe -inputFile PlaylistGen.ps1 -outputFile PlaylistGen.exe
ps2exe -inputFile CopyFromList.ps1 -outputFile CopyFromList.exe

Usage

Interactive Mode

Simply run without parameters for guided setup:

RandomSongs.ps1:

.\RandomSongs.ps1

PlaylistGen.ps1:

.\PlaylistGen.ps1

CopyFromList.ps1:

.\CopyFromList.ps1

Command Line Examples

RandomSongs.ps1

Basic usage - 100 random songs:

.\RandomSongs.ps1 -Src "D:\Music" -Dest "E:\Output" -Total 100

With artist limits and FLAC conversion:

.\RandomSongs.ps1 -Src "D:\Music" -Dest "E:\Output" -Total 500 -MaxPerArtist 3 -ConvertToMp3

Per-folder mode with custom naming:

.\RandomSongs.ps1 -Src "D:\Music" -Dest "E:\Output" -Count 5 -RenameScheme "artist-title"

Dry run to preview actions:

.\RandomSongs.ps1 -Src "D:\Music" -Total 100 -DryRun

PlaylistGen.ps1

Basic usage - Create playlist from CSV:

.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "songs.csv" -Dest "E:\Playlists"

With custom thresholds:

.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "songs.csv" -ArtistThreshold 90 -SongThreshold 60

Different playlist format:

.\PlaylistGen.ps1 -Src "D:\Music" -PlaylistFormat "PLS" -PlaylistName "MyPlaylist"

Dry run to preview matches:

.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "songs.csv" -DryRun

CopyFromList.ps1

Basic usage - Copy files from full paths list:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -Dest "E:\Output"

With FLAC conversion:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -Dest "E:\Output" -ConvertToMp3

With metadata-based renaming:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -Dest "E:\Output" -RenameScheme "ArtistSong"

Combined: Convert and rename with track numbers:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -Dest "E:\Output" -ConvertToMp3 -RenameScheme "TrackArtistSong"

Dry run to preview actions:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -DryRun

Parameters

RandomSongs.ps1

Parameter Type Description Default
-Src String Source music library path Current directory
-Dest String Destination output path "Output" folder
-Count Integer Files per folder (per-folder mode) 3
-Total Integer Total files to select (total mode) Not set
-ConvertToMp3 Switch Convert FLAC files to MP3 False
-MaxPerArtist Integer Maximum files per artist No limit
-RenameScheme String File naming scheme "number-title"
-DryRun Switch Preview only, don't copy files False

PlaylistGen.ps1

Parameter Type Description Default
-Src String Source music library path Current directory
-Dest String Destination playlist path Current directory
-CsvSrc String CSV file with songs to find "addToPlaylist.csv"
-ArtistThreshold Integer Artist name matching percentage 80
-SongThreshold Integer Song title matching percentage 50
-PlaylistFormat String Playlist format (M3U/PLS/WPL) "M3U"
-PlaylistName String Name of the generated playlist "GeneratedPlaylist"
-PathType String Path type in playlist (Relative/Absolute) "Relative"
-DryRun Switch Preview only, don't create playlist False

CopyFromList.ps1

Parameter Type Description Default
-Src String Full paths file to read from Required
-Dest String Destination output path "Output" folder
-ConvertToMp3 Switch Convert FLAC files to MP3 False
-RenameScheme String File naming scheme "Original"
-DryRun Switch Preview only, don't copy files False

Rename Schemes

RandomSongs.ps1

  1. number-title (default): 01 Song Title.mp3
  2. number-artist-title: 01 Artist Name - Song Title.mp3
  3. artist-title: Artist Name - Song Title.mp3

CopyFromList.ps1

  1. Original (default): Keeps original filename (e.g., 01 Enter Sandman.flac)
  2. ArtistSong: Artist - Song.ext (e.g., Apocalyptica - Enter Sandman.flac)
  3. SongArtist: Song - Artist.ext (e.g., Enter Sandman - Apocalyptica.flac)
  4. TrackArtistSong: 01 Artist - Song.ext (e.g., 01 Apocalyptica - Enter Sandman.flac)

Playlist Formats (PlaylistGen.ps1)

  1. M3U (default): Standard playlist format, widely supported
  2. PLS: Winamp/Shoutcast playlist format
  3. WPL: Windows Media Player playlist format

How It Works

RandomSongs.ps1

Total Mode (-Total specified)

  1. Scans entire source library for audio files
  2. Randomly selects specified number of files
  3. Respects per-artist limits if specified
  4. Copies to destination maintaining folder structure

Per-Folder Mode (default)

  1. Processes each subfolder individually
  2. Selects specified number of random files from each folder
  3. Copies non-audio files (cover art, etc.) from folders with selected audio
  4. Maintains original folder hierarchy

FLAC Conversion

When -ConvertToMp3 is enabled:

  • Converts FLAC files to high-quality MP3 (VBR ~192kbps)
  • Preserves all metadata tags
  • Embeds cover art from FLAC file
  • Resizes cover art to 300x300px for efficiency

PlaylistGen.ps1

Search Process

  1. Reads CSV file with song names and artist names
  2. Scans source library for all audio files
  3. Extracts metadata (artist, title) from each file using ffprobe
  4. Uses fuzzy string matching to find best matches
  5. Creates playlist with found matches

Fuzzy Matching

  • Artist Matching: Default 80% similarity threshold
  • Song Matching: Default 50% similarity threshold
  • Uses Levenshtein distance algorithm for intelligent matching
  • Handles variations in spelling, punctuation, and formatting

Matching Priority

  • Files must meet both artist AND song thresholds to be included
  • Best match (highest combined similarity) is selected when multiple matches exist
  • Fallback to folder/filename if metadata extraction fails

CopyFromList.ps1

Copy Process

  1. Reads full file paths from input text file (one path per line)
  2. Extracts artist folder structure from each path (preserves Artist/Album hierarchy)
  3. Optionally extracts metadata for renaming (artist, title, track number)
  4. Copies files while preserving folder structure starting from artist folder
  5. Optionally converts FLAC files to MP3 with metadata preservation

Metadata-Based Renaming

When using rename schemes other than "Original":

  • Uses ffprobe to extract artist, title, and track number from audio files
  • Handles different metadata tag variations (ARTIST/artist, TITLE/title, etc.)
  • Automatically pads track numbers to 2 digits (01, 02, etc.)
  • Sanitizes filenames while preserving UTF-8 characters
  • Falls back to original filename if metadata extraction fails

FLAC Conversion

When -ConvertToMp3 is enabled:

  • Converts FLAC files to high-quality MP3 (VBR ~192kbps)
  • Preserves all metadata tags
  • Embeds cover art from FLAC file
  • Resizes cover art to 300x300px for efficiency
  • Can be combined with any rename scheme

Output Structure

RandomSongs.ps1

The script preserves the original folder structure:

Source:
D:\Music\
├── Artist A\Album 1\01 Song.flac
└── Artist B\Album 2\02 Track.mp3

Output:
E:\Output\
├── Artist A\Album 1\01 Song.mp3
└── Artist B\Album 2\02 Track.mp3

PlaylistGen.ps1

Creates playlist files referencing original audio file locations:

Generated playlist: MyPlaylist.m3u
Content:
#EXTM3U
#EXTINF:-1,Alfa Mist - Always Be (feat. Kaya Thomas-Dyke)
D:\Music\Alfa Mist\Bring Backs\01 Always Be.flac

Full paths file: MyPlaylist-FullPaths.txt
Content:
D:\Music\Alfa Mist\Bring Backs\01 Always Be.flac
D:\Music\Melody's Echo Chamber\Bon Voyage\02 In The Stars.mp3

CopyFromList.ps1

Preserves artist/album folder structure from original paths:

Input file: playlist-FullPaths.txt
Content:
D:\Music\Apocalyptica\Plays Metallica by Four Cellos\01 Enter Sandman.flac

Output structure:
E:\Output\
└── Apocalyptica\
    └── Plays Metallica by Four Cellos\
        └── 01 Apocalyptica - Enter Sandman.mp3  (with renaming + conversion)

Performance Tips

RandomSongs.ps1

  • Use -MaxPerArtist for faster processing with large libraries
  • The script uses directory names for artist detection (faster than metadata parsing)
  • FLAC conversion is CPU-intensive; consider smaller batches for older systems

PlaylistGen.ps1

  • Lower thresholds increase processing time but find more matches
  • Ensure ffprobe is in PATH for accurate metadata extraction
  • Large music libraries may take longer to scan initially

CopyFromList.ps1

  • Metadata extraction for renaming requires ffprobe (can be skipped with "Original" scheme)
  • FLAC conversion is CPU-intensive; consider processing in smaller batches
  • Use dry run mode to verify folder structure and renaming before actual copying
  • The script processes files sequentially for better error handling and progress tracking

Error Handling

  • Skips inaccessible files gracefully
  • Handles long file paths by truncating names
  • Validates all parameters before processing
  • Creates destination folders as needed

Examples

RandomSongs.ps1

Create a 1000-song playlist with max 2 songs per artist:

.\RandomSongs.ps1 -Total 1000 -MaxPerArtist 2 -ConvertToMp3 -RenameScheme "artist-title"

Sample 5 songs from each album folder:

.\RandomSongs.ps1 -Count 5 -RenameScheme "number-artist-title"

Quick preview of what would be selected:

.\RandomSongs.ps1 -Total 50 -MaxPerArtist 1 -DryRun

PlaylistGen.ps1

Create playlist from CSV with strict matching:

.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "wishlist.csv" -ArtistThreshold 95 -SongThreshold 80

Generate PLS playlist with relaxed matching:

.\PlaylistGen.ps1 -CsvSrc "songs.csv" -PlaylistFormat "PLS" -ArtistThreshold 70 -SongThreshold 40

Preview matches without creating playlist:

.\PlaylistGen.ps1 -CsvSrc "addToPlaylist.csv" -DryRun

CopyFromList.ps1

Complete workflow from CSV to organized music files:

# Step 1: Generate playlist and full paths file
.\PlaylistGen.ps1 -Src "D:\Music" -CsvSrc "songs.csv" -PlaylistName "MyCollection"

# Step 2: Copy files with conversion and renaming
.\CopyFromList.ps1 -Src "MyCollection-FullPaths.txt" -Dest "E:\OrganizedMusic" -ConvertToMp3 -RenameScheme "TrackArtistSong"

Copy files with original names (fastest):

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -Dest "E:\Backup"

Convert FLAC to MP3 with artist-song naming:

.\CopyFromList.ps1 -Src "flac-files.txt" -Dest "E:\MP3Collection" -ConvertToMp3 -RenameScheme "ArtistSong"

Preview what files will be copied and how they'll be renamed:

.\CopyFromList.ps1 -Src "playlist-FullPaths.txt" -RenameScheme "SongArtist" -DryRun

License

These scripts are provided as-is for personal use. Ensure you have rights to copy and convert your audio files.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published