Skip to content

PowerShell module and collection of PowerShell utilities for managing audio file metadata tags.

License

Notifications You must be signed in to change notification settings

RylandDeGregory/PSTagLib

Repository files navigation

PSTagLib

A collection of PowerShell utilities for downloading and tagging MP3 files with TagLibSharp.

Build Status PSTagLib package in PSTagLib feed in Azure Artifacts

PSTagLib PowerShell module source is located in the PSTagLib/ directory.

Installation

  1. Install PowerShell
    • If you have a Windows computer, launch it by pressing the Windows key and typing PowerShell. Click on Windows PowerShell (not ISE).
    • If you have a MacOS computer, install PowerShell. Launch PowerShell by pressing Cmd + Space and typing PowerShell.
  2. Download this repo to your local machine by clicking the Green Code button and choosing Download ZIP.
  3. Unzip PSTagLib.zip to any folder on your computer.

Download MP3 files

The script Invoke-MP3Download.ps1 will enable you to programmatically download MP3 files from certain websites. Downloading videos or audio from videos is currently unsupported unless you already have a working installation of ffmpeg.

Download youtube-dl

  • Invoke-MP3Download.ps1 can be utilized to programmatically download MP3 files using the youtube-dl command-line tool. If you do not have youtube-dl installed, follow the steps below taken from the youtube-dl download page.

Windows

Open PowerShell as Administrator and copy the following code into the window. Press Enter.

Invoke-RestMethod 'https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe' -OutFile "$env:USERPROFILE\Desktop\vcredist_x86.exe"
Start-Process "$env:USERPROFILE\Desktop\vcredist_x86.exe" -ArgumentList '/Q' -Wait
Remove-Item "$env:USERPROFILE\Desktop\vcredist_x86.exe" -Force -ErrorAction SilentlyContinue
Invoke-WebRequest 'https://yt-dl.org/downloads/latest/youtube-dl.exe' -OutFile "$env:USERPROFILE\AppData\Local\Microsoft\WindowsApps\youtube-dl.exe"
$env:Path = [System.Environment]::GetEnvironmentVariable('PATH')

MacOS and Linux

Open PowerShell and copy the following code into the window. Press Enter.

You will be prompted for your password. Type it in and press Enter. Don't worry if there aren't dots indicating that you are typing, your input is still being received.

Invoke-RestMethod -Method Get -Uri 'https://yt-dl.org/downloads/latest/youtube-dl' -OutFile '/usr/local/bin/youtube-dl'
sudo chmod a+rx '/usr/local/bin/youtube-dl'
$env:Path = [System.Environment]::GetEnvironmentVariable('PATH')

Download MP3 files using PowerShell and youtube-dl

  1. Determine the files you want to download by collecting their URLs from the website(s) you want to download them from.
  2. If you have multiple URLs, paste the URLs into a .txt or .csv file one per line, and save the file into the PSTagLib directory.
  3. Open PowerShell. See the Installation section for details.

Interactive download

  1. Drag and drop Invoke-MP3Download.ps1 into the PowerShell window. Press Enter.
  2. At the first question, select the mode you want the script to run in by typing 1 or 2. Press Enter, then do the following based on your choice:
    • 1: Paste the link into the PowerShell window. Press Enter.
    • 2: Drag and drop the .txt or .csv file you created above into the PowerShell window. Press Enter.
  3. The MP3 files corresponding to the link(s) provided will be downloaded to the Desktop, and a log of operations (including any errors, see Troubleshooting) will be written to the PowerShell window.

If you are satisfied with the results of your MP3 file download(s), proceed to the Set MP3 tags section to set the metadata tags for the newly-downloaded MP3 files.

Programmatic download

PowerShell Comment-based Help is provided for Invoke-MP3Download.ps1. To view, type the following into a PowerShell window and press Enter (your path to the script may be different):

Get-Help -Full ./Invoke-MP3Download.ps1
  • Example 1: Download a list of links from a .txt file on the Desktop and save to them to the current directory.
./Invoke-MP3Download.ps1 -InputFile 'C:\Users\user1\Desktop\tracks.txt'
  • Example 2: Download a list of links from a .csv file and save them to the Music folder.
./Invoke-MP3Download.ps1 -InputFile '/Users/user1/Desktop/tracks.csv' -OutputPath '/Users/user1/Music/'
  • Example 3: Download a single link and save it to the Desktop.
