Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force
Install-Module Microsoft.PowerShell.ConsoleGuiTools 
Import-Module Microsoft.PowerShell.ConsoleGuiTools 

Add-Type -Path ".\selenium.webdriver.4.0.0-alpha05\lib\netstandard2.0\WebDriver.dll"

$pathWebDriver = ".\WebDriver"
$edgeOptions  = New-Object  OpenQA.Selenium.Edge.EdgeOptions
$edgeOptions.UseChromium = $true
$edgeOptions.AddArgument("headless","log-level=3") 
$edgeOptions.AddArgument()
$edgeMarionete = New-Object OpenQA.Selenium.Edge.EdgeDriver($pathWebDriver,$edgeOptions)

$edgeMarionete.Navigate().GoToUrl("https://devshow.com.br/ultimos-episodios/")
[array]$epObjList =@()
$episodesList = $edgeMarionete.FindElementsByClassName("episodes-listing")
$qtdEpisodios = $episodesList.FindElementsByTagName("article")
for ($i = 1; $i -le $qtdEpisodios.Count; $i++) {
    $header = $edgeMarionete.FindElementsByXPath("//div/article[$i]/div/div/header/h2/a")
    $description = $edgeMarionete.FindElementsByXPath("//div/article[$i]/div/div/div[2]/p")
    $uriDownload = $edgeMarionete.FindElementsByXPath("//div/article[$i]/div/div/div[1]/div/div/div/div[3]/div[6]/a")
    $epObj = [PSCustomObject]@{
      header=$header.Text
      description =$description.Text
      uriDownload= $uriDownload.GetProperty("href")
    }
    $epObjList+=$epObj 
}
$edgeMarionete.close()

$epObjList.uriDownload | Out-ConsoleGridView -PassThru | Out-File .\wishlist.txt

[array]$filenameUgly = (Get-Content .\wishlist.txt) | ForEach-Object {($_ -split "/").Item(7)}

[array]$filenameBeauty = @()
for ($i = 0; $i -lt $filenameUgly.Count; $i++) {
  $filenameBeauty += ($filenameUgly.Item($i)).substring(0, $filenameUgly.Item($i).IndexOf('?'))    
}

if(!(Test-Path .\_devshowpodcast)){
New-Item -Name _devshowpodcast -ItemType Directory
}
$uriWishList = (Get-Content .\wishlist.txt)
for ($i = 0; $i -lt $filenameBeauty.Count; $i++) {
    Write-Host "Download ep" $filenameBeauty.item($i)
    $outfile =  ".\_devshowpodcast\{0}" -f $filenameBeauty.Item($i)
    Invoke-WebRequest -uri $uriWishList.item($i) -OutFile $outfile  -DisableKeepAlive 
}
# para efeito de teste implementei o foreach-object parallel, teste e observe a velocidade com que os downloads serão feitos.
if ((-join $PSVersionTable.psversion) -ge  "7.0.0"){
$uriWishList | ForEach-Object  -ThrottleLimit 4 -Parallel { 
  $uriResult = ($_ -split "/").Item(7)
  $resultEpname = $uriResult.substring(0,  $uriResult.IndexOf('?'))
  $outfile =  ".\_devshowpodcast\{0}"  -f $resultEpname 
  Invoke-WebRequest -uri $_ -OutFile $outfile -DisableKeepAlive 
 } } else {throw "Você precisa ter instalado o powershell core https://aka.ms/pscore6"}