2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2024-11-21 08:07:03 +01:00
|
|
|
|
Plays a .M3U playlist
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2022-02-10 08:57:52 +01:00
|
|
|
|
This PowerShell script plays the given playlist (in .M3U file format)
|
2021-10-16 16:50:10 +02:00
|
|
|
|
.PARAMETER filename
|
|
|
|
|
Specifies the path to the playlist
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2024-11-21 08:07:03 +01:00
|
|
|
|
PS> ./play-m3u.ps1 C:\MyPlaylist.m3u
|
|
|
|
|
▶️ Playing '01 Sandy beach - strong waves.mp3' (02:54) ...
|
|
|
|
|
...
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-09-06 21:42:04 +02:00
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-02-17 20:09:44 +01:00
|
|
|
|
#>
|
|
|
|
|
|
2021-10-04 21:29:23 +02:00
|
|
|
|
param([string]$filename = "")
|
2021-02-18 20:17:55 +01:00
|
|
|
|
|
2021-02-17 20:09:44 +01:00
|
|
|
|
try {
|
2024-11-21 08:07:03 +01:00
|
|
|
|
if ($filename -eq "" ) { $filename = Read-Host "Enter the path to the .M3U playlist file" }
|
2021-07-15 15:51:22 +02:00
|
|
|
|
|
2024-11-21 08:07:03 +01:00
|
|
|
|
if (-not(Test-Path "$filename" -pathType leaf)) { throw "Can't access playlist file: $filename" }
|
|
|
|
|
$lines = Get-Content $filename
|
2021-02-17 20:09:44 +01:00
|
|
|
|
|
2024-11-21 08:07:03 +01:00
|
|
|
|
Add-Type -assemblyName presentationCore
|
|
|
|
|
$MediaPlayer = New-Object system.windows.media.mediaplayer
|
2021-02-17 20:09:44 +01:00
|
|
|
|
|
2024-11-21 08:07:03 +01:00
|
|
|
|
foreach ($line in $lines) {
|
|
|
|
|
if ($line[0] -eq "#") { continue }
|
|
|
|
|
if (-not(Test-Path "$line" -pathType leaf)) { throw "Can't access audio file: $line" }
|
|
|
|
|
$fullPath = (Get-ChildItem "$line").fullname
|
|
|
|
|
|
|
|
|
|
& "$PSScriptRoot/play-mp3.ps1" $fullPath
|
2021-02-17 20:09:44 +01:00
|
|
|
|
}
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-02-17 20:09:44 +01:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-02-17 20:09:44 +01:00
|
|
|
|
exit 1
|
|
|
|
|
}
|