A collection of PowerShell utilities for downloading and tagging MP3 files with TagLibSharp.
PSTagLib PowerShell module source is located in the
PSTagLib/
directory.
- 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.
- Download this repo to your local machine by clicking the Green Code button and choosing Download ZIP.
- Unzip
PSTagLib.zip
to any folder on your computer.
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
.
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.
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')
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')
- Determine the files you want to download by collecting their URLs from the website(s) you want to download them from.
- If you have multiple URLs, paste the URLs into a
.txt
or.csv
file one per line, and save the file into thePSTagLib
directory. - Open PowerShell. See the Installation section for details.
- Drag and drop
Invoke-MP3Download.ps1
into the PowerShell window. Press Enter. - At the first question, select the mode you want the script to run in by typing
1
or2
. 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.
- 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.
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.
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.***
- Open PowerShell. See the Installation section for details.
- Drag and drop
Set-MP3Tags.ps1
into the PowerShell window. Press Enter. - 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
- 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
.
- The Genre will be the name of the leaf folder. In this example, it would be
Would you like to set the genre based on folder name? Enter 'Y' or 'N': Y
----------
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.
- Execute the script from a PowerShell session, specifying the directory as a parameter.
./Set-MP3Tags.ps1 -Directory "C:\Users\Ryland\Music\Trance"
- 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
.
- The Genre will be the name of the leaf folder. In this example, it would be
./Set-MP3Tags.ps1 -Directory "C:\Users\Ryland\Music\Trance" -Genre
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:
- 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
- If your folder path has a space, you may have to wrap the path in quotes ("").
"C:\Users\Ryland\New Music\Trance"
- 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.
- If you desire, you may modify the delimiter by which the script processes files. In
----------
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.
This code is distributed under the MIT License.