./Invoke-MP3Download.ps1 -InputURL 'https://soundcloud.com/ryland-degregory/sample1' -OutputPath 'C:\Users\user1\Desktop\'
  • Example 4: Download multiple links and save them to the current directory.
./Invoke-MP3Download.ps1 -InputURL 'https://soundcloud.com/ryland-degregory/sample1', 'https://soundcloud.com/ryland-degregory/sample2'

The MP3 files corresponding to the link(s) provided will be downloaded, and a log of operations (including any errors, see Troubleshooting) will be written to the PowerShell window.

If you are satisfied with the results of your MP3 file download(s), proceed to the Set MP3 tags section to set the metadata tags for the newly-downloaded MP3 files.

Set MP3 Metadata tags

Ensure that both Set-MP3Tags.ps1 and taglib-sharp.dll are in the same folder.

  • Set-MP3Tags.ps1 can be utilized either interactively or programmatically.
  • It expects files to adhere to the following naming convention:
<Artist> - <Title> (<mix>)

Example: Above & Beyond, OceanLab - Satellite (Trance Wax Extended Mix)
  • The delimiter between artist and title is ' - ' (space, hyphen, space).
  • Any files that fail to adhere to the naming convention will not be processed.
C:\Users\Ryland\Music\Trance\Factor B feat. Cat Martin Crashing Over (Extended Mix).mp3
***Filename improperly formatted. This file will be skipped.***

Interactively

Example 1

  1. Open PowerShell. See the Installation section for details.
  2. Drag and drop Set-MP3Tags.ps1 into the PowerShell window. Press Enter.
  3. Follow prompt to select the folder it will process.
What is the path to the folder you want to process?: C:\Users\Ryland\Music\Trance
  1. Select if you want the Genre set or not during processing.
    • The Genre will be the name of the leaf folder. In this example, it would be Trance.
Would you like to set the genre based on folder name? Enter 'Y' or 'N': Y

Output 1

----------
C:\Users\RylandMusic\Trance\Above & Beyond, OceanLab - Satellite (Trance Wax Extended Mix).mp3
Artist: Above & Beyond, OceanLab
Title: Satellite (Trance Wax Extended Mix)
Genre: Trance
----------
Completed.

Programmatically

Example 2

  1. Execute the script from a PowerShell session, specifying the directory as a parameter.
./Set-MP3Tags.ps1 -Directory "C:\Users\Ryland\Music\Trance"
  1. Execute the script from PowerShell, specifying a directory and for Genre to be processed.
    • The Genre will be the name of the leaf folder. In this example, it would be Trance.
./Set-MP3Tags.ps1 -Directory "C:\Users\Ryland\Music\Trance" -Genre

Output 2

PS C:\Users\Ryland\Documents\Code\PSTagLib> .\Set-MP3Tags.ps1 -Directory C:\Users\Ryland\Music\Trance -Genre
----------
C:\Users\Ryland\Music\Trance\Above & Beyond, OceanLab - Satellite (Trance Wax Extended Mix).mp3
Artist: Above & Beyond, OceanLab
Title: Satellite (Trance Wax Extended Mix)
Genre: Trance
----------
C:\Users\Ryland\Music\Trance\Factor B feat. Cat Martin - Crashing Over (Extended Mix).mp3
Artist: Factor B feat. Cat Martin
Title: Crashing Over (Extended Mix)
Genre: Trance
----------
Completed.
Press Enter to exit:

Troubleshooting

Script won't execute

WindowsTerminal_EVBHp0icto

  • Ensure that you can execute scripts on your machine. Enter an Administrator PowerShell session and paste the following command:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
  • If you change this setting, you MUST change it back when you are done using this tool.
Set-ExecutionPolicy -ExecutionPolicy Default

Invalid folder path

WindowsTerminal_soOeUqTpkg

  • If your folder path has a space, you may have to wrap the path in quotes ("").
    • "C:\Users\Ryland\New Music\Trance"

Filename improperly formatted

  • If you receive the following error message on any of your files, review the naming convention (default Artist - Title).
    • If you desire, you may modify the delimiter by which the script processes files. In Set-MP3Tags.ps1, modify the value of $delimiter at the top of the script.
----------
C:\Users\Ryland\Desktop\Music\Trance\Factor B feat. Cat Martin Crashing Over (Extended Mix).mp3
***Filename improperly formatted. This file will be skipped.***
----------
  • Once you have updated the incorrect filenames, you can safely run the script again with no impact to the already-correct files.

License

This code is distributed under the MIT License.

About

PowerShell module and collection of PowerShell utilities for managing audio file metadata tags.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published