Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto download MediaInfo using PowerShell #832

Open
Obegg opened this issue May 7, 2024 · 2 comments
Open

Auto download MediaInfo using PowerShell #832

Obegg opened this issue May 7, 2024 · 2 comments

Comments

@Obegg
Copy link

Obegg commented May 7, 2024

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'
@g-maxime
Copy link
Contributor

g-maxime commented May 7, 2024

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.

@Obegg
Copy link
Author

Obegg commented May 7, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants