DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
72 stars 16 forks source link

[Broken] JabraDirect #22

Closed o-l-a-v closed 2 years ago

o-l-a-v commented 2 years ago

Seems the logic for Jabra Direct is borked. Not a issue for me, just a heads up. :)

PS C:\Windows\system32> Nevergreen\Get-NevergreenApp -Name 'JabraDirect'
WARNING: No version found within 
--- a lot of HTML ---
Nevergreen\Get-NevergreenApp : Error retriving results for 'JabraDirect': Get-JabraDirect.ps1: Cannot validate argument on parameter 'Version'. The argument is null or empty. Provide an argument that is not null or 
empty, and then try the command again.
At line:1 char:1
+ Nevergreen\Get-NevergreenApp -Name 'JabraDirect'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-NevergreenApp

PS C:\Windows\system32> 

And version of the module

PS C:\Windows\system32> Get-Module -Name 'Nevergreen'

ModuleType Version    Name                                ExportedCommands                                                                                                                                               
---------- -------    ----                                ----------------                                                                                                                                               
Script     2109.1     Nevergreen                          {Find-NevergreenApp, Get-NevergreenApp}                                                                                                                        

PS C:\Windows\system32> 
o-l-a-v commented 2 years ago

Jabra webpage returns webpage in native language if available, that might be the cause of it.

Here is some (for now) working PowerShell to get latest available version.

[System.Version](
    (
        Invoke-RestMethod -Method 'Get' -Uri 'https://www.jabra.com/Support/release-notes/release-note-jabra-direct'
    ).Split(
        [System.Environment]::NewLine,
        [System.StringSplitOptions]::RemoveEmptyEntries
    ).Where{
        -not [string]::IsNullOrEmpty($_)
    }.ForEach{
        $_.Trim() -replace '\s{2,}', ' '
    }.Where{
        $_ -like '*?.?.?*<br>*'
    }[0].Split(
        ' ',
        [System.StringSplitOptions]::RemoveEmptyEntries
    ).ForEach{
        $_.Replace('<br>','')
    }.Where{
        $_ -like '?.?.?*'
    }[0]
)

I tried to look for some headers or URL parameters to request English language, but did not find anything in my short research here.

DanGough commented 2 years ago

Thanks for the report, could you please confirm if it's still an issue? It's working for me at the moment with an English OS, I will investigate!

o-l-a-v commented 2 years ago

@DanGough

Yup, still a problem. English OS. en-SE culture (Get-Culture, LCID = 8192).

DanGough commented 2 years ago

Hi, would you be able to try the version I've just uploaded to Dev at all?

I got an error if I tried switching it from .co.uk to .com, unless I set the user agent to GoogleBot, so I've now tweaked the internal function Get-Version to support a UserAgent parameter. I've used this and also switched the URL to use .com, and changed the match parameter to find the first version number followed by <br>, so that it works independent of language.

o-l-a-v commented 2 years ago

It worked. :)

Test script:

#Requires -Version 5.1
<#
    .SYNOPSIS
        Test dev branch of Nevergreen by first downloading it to desktop and unzip it.

    .NOTES
        Author:   Olav Rønnestad Birkeland
        Created:  211015
        Modified: 211015

    .EXAMPLE
        & $psISE.CurrentFile.FullPath -Name 'JabraDirect'
#>

# Input parameters
[OutputType($null)]
Param(
    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $Name
)

# PowerShell preferences
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'

# Import dev module
## Introduce step
Write-Information -MessageData '# Import module'

## Create expected module path
$ModulePath = [string] '{0}\Nevergreen-dev\Nevergreen\Nevergreen.psm1' -f [System.Environment]::GetFolderPath('Desktop')

## Chech that it exists
if (-not [System.IO.File]) {
    Throw ('Did not find module at "{0}".' -f $ModulePath)
}

## Remove if imported from different path
if ($(Try{(Get-Module -Name 'Nevergreen').'Path' -ne $ModulePath}Catch{$false})) {
    $null = Remove-Module -Name 'Nevergreen' -Force
}

## Import if needed
if ($(Try{(Get-Module -Name 'Nevergreen').'Path' -eq $ModulePath}Catch{$false})) {
    Write-Information -MessageData 'Module already imported.'
}
else {    
    Write-Information -MessageData 'Module not already imported.'
    $null = Import-Module -Name $ModulePath -Force
}

## View module and version
Get-Module -Name 'Nevergreen' | Format-List

# Test getting version of Jabra Direct
## Introduce step
Write-Information -MessageData ('{0}# Try get version of "{1}"' -f [System.Environment]::NewLine, $Name)

## Get version
Get-NevergreenApp -Name $Name

Output

PS C:\Users\birola>         & $psISE.CurrentFile.FullPath -Name 'JabraDirect'
# Import module
Module already imported.

Name              : Nevergreen
Path              : C:\Users\birola\OneDrive - <removed>\Skrivebord\Nevergreen-dev\Nevergreen\Nevergreen.psm1
Description       : 
ModuleType        : Script
Version           : 0.0
NestedModules     : {}
ExportedFunctions : {Find-NevergreenApp, Get-NevergreenApp}
ExportedCmdlets   : 
ExportedVariables : 
ExportedAliases   : 

# Try get version of "JabraDirect"

Name         : Jabra Direct
Architecture : Multi
Type         : Exe
Version      : 5.8.49513
Uri          : https://jabraxpressonlineprdstor.blob.core.windows.net/jdo/JabraDirectSetup.exe

PS C:\Users\birola>