Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AnonymerNiklasistanonym/53e1b6e27043a6e8c99fe52d7ce88a5a to your computer and use it in GitHub Desktop.
Save AnonymerNiklasistanonym/53e1b6e27043a6e8c99fe52d7ce88a5a to your computer and use it in GitHub Desktop.
Scripts to stream online streams via streamlink or YouTube playlists using youtube-dl to VLC (very low CPU usage)
#!/usr/bin/env pwsh
Param (
[string]$YouTubeDL = "yt-dlp.exe",
[string]$MediaPlayer = "C:\Program Files\VideoLAN\VLC\vlc.exe",
[string[]]$MediaPlayerOptions = @(
# Don't render video to save resources
"--no-video"
# Start in background with no foreground window
"--qt-start-minimized"
# Shuffle playlist content
"--random"
),
[string]$YouTubePlaylistURL = "https://youtube.com/playlist?list=PLv9TnWhb81QxzAMNKVLLdipkc4N3Hvh8R",
[string]$TempPlaylistPath = (Join-Path -Path $env:TEMP -ChildPath "temp_playlist_music.m3u"),
[bool]$ClearTempPlaylist = $false
)
# Stop script on error
$ErrorActionPreference = "Stop"
# Run this command if you can't execute any scripts
# > set-executionpolicy remotesigned
# Get YouTubeDL: (winget install Python.Python.3.11, pip install yt-dlp)
# > https://github.com/yt-dlp/yt-dlp/releases
# Get VLC media player: (winget install VideoLAN.VLC)
# > https://www.videolan.org/vlc/index.de.html
if ($ClearTempPlaylist -and (Test-Path -Path $TempPlaylistPath -PathType Leaf)) {
Remove-Item -Path $TempPlaylistPath
}
# Parse and store the videos of the YouTube playlist in a file that can be imported if not already existing
if (-not (Test-Path -Path $TempPlaylistPath -PathType Leaf)) {
[string[]]$YouTubeDLArguments = @("-O", "#EXTINF:%(duration)s,%(upload_date>%d/%m/%Y)s %(title)s", "-O", "webpage_url", $YouTubePlaylistURL)
Start-Process -FilePath $YouTubeDL -ArgumentList $YouTubeDLArguments -NoNewWindow -PassThru -Wait -RedirectStandardOutput $TempPlaylistPath
}
# Load created playlist file with media player
[string[]]$MediaPlayerArguments = $MediaPlayerOptions + @($TempPlaylistPath)
Start-Process -FilePath $MediaPlayer -ArgumentList $MediaPlayerArguments -NoNewWindow -PassThru
#!/usr/bin/env pwsh
Param (
[string]$MediaPlayer = "C:\Program Files\VideoLAN\VLC\vlc.exe",
[string[]]$MediaPlayerOptions = @(
# Don't render video to save resources
"--no-video"
# Start in background with no foreground window
"--qt-start-minimized"
),
[string]$YouTubeVideoURL = "https://www.youtube.com/watch?v=VExiRl2azl8"
)
# Stop script on error
$ErrorActionPreference = "Stop"
# Run this command if you can't execute any scripts
# > set-executionpolicy remotesigned
# Get VLC media player: (winget install VideoLAN.VLC)
# > https://www.videolan.org/vlc/index.de.html
# Open video URL with media player
[string[]]$MediaPlayerArguments = $MediaPlayerOptions + @($YouTubeVideoURL)
Start-Process -FilePath $MediaPlayer -ArgumentList $MediaPlayerArguments -NoNewWindow -PassThru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment