Auto download MediaInfo using PowerShell
Obegg opened this issue · 4 comments
Since this repo doesn't have discussions, I had to open an issue, sorry about that.
I'm trying to create a powershell script that will auto download MediaInfo.
(Yes, I know this is a bit unrelated to this repo, but what else should I do?)
Basically I did the following:
Write-Host 'Mediainfo > Get latest' -ForegroundColor green -BackgroundColor black
$LastestMediaInfoVersion = 'https://mediaarea.net/download/binary/mediainfo-gui/' + (Invoke-WebRequest -UseBasicParsing 'https://api.github.com/repos/MediaArea/MediaInfo/releases/latest' | ConvertFrom-Json | Select-Object -ExpandProperty name) + '/MediaInfo_GUI_' + (Invoke-WebRequest -UseBasicParsing 'https://api.github.com/repos/MediaArea/MediaInfo/releases/latest' | ConvertFrom-Json | Select-Object -ExpandProperty name) + '_Windows.exe'
Write-Host 'Mediainfo > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile($LastestMediaInfoVersion, "$env:TEMP\MediaInfo.exe")
But it's not very "elegant" solution, I mean - it's working, but, that's not ideal.
If someone has suggestions or a better idea, please let me know.
(Please do not suggest using chocolatey)
I think this is the best:
Write-Host 'Mediainfo > Get latest' -ForegroundColor green -BackgroundColor black
$MediaInfoHREF = (Invoke-WebRequest -UseBasicParsing -Uri 'https://mediaarea.net/en/MediaInfo/Download/Windows' | Select-Object -ExpandProperty Links | Where-Object { ($_.outerHTML -match 'GUI') } | Select-Object -First 1 | Select-Object -ExpandProperty href)
$MediaInfoDL = 'https:' + $MediaInfoHREF
Write-Host 'Mediainfo > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile($MediaInfoDL, "$env:TEMP\MediaInfo.exe")
Write-Host 'Mediainfo > Install' -ForegroundColor green -BackgroundColor black
Start-Process -FilePath $env:TEMP\MediaInfo.exe -Args '/S'
1: Retrieve the version number
2: Download the file
Your script is correct.
You can use a variable to avoid two identical web requests:
$LastestMediaInfoVersion = Invoke-WebRequest -UseBasicParsing 'https://api.github.com/repos/MediaArea/MediaInfo/releases/latest' | ConvertFrom-Json | Select-Object -ExpandProperty name
$LastestMediaInfoURL = "https://mediaarea.net/download/binary/mediainfo-gui/${LastestMediaInfoVersion}/MediaInfo_GUI_${LastestMediaInfoVersion}_Windows.exe"
Write-Host 'Mediainfo > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile($LastestMediaInfoURL, "$env:TEMP\MediaInfo.exe")
You can also read the version from the version.txt file if you don't want to parse the JSON:
$LastestMediaInfoVersion = (Invoke-WebRequest -UseBasicParsing 'https://raw.githubusercontent.com/MediaArea/MediaInfo/master/Project/version.txt').Content.Trim()
$LastestMediaInfoURL = "https://mediaarea.net/download/binary/mediainfo-gui/${LastestMediaInfoVersion}/MediaInfo_GUI_${LastestMediaInfoVersion}_Windows.exe"
Write-Host 'Mediainfo > Download' -ForegroundColor green -BackgroundColor black
(New-Object System.Net.WebClient).DownloadFile($LastestMediaInfoURL, "$env:TEMP\MediaInfo.exe")
On our side, we can add a URL to download the latest binary, e.g.: binary/mediainfo-gui/latest/MediaInfo_GUI_latest_Windows.exe
.
However, this also have drawbacks. Since the version number doesn't appear in the URL, you still have to retrieve it one way or another, for example, to check if the version is newer than the installed one.
Thank you for taking the time to reply about this.
I don't think it's a good idea to retrieve the version number at all, I moved to different approach which includes going to the official website instead of GitHub and selecting the correct version from there (I edited first post).
Why don't use chocolatey?
https://community.chocolatey.org/packages?q=mediainfo
Why don't use chocolatey? https://community.chocolatey.org/packages?q=mediainfo
I don't want package managers like winget or chocolatey.