Skip to content

Instantly share code, notes, and snippets.

@reisir
Last active February 19, 2023 23:57
Show Gist options
  • Save reisir/141507e4b833ca905ad6fd020f8700b0 to your computer and use it in GitHub Desktop.
Save reisir/141507e4b833ca905ad6fd020f8700b0 to your computer and use it in GitHub Desktop.
Video editing essentials
$isWinget = [bool] (Get-Command -ErrorAction Ignore -Type Application winget)
$isChoco = [bool] (Get-Command -ErrorAction Ignore -Type Application choco)
$is7z = [bool] (Get-Command -ErrorAction Ignore -Type Application 7z)
# Check if 7z is already installed in C:\ProgramFiles
$packages = @(@{
"Name" = "MediaInfo"
"Description" = "provides extensive information about media files"
"choco" = "mediainfo"
"winget" = "MediaArea.MediaInfo.GUI"
"manual" = "https://mediaarea.net/en/MediaInfo"
}, @{
"Name" = "MPV"
"Description" = "a lightweight media player"
"choco" = "mpv"
"winget" = "9P3JFR0CLLL6"
"manual" = "https://sourceforge.net/projects/mpv-player-windows/files/"
}, @{
"Name" = "VLC"
"Description" = "a feature rich media player"
"choco" = "vlc"
"winget" = "VideoLAN.VLC"
"manual" = "https://www.videolan.org/vlc/download-windows.html"
}, @{
"Name" = "utVideo"
"Description" = "a lossless video codec"
"choco" = "utvideo"
"winget" = "UMEZAWATakeshi.UtvideoCodecSuite"
"manual" = "https://github.com/umezawatakeshi/utvideo/releases/latest/"
}, @{
"Name" = "ffmpeg"
"Description" = "a command line media tool"
"choco" = "ffmpeg"
"winget" = "Gyan.FFmpeg"
"manual" = "https://www.gyan.dev/ffmpeg/builds/"
}, @{
"Name" = "MKVtoolnix"
"Description" = "matroska (.mkv) tools"
"choco" = "mkvtoolnix"
"winget" = "MoritzBunkus.MKVToolNix"
"manual" = "https://www.fosshub.com/MKVToolNix.html"
})
$amvtool = @{
"Name" = "AMVtool"
"Description" = "easy to use re-encoding and re-containing program"
"github" = "https://github.com/l33tmeatwad/AMVtool/releases/latest/"
"manual" = "https://www.videolan.org/vlc/download-windows.html"
}
$7z = @{
"Name" = "7zip"
"Description" = "zip utility"
"choco" = "7zip"
"winget" = "7zip.7zip"
}
function Main {
Admin-Shell
Write-Host "`namv.tools Essentials v1.0" -ForegroundColor Blue
$skipConfirmation = Yes-No "`nCan the script install all packages without confirmation?"
$packageManager = Which-PackageManager
$packages | ForEach-Object {
Install-Package $_
}
AMVtool
Summary
Write-Host "`nPress any key to quit" -ForegroundColor Blue
Read-Host
}
function Install-Package {
param (
[Parameter()]
[hashtable]
$package
)
Write-Host "`n$($package.Name)" -ForegroundColor Blue
Write-Host "$($package.Description)`n"
if ($skipConfirmation) {
$install = $true
}
else {
$install = Yes-No "Do you want to install $($package.Name)?"
}
if ($install) {
switch ($packageManager) {
"choco" {
choco install $package.choco --yes
}
"winget" {
winget install $package.winget
}
Default { }
}
}
}
function Summary {
if (($packageManager -eq "choco") -and (-not($isChoco))) {
Write-Host "Chocolatey was installed" -ForegroundColor Blue
if (Yes-No "would you like to see instructions on how to use chocolatey?") {
Start-Process "https://docs.chocolatey.org/en-us/getting-started#using-chocolatey"
}
}
}
function AMVtool {
Write-Host "`n$($amvtool.Name)" -ForegroundColor Blue
Write-Host "$($amvtool.Description)`n"
if (-not( $skipConfirmation )) {
$installAMVtool = Yes-No "Do you want to install $($amvtool.Name)?"
if (-not($installAMVtool)) { return }
}
# Ensure amvtool directory exists
$amvtoolDirectory = "$([Environment]::GetFolderPath("MyDocuments"))\AMVtool"
$amvtoolDirectoryExists = Test-Path $amvtoolDirectory -InformationAction Ignore
if (-not ($amvtoolDirectoryExists)) { New-Item -Path $amvtoolDirectory -ItemType Directory }
# Get latest release assets from GitHub API
Write-Host "`nGetting latest $($amvtool.Name) release from l33tmeatwad/AMVtool"
$releaseURL = "https://api.github.com/repos/l33tmeatwad/AMVtool/releases/latest"
$releaseResponse = Invoke-WebRequest -UseBasicParsing $releaseURL | ConvertFrom-Json
$assetsURL = $releaseResponse.assets_url
$assetsResponse = Invoke-WebRequest -UseBasicParsing $assetsURL | ConvertFrom-Json
# Find the WINx64.7z archive
$assetName = ""
$downloadUrl = "WINx64 not found"
foreach ($asset in $assetsResponse) {
if ($asset.name -match '(?i)winx?64') {
$assetName = $asset.name
$downloadUrl = $asset.browser_download_url
break
}
}
if (-not ($assetName)) {
Write-Host "AMVtool release not found" -ForegroundColor Red
return
}
Write-Host "Found " -NoNewline
Write-Host "$assetName" -ForegroundColor Green
$assetPath = "$($amvtoolDirectory)\$assetName"
Write-Host "`nDownloading $($downloadUrl)"
Write-Host "Saved as " -NoNewline
Write-Host "$assetPath" -ForegroundColor Green
Invoke-WebRequest -Uri $downloadUrl -OutFile $assetPath
Write-Host "`nExtracting $assetName archive" -ForegroundColor Green
# Ensure 7z is installed
$7zPath = 7zInstalled
if ((-not($7zPath)) -and (-not($is7z))) {
Write-Host "`n7zip is required to extract $assetName archive" -ForegroundColor Yellow
Install-Package $7z
$7zPath = 7zInstalled
}
if (-not($7zPath)) {
Write-Host "Cannot extract $assetPath without 7-zip" -ForegroundColor Red
return
}
# Extract the amvtool .7z archive
Set-Location -Path $amvtoolDirectory
$7zCommand = "& `"$7zPath`" x `"$assetName`" -y"
$output = Invoke-Expression $7zCommand
Remove-Item -Path $assetName
Write-Host "`n$($amvtool.Name) installed at $($amvtoolDirectory)"
Write-Host "`nDownloading Microsoft Visual C++ 2015-2019 Redistributable Package"
Invoke-WebRequest "https://download.visualstudio.microsoft.com/download/pr/b929b7fe-5c89-4553-9abe-6324631dcc3a/296F96CD102250636BCD23AB6E6CF70935337B1BBB3507FE8521D8D9CFAA932F/VC_redist.x64.exe" -OutFile "VCRedist_x64.exe"
Write-Host "`nInstalling Microsoft Visual C++ 2015-2019 Redistributable Package"
Start-Process .\VCRedist_x64.exe -ArgumentList "/Q"
Set-Location -Path $PSScriptRoot
if ($skipConfirmation) {
$amvtoolIcon = $true
}
else {
$amvtoolIcon = Yes-No "Would you like to create a desktop icon for $($amvtool.Name)"
}
if ($amvtoolIcon) {
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\AMVtool.lnk")
$Shortcut.TargetPath = "$amvtoolDirectory\AMVtool64\AMVtool.exe"
$Shortcut.Save()
Write-Host "$($amvtool.Name) shortcut created!"
}
}
function Which-PackageManager {
Write-Host "`nPackage manager" -ForegroundColor Blue
if ($isChoco) {
$useChoco = Yes-No "Do you want to use chocolatey to install packages?"
if ($useChoco) { return "choco" }
}
if ($isWinget) {
$useWinget = Yes-No "Do you want to use winget to install packages?"
if ($useWinget) { return "winget" }
}
if (-not($isChoco)) {
if ($skipConfirmation) {
$installChoco = $true
}
else {
$installChoco = Yes-No "Do you want to install chocolatey to install packages?"
}
if ($installChoco) {
Install-Chocolatey
return "choco"
}
}
Write-Host "`nNo package manager selected. Cannot install packages" -ForegroundColor Red
Read-Host "Press any key to quit"
Exit
}
function Install-Chocolatey {
if (-not($isChoco)) {
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Write-Output "`nChocolatey installed`n" -ForegroundColor Green
}
else {
Write-Output "Chocolatey $isChoco is already installed, skipping install"
}
}
function Yes-No {
[CmdletBinding()]
param (
[Parameter(Position = 0)]
[string]
$Question
)
$confirmation = Read-Host "$Question [Y\n]"
if ($confirmation -eq 'y' -or $confirmation -eq '') { return $true } else { return $false }
}
function Admin-Shell {
# If not run in an administrator shell
if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
$iexSelf = "Set-ExecutionPolicy Bypass -Scope CurrentUser -Force ; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 ; Invoke-Expression (Invoke-WebRequest -UseBasicParsing https://gist.githubusercontent.com/reisir/141507e4b833ca905ad6fd020f8700b0/raw/)"
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList "-Command $iexSelf"
Exit
}
}
function 7zInstalled {
$7zPath = Get-ItemProperty -Path 'HKLM:\SOFTWARE\7-Zip\' -ErrorAction Ignore | Select Path
if ($7zPath -eq $null) { return $false }
return "$($7zPath.Path)7z.exe"
}
Main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment