Skip to content

Instantly share code, notes, and snippets.

@jeremyrsellars
Created January 12, 2023 05:15
Show Gist options
  • Save jeremyrsellars/93a4db07098348c55eec6108a6028883 to your computer and use it in GitHub Desktop.
Save jeremyrsellars/93a4db07098348c55eec6108a6028883 to your computer and use it in GitHub Desktop.
Clip YT audio
# Downloads the video and coverts to audio, then clips it from $start to $stop time and saves as $file
# The time formats must be "hh:mm:ss" and are relative to the beginning of the source video.
$youtubeUrl = "https://www.youtube.com/watch?v=T6SyM0Kw6GA"
$start = "00:00:36"
$stop = "00:04:55"
$file = "clip"
$youtube_id = [regex]::new("[^/=]+$").Match($youtubeUrl).Value
md $youtube_id -ErrorAction SilentlyContinue
cd $youtube_id
if(Test-Path "*$youtube_id.mp3") {
Echo "Already downloaded $youtube_id.mp3"
} else {
youtube-dl --extract-audio --audio-format mp3 --print-traffic --console-title --write-thumbnail $youtubeUrl
}
$whole = Get-ChildItem -Path "*$youtube_id.mp3" -Force -Recurse -File | Select-Object -First 1
del "$file.mp3" -ErrorAction SilentlyContinue
ffmpeg -i $whole -ss $start -to $stop "$file.mp3"
dir "$file.mp3"
popd
# Requires Homebrew
brew install ffmpeg
brew install youtube-dl
# Requires chocolatey package manager https://chocolatey.org/install
choco install ffmpeg
choco install youtube-dl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment