Hi there, thought i share my script to quick and easy check/install latest Plex HTPC and also mpv-2.dll from mitzsch witch fixes support for TrueHD.
###Do not use if you aren’t using mpv-2.dll as mediaplayer for Plex HTPC!###
Its Powershell (works with 5.1 and 7.x) so just run it as admin, might need to check the path to your Plex HTPC install but i use standard so that’s what i set in the script. I use Nanazip to extract 7z archive if needed and the script will check and /or install that if its missing. Do edit the script if that’s not what you are fine with
###As always, do not run script from the internet if you don’t have the know-how to safely assess if its okay or not!###
This is my current output from the script when executed:
Starting update check for Plex HTPC and MPV…
NanaZip is already installed.
Plex HTPC is up-to-date.
Current Plex HTPC version: 1.65.3.199 same as latest online version: 1.65.3.199
No Plex HTPC update required.
Current MPV version date (from DLL): 2024-07-28
Latest online MPV version: 2024-07-28-6107112
MPV is up-to-date.
No MPV update required.
Update process completed.
Here is the full script, let me know if there are any issues but if you have set $localInstallPath to the correct path i cannot see what might go wrong. Do prove me wrong if so! Will obviously only work on Windows. Laters
#####################################################################
function Get-PlexHTPCFileVersion {
param (
[string]$LatestOnlineVersion
)
$plexPath = Join-Path -Path $localInstallPath -ChildPath 'Plex HTPC.exe'
if (Test-Path $plexPath) {
try {
$content = [System.IO.File]::ReadAllBytes($plexPath)
$text = [System.Text.Encoding]::ASCII.GetString($content)
$cleanText = $text -replace "`0", " "
$versionPattern = "Plex HTPC\s+(\d+\.\d+\.\d+\.\d+)-[a-f0-9]+"
if ($cleanText -match $versionPattern) {
$foundVersion = $matches[1]
$updateNeeded = $foundVersion -ne $LatestOnlineVersion
return [PSCustomObject]@{
UpdateNeeded = $updateNeeded
LocalVersion = $foundVersion
}
}
else {
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
catch {
Write-Host "An error occurred while processing the file: $_"
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
else {
Write-Host "Plex HTPC executable not found at the specified path."
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
function Check-PlexHTPCUpdate {
$plexExePath = Join-Path $localInstallPath -ChildPath 'Plex HTPC.exe'
if (-not (Test-Path $plexExePath)) {
Write-Host "Plex HTPC not installed. Install manually."
return $null
}
$json = Invoke-RestMethod -Uri "https://plex.tv/api/downloads/7.json"
$download = $json.computer.Windows.releases.url
if (-not $download) {
Write-Host "Error fetching data from plex.tv"
return $null
}
$downloadVersion = $json.computer.Windows.version -replace '-.*$'
$localVersion = Get-PlexHTPCFileVersion -LatestOnlineVersion $downloadVersion
if ($localVersion.UpdateNeeded -eq $false) {
Write-Host "Plex HTPC is up-to-date."
Write-Host "Current Plex HTPC version: $($localVersion.LocalVersion) same as latest online version: $downloadVersion"
return $null
}
else {
Write-Host "Plex HTPC is NOT up-to-date."
Write-Host "Current Plex HTPC version: $($localVersion.LocalVersion) is NOT same as latest online version: $downloadVersion"
return @{
Download = $download
Version = $downloadVersion
}
}
}
function Get-MPVDLLDate {
$mpvDllPath = Join-Path $localInstallPath "mpv-2.dll"
if (Test-Path $mpvDllPath) {
return (Get-Item $mpvDllPath).LastWriteTime.ToString("yyyy-MM-dd")
}
else {
return $null
}
}
function Check-MPVUpdate {
$mpvRelease = Invoke-RestMethod -Uri "https://api.github.com/repos/mitzsch/mpv-winbuild/releases/latest"
$latestVersion = $mpvRelease.tag_name
$latestDate = $latestVersion.Substring(0, 10) # Extract date from version string
$localDate = Get-MPVDLLDate
if ($localDate) {
Write-Host "Current MPV version date (from DLL): $localDate"
}
else {
Write-Host "MPV DLL not found. Assuming update is needed."
$localDate = "0000-00-00"
}
Write-Host "Latest online MPV version: $latestVersion"
if ($latestDate -le $localDate) {
Write-Host "MPV is up-to-date."
return $null
}
Write-Host "New MPV version available: $latestVersion"
$mpvDownloadUrl = ($mpvRelease.assets | Where-Object name -Like "mpv-dev-x86_64-v3-*").browser_download_url
return @{
Download = $mpvDownloadUrl
Version = $latestVersion
}
}
function Update-PlexHTPC {
param (
[Parameter(Mandatory = $true)]
[string]$Download,
[Parameter(Mandatory = $true)]
[string]$Version
)
try {
Write-Host "Starting Plex HTPC update process..."
New-Item -Path $tempPath -ItemType Directory -Force | Out-Null
$plexFilename = Split-Path $Download -Leaf
Write-Host "Downloading Plex HTPC update: $plexFilename"
Invoke-WebRequest -Uri $Download -OutFile (Join-Path $tempPath $plexFilename)
Write-Host "Extracting Plex HTPC update..."
& $zipTool x (Join-Path $tempPath $plexFilename) ("-o" + (Join-Path $tempPath "app\")) -y
$plexProcess = Get-Process "Plex HTPC" -ErrorAction SilentlyContinue
if ($plexProcess) {
Write-Host "Stopping Plex HTPC process..."
$plexProcess | Stop-Process -Force
}
Write-Host "Copying updated Plex HTPC files..."
Copy-Item -Path (Join-Path $tempPath "app\*") -Destination $localInstallPath -Recurse -Exclude '$PLUGINSDIR', '$TEMP', "*.nsi", "*.nsis" -Force
if ($plexProcess) {
Write-Host "Restarting Plex HTPC..."
Start-Process -FilePath (Join-Path $localInstallPath "Plex HTPC.exe")
}
Write-Host "Plex HTPC update completed successfully! New version: $Version"
}
catch {
Write-Host "An error occurred during the Plex HTPC update process: $_"
}
finally {
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Update-MPV {
param (
[Parameter(Mandatory = $true)]
[string]$Download,
[Parameter(Mandatory = $true)]
[string]$Version
)
try {
Write-Host "Starting MPV update process..."
New-Item -Path $tempPath -ItemType Directory -Force | Out-Null
$mpvFilename = [System.IO.Path]::GetFileName($Download)
Write-Host "Downloading MPV update: $mpvFilename"
Invoke-WebRequest -Uri $Download -OutFile (Join-Path $tempPath $mpvFilename)
Write-Host "Extracting MPV update..."
& $zipTool x (Join-Path $tempPath $mpvFilename) ("-o" + (Join-Path $tempPath "lib\")) -y
$plexProcess = Get-Process "Plex HTPC" -ErrorAction SilentlyContinue
if ($plexProcess) {
Write-Host "Stopping Plex HTPC process..."
$plexProcess | Stop-Process -Force
}
Write-Host "Copying updated MPV files..."
Copy-Item -Path (Join-Path $tempPath "lib\mpv-2.dll") -Destination $localInstallPath -Force -Confirm:$false
if ($plexProcess) {
Write-Host "Restarting Plex HTPC..."
Start-Process -FilePath (Join-Path $localInstallPath "Plex HTPC.exe")
}
Write-Host "MPV update completed successfully! New version: $Version"
$updatedDate = Get-MPVDLLDate
if ($updatedDate -eq $Version.Substring(0, 10)) {
Write-Host "MPV update verified successfully."
}
else {
Write-Host "MPV update verification failed. Please check manually."
Write-Host "Expected date: $($Version.Substring(0, 10))"
Write-Host "Actual date: $updatedDate"
}
Remove-Item -Path (Join-Path $tempPath $mpvFilename) -Force -ErrorAction SilentlyContinue
}
catch {
Write-Host "An error occurred during the MPV update process: $_"
}
finally {
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Ensure-NanaZipInstalled {
$nanaZipInstalled = Get-AppxPackage | Where-Object { $_.Name -like "*NanaZip*" }
if ($nanaZipInstalled) {
Write-Host "NanaZip is already installed."
return $true
}
$wingetPath = Get-Command winget -ErrorAction SilentlyContinue
if (-not $wingetPath) {
Write-Host "Winget is not installed. Please install the Windows Package Manager (winget) to proceed."
return $false
}
Write-Host "Attempting to install NanaZip..."
try {
winget install -e --force --id M2Team.NanaZip --accept-package-agreements --accept-source-agreements
$nanaZipInstalled = Get-AppxPackage | Where-Object { $_.Name -like "*NanaZip*" }
if ($nanaZipInstalled) {
Write-Host "NanaZip has been successfully installed."
return $true
}
else {
Write-Host "NanaZip installation seems to have failed. Please check for any error messages above."
return $false
}
}
catch {
Write-Host "An error occurred while trying to install NanaZip: $_"
return $false
}
}
# Main script
Write-Host "Starting update check for Plex HTPC and MPV..."
# Global variables
$localInstallPath = "C:\Program Files\Plex\Plex HTPC\"
$tempPath = "$env:TEMP\plexhtpc\"
$zipTool = "nanazipc"
#Start update check
if (!(Ensure-NanaZipInstalled)) {
Write-Host "Failed to make sure nanazip is installed and usable. The script will not work without it."
Exit 1
}
$plexUpdateInfo = Check-PlexHTPCUpdate
if ($plexUpdateInfo) {
Write-Host "Updating Plex HTPC..."
Update-PlexHTPC -Download $plexUpdateInfo.Download -Version $plexUpdateInfo.Version
}
else {
Write-Host "No Plex HTPC update required."
}
$mpvUpdateInfo = Check-MPVUpdate
if ($mpvUpdateInfo) {
Write-Host "Updating MPV..."
Update-MPV -Download $mpvUpdateInfo.Download -Version $mpvUpdateInfo.Version
}
else {
Write-Host "No MPV update required."
}
Write-Host "Update process completed."
Glad you liked it I have refined the script today and added tons of extra error handling is something goes wrong. More helpful output of information during the script execute. Automatic backup of the current mpv-2.dll if a new version is found. Should be much more robust and will handle any errors that might occur gracefully and informative.
function Get-PlexHTPCFileVersion {
[CmdletBinding()]
param (
[string]$LatestOnlineVersion
)
$plexPath = Join-Path -Path $localInstallPath -ChildPath 'Plex HTPC.exe'
if (Test-Path $plexPath) {
try {
$content = [System.IO.File]::ReadAllBytes($plexPath)
$text = [System.Text.Encoding]::ASCII.GetString($content)
$cleanText = $text -replace "`0", " "
$versionPattern = "Plex HTPC\s+(\d+\.\d+\.\d+\.\d+)-[a-f0-9]+"
if ($cleanText -match $versionPattern) {
$foundVersion = $matches[1]
$updateNeeded = $foundVersion -ne $LatestOnlineVersion
return [PSCustomObject]@{
UpdateNeeded = $updateNeeded
LocalVersion = $foundVersion
}
}
else {
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
catch {
Write-Host "An error occurred while processing the file. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
else {
Write-Host "Plex HTPC executable not found at the specified path." -ForegroundColor Red
return [PSCustomObject]@{
UpdateNeeded = $true
LocalVersion = $null
}
}
}
function Check-PlexHTPCUpdate {
$plexExePath = Join-Path $localInstallPath -ChildPath 'Plex HTPC.exe'
if (-not (Test-Path $plexExePath)) {
Write-Host "Plex HTPC not installed. Install manually." -ForegroundColor Yellow
return $null
}
try {
$json = Invoke-RestMethod -Uri "https://plex.tv/api/downloads/7.json"
$download = $json.computer.Windows.releases.url
Write-Host "Successfully got data from plex.tv." -ForegroundColor Green
}
catch {
Write-Host "Could not fetching data from plex.tv. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return $null
}
$downloadVersion = $json.computer.Windows.version -replace '-.*$'
$localVersion = Get-PlexHTPCFileVersion -LatestOnlineVersion $downloadVersion
if ($localVersion.UpdateNeeded -eq $false) {
Write-Host "Plex HTPC is up-to-date." -ForegroundColor Green
Write-Host "Current Plex HTPC version:"`e[32m"[$($localVersion.LocalVersion)]"`e[0m" same as latest online version:"`e[32m"[$downloadVersion]"`e[0m""
return $null
}
else {
Write-Host "Plex HTPC is NOT up-to-date." -ForegroundColor Yellow
Write-Host "Current Plex HTPC version:"`e[32m"[$($localVersion.LocalVersion)]"`e[0m" is NOT same as latest online version:"`e[32m"[$downloadVersion]"`e[0m". Will update!"
return @{
Download = $download
Version = $downloadVersion
}
}
}
function Compare-MPVVersion {
[CmdletBinding()]
param (
[string]$Version
)
$versionPattern = '(?<minor>\d+)\.(?<patch>\d+)[_-](?<build>\d+)[_-](?<revision>\d+)'
if ($Version -match $versionPattern) {
$minor = $matches['minor']
$patch = $matches['patch']
$build = $matches['build']
$revision = $matches['revision']
$patch = if ($patch) {
$patch
}
else {
'0'
}
$build = if ($build) {
$build
}
else {
'0'
}
$revision = if ($revision) {
$revision
}
else {
'0'
}
$customVersionString = "$minor.$patch.$build.$revision"
return $customVersionString
}
if ($Version -match '-UNKNOWN') {
return ($version -split '-')[0]
}
return $null
}
function Get-MPVVersion {
[CmdletBinding()]
param (
[switch]$CompareVersion
)
try {
$mpvOnlineResponse = Invoke-RestMethod -Uri "https://api.github.com/repos/mitzsch/mpv-winbuild/releases/latest"
$mpvDownloadUrl = ($mpvOnlineResponse.assets | Where-Object name -Like "mpv-dev-x86_64-v3-*").browser_download_url
}
catch {
Write-Host "Could not get MPV version info from github. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return @{
NeedUpdate = $false
Version = $null
VersionDownloaded = $false
URL = $null
}
}
if ($CompareVersion.IsPresent) {
New-Item -Path $tempPath -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
try {
Invoke-WebRequest -Uri $mpvDownloadUrl -OutFile (Join-Path $tempPath ([System.IO.Path]::GetFileName($mpvDownloadUrl)))
Write-Host "Successfully downloaded the latest mpv client to compare against." -ForegroundColor Green
& $zipTool x (Join-Path $tempPath ([System.IO.Path]::GetFileName($mpvDownloadUrl))) ("-o" + (Join-Path $tempPath "lib\")) -y | Out-Null
Write-Host "Successfully extraced the mpv update..." -ForegroundColor Green
}
catch {
Write-Host "Something went wrong when downloading or extracting the latest mpv client. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return @{
NeedUpdate = $false
Version = $null
VersionDownloaded = $false
URL = $null
}
}
try {
$online = (Get-Item -Path "$tempPath\lib\mpv-2.dll").VersionInfo.FileVersion
$local = (Get-Item (Join-Path $localInstallPath "mpv-2.dll")).VersionInfo.FileVersion
[version]$localVersion = Compare-MPVVersion -Version $local
[version]$onlineVersion = Compare-MPVVersion -Version $online
if ($onlineVersion -and $localVersion -and $onlineVersion -gt $localVersion) {
return @{
NeedUpdate = $true
Version = $onlineVersion
VersionDownloaded = $true
URL = $mpvDownloadUrl
}
}
else {
return @{
NeedUpdate = $false
Version = $onlineVersion
VersionDownloaded = $true
URL = $mpvDownloadUrl
}
}
}
catch {
Write-Host "Could not compare versions mpv version. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return @{
NeedUpdate = $false
Version = $null
VersionDownloaded = $false
URL = $null
}
}
}
try {
[datetime]$localVersionDate = (Get-Item (Join-Path $localInstallPath "mpv-2.dll")).LastWriteTime.ToString("yyyy-MM-dd")
[datetime]$onlineVersionDate = ($mpvOnlineResponse.tag_name).Substring(0, 10)
if ($onlineversiondate -and $localVersionDate -and $onlineVersionDate -gt $localVersionDate) {
return @{
NeedUpdate = $true
Version = $onlineVersionDate
VersionDownloaded = $false
URL = $mpvDownloadUrl
}
}
else {
return @{
NeedUpdate = $false
Version = $null
VersionDownloaded = $false
URL = $mpvDownloadUrl
}
}
}
catch {
Write-Host "Could not compare versions mpv version. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return @{
NeedUpdate = $false
Version = $null
VersionDownloaded = $false
URL = $null
}
}
}
function Check-MPVUpdate {
[CmdletBinding()]
param(
[switch]$CompareVersion,
[switch]$KeepCurrentVersion
)
if ($KeepCurrentVersion.IsPresent) {
Write-Host "Keeping current MPV version."
Write-Host "Current local mpv version is:"`e[32m"[$((Get-Item (Join-Path $localInstallPath "mpv-2.dll")).VersionInfo.FileVersion)]"`e[0m""
return
}
$needUpdate = if ($CompareVersion.IsPresent) {
Get-MPVVersion -CompareVersion
}
else {
Get-MPVVersion
}
if ($needUpdate.NeedUpdate -eq $true -and $needUpdate.URL ) {
Write-Host "New MPV version available:"`e[32m"[$($needUpdate.Version)]"`e[0m""
return @{
Download = $needUpdate.URL
Version = $needUpdate.Version
VersionDownloaded = $needUpdate.VersionDownloaded
}
}
else {
Write-Host "Local mpv version"`e[32m"[$((Get-Item (Join-Path $localInstallPath "mpv-2.dll")).VersionInfo.FileVersion)]"`e[0m" is up to date."
}
if ((Get-Item (Join-Path $localInstallPath "mpv-2.dll")).Length -lt 50000000) {
Write-Host "You are using the original PlexHTPC mpv client."
}
else {
Write-Host "You are using a custom modified PlexHTPC mpv and not the standard PlexHTPC mpv client."
}
}
function Stop-RestartPlexHTPC {
[CmdletBinding()]
param(
[switch]$Restart
)
if ($Restart.IsPresent) {
Write-Host "Restarting Plex HTPC..."
try {
Start-Process -FilePath (Join-Path $localInstallPath "Plex HTPC.exe") -WindowStyle Hidden -ErrorAction Stop
Write-Host "Plex HTPC successfully restarted!" -ForegroundColor Green
}
catch {
Write-Host "Something went wrong when restarting Plex HTPC. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
}
return
}
$plexProcess = Get-Process "Plex HTPC" -ErrorAction SilentlyContinue
if ($plexProcess) {
Write-Host "Stopping Plex HTPC process..."
try {
$plexProcess | Stop-Process -Force -Confirm:$false -ErrorAction Stop
Write-Host "Successfully stopped Plex HTPC before the update." -ForegroundColor Green
}
catch {
Write-Host "Something went wrong when stopping Plex HTPC. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
}
}
else {
Write-Host "Plex HTPC is not running. Nothing to stop." -ForegroundColor Yellow
}
}
function Update-PlexHTPC {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$Download,
[Parameter(Mandatory = $true)][string]$Version
)
try {
Write-Host "Starting Plex HTPC update process..."
New-Item -Path $tempPath -ItemType Directory -Force | Out-Null
$plexFilename = Split-Path $Download -Leaf
Write-Host "Downloading Plex HTPC update: $plexFilename"
try {
Invoke-WebRequest -Uri $Download -OutFile (Join-Path $tempPath $plexFilename)
Write-Host "Successfully downloaded the new Plex HTPC client." -ForegroundColor Green
& $zipTool x (Join-Path $tempPath $plexFilename) ("-o" + (Join-Path $tempPath "app\")) -y | Out-Null
Write-Host "Successfully extraced the Plex HTPC update..." -ForegroundColor Green
}
catch {
Write-Host "Something went wrong when downloading or extracting the new Plex HTPC client. Will abort the update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return
}
Stop-RestartPlexHTPC
Write-Host "Copying updated Plex HTPC files..."
try {
Copy-Item -Path (Join-Path $tempPath "app\*") -Destination $localInstallPath -Recurse -Exclude '$PLUGINSDIR', '$TEMP', "*.nsi", "*.nsis" -Force -ErrorAction Stop
Write-Host "Plex HTPC update completed successfully! New version:"`e[32m"[$Version]"`e[0m""
}
catch {
Write-Host "Something went wrong during Plex HTPC update. Will abort the update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return
}
Stop-RestartPlexHTPC -Restart
Write-Host "Plex HTPC update completed successfully! New version:"`e[32m"[$Version]"`e[0m""
}
catch {
Write-Host "An error occurred during the Plex HTPC update process:"`e[31m"$($_.Exception.Message)"`e[0m""
}
finally {
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Update-MPV {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)][string]$Download,
[Parameter(Mandatory = $true)][string]$Version,
[switch]$VersionDownloaded,
[switch]$Force
)
try {
if ($VersionDownloaded.IsPresent) {
try {
Write-Host "Starting MPV update process... Latest version is already downloaded. Copying new mpv-2.dll to $localInstallPath..."
Copy-Item -Path (Join-Path $tempPath "lib\mpv-2.dll") -Destination $localInstallPath -Force -Recurse -Confirm:$false -ErrorAction Stop | Out-Null
Write-Host "MPV update completed successfully! New version:"`e[32m"[$Version]"`e[0m""
}
catch {
Write-Host "Something went wrong during MPV update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
}
return
}
Write-Host "Starting MPV update process..."
New-Item -Path $tempPath -ItemType Directory -Force | Out-Null
$mpvFilename = [System.IO.Path]::GetFileName($Download)
Write-Host "Downloading MPV update: $mpvFilename"
try {
Invoke-WebRequest -Uri $Download -OutFile (Join-Path $tempPath $mpvFilename)
Write-Host "Successfully downloaded the new mpv client." -ForegroundColor Green
& $zipTool x (Join-Path $tempPath $mpvFilename) ("-o" + (Join-Path $tempPath "lib\")) -y | Out-Null
Write-Host "Successfully extraced the mpv update..." -ForegroundColor Green
}
catch {
Write-Host "Something went wrong when downloading or extracting the new mpv client. Will abort the update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return
}
Stop-RestartPlexHTPC
Write-Host "Copying updated MPV files..."
New-Item -Path $backupDir -Force -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
try {
Copy-Item -Path ("$localInstallPath" + "mpv-2.dll") -Destination $backupDir -Force -Confirm:$false -ErrorAction Stop | Out-Null
Write-Host "Successfully backed up the current mpv client to"`e[32m"[$backupDir\mpv-2.dll]"`e[0m"."
}
catch {
if($Force.IsPresent) {
Write-Host "Something went wrong when trying to backup the current mpv client. Will contune since -Force was specified. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
}
else {
Write-Host "Something went wrong when trying to backup the current mpv client. Will abort since -Force was not specified. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return
}
}
try {
Copy-Item -Path (Join-Path $tempPath "lib\mpv-2.dll") -Destination $localInstallPath -Force -Recurse -Confirm:$false -ErrorAction Stop | Out-Null
Write-Host "MPV update completed successfully! New version:"`e[32m"[$Version]"`e[0m""
}
catch {
Write-Host "Something went wrong during MPV update. Will abort the update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return
}
Stop-RestartPlexHTPC -Restart
Remove-Item -Path (Join-Path $tempPath $mpvFilename) -Force -ErrorAction SilentlyContinue
}
catch {
Write-Host "An error occurred during the MPV update process. Will abort the update. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
}
finally {
Remove-Item $tempPath -Recurse -Force -ErrorAction SilentlyContinue
}
}
function Ensure-NanaZipInstalled {
$nanaZipInstalled = Get-AppxPackage | Where-Object { $_.Name -like "*NanaZip*" }
if ($nanaZipInstalled) {
Write-Host "NanaZip version"`e[32m"[$($nanaZipInstalled.Version)]"`e[0m" is already installed."
return $true
}
$wingetPath = Get-Command winget -ErrorAction SilentlyContinue
if (-not $wingetPath) {
Write-Host "Winget is not installed. Please install the Windows Package Manager (winget) to proceed." -ForegroundColor Red
return $false
}
Write-Host "Attempting to install NanaZip..."
try {
Start-Process -FilePath $wingetPath.Source -ArgumentList "install -e --force --id M2Team.NanaZip --accept-package-agreements --accept-source-agreements --silent" -Wait -NoNewWindow
$nanaZipInstalled = Get-AppxPackage | Where-Object { $_.Name -like "*NanaZip*" }
if ($nanaZipInstalled) {
Write-Host "NanaZip version"`e[32m"[$($nanaZipInstalled.Version)]"`e[0m" has been successfully installed."
return $true
}
else {
Write-Host "NanaZip installation seems to have failed. Please check for any error messages above." -ForegroundColor Red
return $false
}
}
catch {
Write-Host "An error occurred while trying to install NanaZip. Error:"`e[31m"$($_.Exception.Message)"`e[0m""
return $false
}
}
# Main script
Write-Host "Starting update check for Plex HTPC and MPV..."
# Global variables
$localInstallPath = "C:\Program Files\Plex\Plex HTPC\"
$backupDir = "$localInstallPath" + "Backup"
$tempPath = "$env:TEMP\plexhtpc\"
$zipTool = "nanazipc"
#Start update check
if (!(Ensure-NanaZipInstalled)) {
Write-Host "Failed to make sure nanazip is installed and usable. The script will not work without it."
Exit 1
}
$plexUpdateInfo = Check-PlexHTPCUpdate
if ($plexUpdateInfo) {
Write-Host "Updating Plex HTPC..."
Update-PlexHTPC -Download $plexUpdateInfo.Download -Version $plexUpdateInfo.Version
}
else {
Write-Host "No Plex HTPC update required."
}
$mpvUpdateInfo = Check-MPVUpdate -CompareVersion #With -CompareVersion it will download the latest mpv client and check the dll version to compare with. Without -CompareVersion it will just compare the date of the local dll with latest on Github.
if ($mpvUpdateInfo) {
Write-Host "Updating MPV..."
Update-MPV -Download $mpvUpdateInfo.Download -Version $mpvUpdateInfo.Version -VersionDownloaded:$mpvUpdateInfo.VersionDownloaded -Force #-Force is used to ignore if the script is unabled to backup the current mvp client.
}
else {
Write-Host "No MPV update required."
}
Write-Host "Update process completed."
I have tweaked it further so i feel its good enough to publish on Github
-Added custom logging like this:
[2024-08-22 21:51:41.925][SUCCESS] NanaZip version [3.1.1080.0] is already installed. [Function: Ensure-NanaZipInstalled]
[2024-08-22 21:51:43.332][SUCCESS] Successfully downloaded the latest mpv client to compare against. [Function: Get-MPVVersion]
[2024-08-22 21:51:44.130][SUCCESS] Successfully extraced the mpv update... [Function: Get-MPVVersion]
[2024-08-22 21:51:44.163][SUCCESS] Local mpv version: [v0.38.0_4-243-g718fd0d8] is up to date. [Function: Check-MPVUpdate]
[2024-08-22 21:51:44.164][INFO] You are using a custom modified PlexHTPC mpv and not the standard PlexHTPC mpv client. [Function: Check-MPVUpdate]
[2024-08-22 21:51:44.193][INFO] No MPV update required.
[2024-08-22 21:51:44.347][SUCCESS] Successfully got data from plex.tv. [Function: Check-PlexHTPCUpdate]
[2024-08-22 21:51:44.394][SUCCESS] Plex HTPC is up-to-date. [Function: Check-PlexHTPCUpdate]
[2024-08-22 21:51:44.395][SUCCESS] Current Plex HTPC version: [1.66.1.215] same as latest online version: [1.66.1.215] [Function: Check-PlexHTPCUpdate]
[2024-08-22 21:51:44.407][INFO] No Plex HTPC update required.
[2024-08-22 21:51:44.411][SUCCESS] Update process completed.
Fixed slow download speed on PS 5.1, its about 10 times faster.
I wonder if anyone knows of any simple tools to create a GUI executable to run powershell scripts? It would be super cool to have a light utility to call functions of this script and maybe even extended features like toggling between stock and mitzsch dll, toggling mpv.conf flags like RTX super resolution etc.