$windowLocTimer = New-Object System.Windows.Forms.Timer $windowLocTimer.Interval = 10 $windowLocTimer.Add_Tick({ if ($curr_process.MainWindowHandle -ne 0) { $windowLocTimer.Dispose() $proc_size = ((((Set-Window -Id $curr_process.Id -Passthru) -split "Size")[1] -split "=")[1] -split ";")[0] -split "," $nx = [math]::Max(0, ($win_loc.X + $win_size.Width / 2) - $proc_size[0] / 2) $ny = [math]::Max(0, ($win_loc.Y + $win_size.Height / 2) - $proc_size[1] / 2) Set-Window -Id $curr_process.Id -X $nx -Y $ny -Passthru } }) function record($image, $mic, $out, $window, $bg, $monitor) { if (-not (hasExtension($out))) { if ($image) { $out = "$out.$def_video_fmt" } else { $out = "$out.$def_audio_fmt" } } if (checkFileExists -filepath $out) { return $null } $audioStr = "" if ($mic) { $audioStr = "-f dshow -i audio=`"$mic`"" } $imageStr = "" if ($image -eq "screen") { $monStr = "" if (-not ($monitor -eq "Todos")) { $monSp = (($monitor -split "- ")[1] -split ", ") -split "=" $monStr = "-offset_x $($monSp[1]) -offset_y $($monSp[3]) -video_size $($monSp[5])x$($monSp[7])" } $imageStr = "-f gdigrab $monStr -i desktop -preset ultrafast -pix_fmt yuv420p" } elseif ($image -eq "window") { $imageStr = "-f gdigrab -draw_mouse 0 -i title=`"$window`" -preset ultrafast -pix_fmt yuv420p -vf `"scale=2*trunc(iw/2):2*trunc(ih/2),setsar=1`"" } elseif ($image -eq "fixed") { $imageStr = "-loop 1 -i `"$bg`"" } $global:curr_process = Start-Process $ffmpeg -PassThru -ArgumentList "-hide_banner -y $audioStr $imageStr `"$out`"" $windowLocTimer.Start() return $curr_process } function capture($url, $out) { if (-not (hasExtension($out))) { $out = "$out.$def_video_fmt" } if (checkFileExists -filepath $out) { return $null } $global:curr_process = Start-Process $ffmpeg -PassThru -ArgumentList "-hide_banner -y -i `"$url`" -vcodec copy -acodec copy `"$out`"" $windowLocTimer.Start() return $curr_process } function speedmod($in, $out, $factor, $interpolate) { if (-not (hasExtension($out))) { $out = "$out.$def_video_fmt" } if (checkFileExists -filepath $out) { return $null } $vid = 1 / $factor $param_interpol = "" if ($interpolate -and (isInt -value $interpolate)) { $param_interpol = ",minterpolate='fps=$interpolate'" } $param_atempo = "" $atempo = $factor if ($atempo -lt 0.5) { $div = 0.5 } if ($atempo -gt 100) { $div = 100 } while (($atempo -lt 0.5) -or ($atempo -gt 100)) { $param_atempo += "atempo=$div," $atempo = $atempo / $div } $param_atempo += "atempo=$atempo" Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$in`" -filter_complex `"setpts=$vid*PTS$param_interpol`" -filter:a `"$param_atempo`" `"$out`"" } function mix($image, $audio, $subs, $subs_mode, $out, $encode) { if (-not (hasExtension($out))) { $out = "$out.$def_video_fmt" } if (checkFileExists -filepath $out) { return $null } $imageInput = "" $audioInput = "" $subsInput = "" $map = "" $after = "" $vlen = 0 $alen = 0 if (-not $image) { $image = $def_background } $isImage = isImage($image) $map += " -map 0:v" if ($isImage) { $imageInput = "-loop 1 -i `"$image`"" } else { $vlen = & ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $image $imageInput = "-i `"$image`"" } if ($audio) { $alen = & ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $audio $audioInput = "-i `"$audio`"" $map += " -map 1:a" if (-not $isImage) { $after += " -af apad" } } else { $map += " -map 0:a?" } if ($subs) { if ($subs_mode -eq "attach") { $subsInput = "-i `"$subs`"" $after += " -c:s mov_text" if ($audio) { $map += " -map 2:s" } else { $map += " -map 1:s" } } else { $tempSubs = (New-TemporaryFile).FullName Copy-Item $subs -Destination $tempSubs $tempSubs = $tempSubs.Replace("\", "\\\\").Replace(":", "\\:") $after += " -vf `"subtitles=`"$tempSubs`":force_style='FontName=Arial,FontSize=20,BackColour=&H50000000,BorderStyle=4,OutlineColour=&H80000000,PrimaryColour=&H00FFFFFF,MarginL=5,MarginV=5',scale=2*trunc(iw/2):2*trunc(ih/2),setsar=1`"" } } if ((-not $subs) -or ($subs_mode -ne "burn")) { $after += " -vf `"scale=2*trunc(iw/2):2*trunc(ih/2),setsar=1`"" } $len = [float] ($vlen, $alen | Measure-Object -Maximum).Maximum $after += " -t $len" Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y $imageInput $audioInput $subsInput $map $after `"$out`"" if ($tempSubs) { rm ($tempSubs.Replace("\\:", ":").Replace("\\\\", "\")) } } function getDimensions($in) { $dimensions = & ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 "`"$in`"" # write-host $dimensions return $dimensions } function resize($in, $out, $width, $height) { if (-not (hasExtension($out))) { $out = "$out.$def_video_fmt" } if (checkFileExists -filepath $out) { return $null } Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$in`" -vf `"scale=$width`:$height`" `"$out`"" } function convert($in, $out) { if (-not (hasExtension($out))) { if (hasVideo -file $in) { $out = "$out.$def_video_fmt" } else { $out = "$out.$def_audio_fmt" } } if (checkFileExists -filepath $out) { return $null } doConvert -in $in -out $out } # https://stackoverflow.com/questions/52810233/ffmpeg-cut-video-but-getting-the-wrong-length function cut($in, $out, $start, $end, $encode) { if (-not (hasExtension($out))) { if (hasVideo -file $in) { $out = "$out.$def_video_fmt" } else { $out = "$out.$def_audio_fmt" } } if (checkFileExists -filepath $out) { return $null } $extra = "" if (-not $encode) { $extra = "-c copy" } Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$in`" -ss `"$start`" -to `"$end`" $extra -copyts `"$out`"" } function play($in, $start, $end) { $ssp = $start -split ":" $esp = $end -split ":" $len = ([int]$esp[0]*3600 + [int]$esp[1]*60 + [float]$esp[2]) - ([int]$ssp[0]*3600 + [int]$ssp[1]*60 + [float]$ssp[2]) Start-Process $ffplay -Wait -ArgumentList "-hide_banner -ss `"$start`" -t `"$len`" `"$in`"" } function join($infiles, $out, $encode) { if (-not (hasExtension($out))) { $isvid = $false foreach ($in in $infiles) { if (hasVideo -file $in) { $isvid = $true } } if ($isvid) { $out = "$out.$def_video_fmt" } else { $out = "$out.$def_audio_fmt" } } if (checkFileExists -filepath $out) { return $null } $tempList = New-TemporaryFile foreach ($file in $infiles) { "file '$file'" | Out-FileUtf8NoBom -Append $tempList } $extra = "" if ($out.EndsWith('.gif')) { $extra = "-vf `"split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`"" } elseif (isImage($infiles[0])) { $extra = "-pix_fmt yuv420p" } elseif (-not $encode) { $extra = "-c copy" } Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -fflags +discardcorrupt -f concat -safe 0 -i `"$tempList`" $extra `"$out`"" Remove-Item $tempList -ErrorAction Ignore } function upscale($in, $out, $model, $scale, $tile, $temp, $remove) { if (checkFileExists -filepath $out) { return $null } $sr = fact -div 4 -num $scale $sf = $scale / ([Math]::Pow(4, $sr)) if ((isDirectory -path $in) -or (isImage -file $in)) { if (isImage -file $in) { $f = $out.Split(".")[-1] } else { $f = ((Get-ChildItem -Path $in -Recurse -Include *.png,*.jpg,*.webp)[0].Extension).Replace(".", "") } for ($i=0; $i -lt $sr; $i++) { Start-Process -FilePath $upscaler -Wait -ArgumentList "-i `"$in`" -o `"$out`" -n `"$model`" -f $f -t $tile" $in = $out } if ($sf -lt 1) { if (isImage -file $in) { Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$in`" -vf scale=iw*`"$sf`":ih*`"$sf`" `"$out`"" } else { $infiles = Get-ChildItem -Path $in -Recurse -Include *.png,*.jpg,*.webp $strI = "" $strO = "" for ($i = 0; $i -lt $infiles.Length; $i++) { $out_f = "$out\$($infiles[$i].Name)" $strI += "-i `"$out_f`" " $strO += "-map $i -vf scale=iw*`"$sf`":ih*`"$sf`" `"$out_f`" " } Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y $strI $strO" } } } else { if (-not (hasExtension($out))) { $out = "$out.$def_video_fmt" } $ori_dir = createTempDir -root $temp $super_dirs = @("") * $sr for ($i = 0; $i -lt $sr; $i++) { $super_dirs[$i] = createTempDir -root $temp -suffix "_SUPER" } $ori_frames = "$ori_dir\%09d.jpg" $super_frames = "$($super_dirs[-1])\%09d.jpg" Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$in`" -qscale:v 2 `"$ori_frames`"" $in_dir = $ori_dir for ($i=0; $i -lt $sr; $i++) { Start-Process -Wait powershell -argument "$upscale_job -upscaler `"$upscaler`" -ori_dir `"$in_dir`" -super_dir `"$($super_dirs[$i])`" -model `"$model`" -tile $tile -curr_it $i -max_it $sr" $in_dir = $super_dirs[$i] } $frames = & ffprobe -v error -select_streams v -of default=noprint_wrappers=1:nokey=1 -show_entries stream=r_frame_rate $in $fps = ($frames -split "/") $fps = $fps[0] / $fps[1] $pix_fmt = & ffprobe -loglevel error -show_entries stream=pix_fmt -of csv=p=0 $in if ($pix_fmt -is [array]) { $pix_fmt = $pix_fmt[0] } if ($out.endswith(".gif")) { Start-Process $ffmpeg -Wait "-hide_banner -y -framerate $fps -i `"$super_frames`" -r $fps -vf `"scale=iw*`"$sf`":ih*`"$sf`", split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`" `"$out`"" } else { Start-Process $ffmpeg -Wait "-hide_banner -y -framerate $fps -i `"$super_frames`" -i `"$in`" -map 0:v -map 1:a? -r $fps -pix_fmt $pix_fmt -x264opts colormatrix=bt709 -vcodec libx264 -crf 16 -acodec copy -vf scale=iw*`"$sf`":ih*`"$sf`" `"$out`"" } if ($remove) { rm -r $ori_dir for ($i = 0; $i -lt $sr; $i++) { rm -r $super_dirs[$i] } } } } function transcribe($in, $model, $language, $translate) { $output = New-TemporaryFile Remove-Item -path $output -force $params = "" if ($translate) { $params += " --translate" } $model = $transcriber_models.replace("*", $model) $language = ($language -split " - ")[1] $threads = ($env:NUMBER_OF_PROCESSORS , 8 | Measure-Object -Minimum).Minimum $tempWav = Get-ChildItem ([IO.Path]::GetTempFileName()) | Rename-Item -NewName { [IO.Path]::ChangeExtension($_, ".wav") } -PassThru Start-Process $ffmpeg -Wait "-y -i `"$in`" -ar 16000 -ac 1 -c:a pcm_s16le `"$tempWav`"" Start-Process $transcriber -Wait "-m $model --language $language -ovtt -ocsv -otxt -t $threads --output-file `"$output`" $params `"$tempWav`"" $txt = Get-Content "$output.txt" $vtt = Get-Content "$output.vtt" $csv = Get-Content "$output.csv" rm $tempWav rm "$output.txt" rm "$output.vtt" rm "$output.csv" if ($txt -and $vtt -and $csv) { return @{ txt=$txt; vtt=$vtt; csv=$csv } } return $false } function mix_transcribed($source, $subs, $subs_mode, $out) { $streams = & ffprobe -loglevel error -show_entries stream=codec_type -of csv=p=0 $source if ($streams.Contains("video")) { $image = $source } else { $image = $def_background } $tmpFile = New-TemporaryFile Set-Content -Path $tmpFile -Value $subs mix -image $image -audio $source -subs $tmpFile.FullName -subs_mode $subs_mode -out $out -encode $true rm $tmpFile } function download($url, $out, $audio) { # $out = $out + "\%(title)s - %(id)s.%(ext)s" $convert = $false $ext = hasExtension($out) if ($out.EndsWith('.mp4')) { $outTemp = $out } elseif ($audio -or $ext) { $outTemp = "$(New-TemporaryFile).mp4" $convert = $true if ($audio -and (-not $ext)) { $out = "$out.aac" } } else { $outTemp = "$out.mp4" $out = $outTemp } if (Test-Path -Path $out -PathType Leaf) { if (checkFileExists -filepath $out) { return $null } else { rm $out } } $url = checkCustomDownload -url $url -out $out if ($url) { if ($url.Count -gt 1) { # urls[0] = video # urls[1] = array audios # urls[2] = array subs Remove-Item $outTemp -ErrorAction Ignore $outTemp = "$(New-TemporaryFile).$def_video_fmt" Start-Process -FilePath $ytdl -Wait -ArgumentList " -o `"$outTemp`" `"$($url[0])`"" $audios = @() $audio_str = "" $map_str = "" $i = 1 foreach ($u in $url[1]) { $audio = "$(New-TemporaryFile).$def_audio_fmt" $audios += $audio Start-Process -FilePath $ytdl -Wait -ArgumentList " -o `"$audio`" `"$u`"" $audio_str += "-i $audio " $map_str += "-map $i " $i++ } Start-Process $ffmpeg -Wait -ArgumentList "-hide_banner -y -i `"$outTemp`" $audio_str -map 0 $map_str -c copy `"$out`"" Remove-Item $outTemp -ErrorAction Ignore foreach ($a in $audios) { Remove-Item $a -ErrorAction Ignore } } else { Start-Process -FilePath $ytdl -Wait -ArgumentList "-f `"bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best`" -o `"$outTemp`" `"$url`"" if ($convert) { doConvert -in $outTemp -out $out Remove-Item $outTemp -ErrorAction Ignore } } } } function checkCustomDownload($url, $out) { $accept = "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01" if ($url.StartsWith("https://www.atresplayer.com")) { $headers = @{ accept = $accept; referer = 'https://eljaviero.com/descargarvideosdelatele/'; } $post = @{url_noticia = $url; submit_enviar_url = 'ok'; current_url = 'https://eljaviero.com/descargarvideosdelatele/' } $page = Invoke-WebRequest -Uri "https://eljaviero.com/descargarvideosdelatele/index.php?jsoncall=jQuery11120014304724907985733_1665862825338" -Method POST -Body $post -Headers $headers $link = ($page.ParsedHtml.getElementsByClassName("code_manifest_url")[1].textContent.replace('\', '') -split "<")[0] $m3u8_stream = Invoke-WebRequest -Uri $link -Method GET $max_res = 0 $max_i = 1 $m3u8_split = $m3u8_stream.RawContent -split "RESOLUTION=" for ($i = 1; $i -lt $m3u8_split.Length; $i++) { $res = [int] (($m3u8_split[$i] -split "x")[0]) if ($res -gt $max_res) { $max_res = $res $max_i = $i } } $video = $link.replace("playlist.m3u8", ($m3u8_split[$max_i] -split "`n")[1]) $urls = @($video) if ($m3u8_stream.RawContent.Contains("TYPE=AUDIO")) { $audios = @() $m3u8_split = $m3u8_stream.RawContent -split "`n" for ($i = 0; $i -lt $m3u8_split.Length; $i++) { if ($m3u8_split[$i].Contains("TYPE=AUDIO")) { $audios += $link.replace("playlist.m3u8", ($m3u8_split[$i] -split "URI=")[1].Replace("`"", "")) } } $urls += , $audios } return $urls } elseif ($url.StartsWith("https://www.rtve.es")) { $post = @{web = $url; } $page = Invoke-WebRequest -Uri "https://www.descargavideos.tv/" -Method POST -Body $post return ((($page -split "linkHtml")[1]) -split "'")[1] } elseif ($url.Contains("://www.crtvg.es")) { $page = (New-Object net.webclient).DownloadString(($url -split "\?")[0]) $file = (($page -split ".mp4")[0] -split "`"")[-1] return "$file.mp4/playlist.m3u8" } elseif ($url.StartsWith("https://elpais.com")) { $client = New-Object net.webclient $page = $client.DownloadString($url) $media = (($page -split "id_media")[1] -split "`"")[2] $json = $client.DownloadString("https://fapi-top.prisasd.com/api/v2/search/elpais/video/idref/$media") | ConvertFrom-Json $best_bit = 0 $best_asset = "" $target = "" foreach ($asset in $json.data[0].asset) { if ($asset.bitrate) { if ($asset.bitrate -gt $best_bit) { $best_bit = $asset.bitrate $best_asset = $asset.url[2].url } } else { $target = $asset.url.url } } if ($best_asset) { $target = $best_asset } return $target } elseif ($url.StartsWith("https://www.lamoncloa.gob.es")) { $page = (New-Object net.webclient).DownloadString($url) return (($page.RawContent -split "urlVideo")[2] -split "'")[1] } elseif ($url.StartsWith("https://tv.uvigo.es")) { $url = $url.Replace("video", "videoplayer") $page = (New-Object net.webclient).DownloadString($url) $file = (($page -split "trackplayed/")[1] -split "'")[0] $file_url = "$(($url -split "videoplayer")[0])trackfile/$file" # return "$(($url -split "videoplayer")[0])trackfile/$file" $out = $out -replace ' ', '_' if (checkFileExists -filepath $out) { return $false } else { Start-Process -Wait powershell -argument "$download_job -url `"$file_url`" -out `"`"$out`"`"" return $false } } elseif ($url.StartsWith("https://scribd.com") -or ($url -like "https://*.scribd.com/*")) { $path = getPathFromURL -url $url Start-Process "https://scribd.vdownloaders.com/$path" return $false } elseif ($url.StartsWith("https://www.studocu.com")) { $path = getPathFromURL -url $url Start-Process "https://downstudocu.com/$path" return $false } elseif ($url.StartsWith("https://slideshare.net") -or ($url -like "https://*.slideshare.net/*")) { $url = "https://slideshare.downloader.is/slideshareappiippg/convert2pdf.php?url=$url" $cookies = "downloadStarted,0,slideshare.downloader.is" Start-Process -Wait powershell -argument "$download_job -url `"$url`" -cookies `"`"`"$cookies`"`"`" -out `"$out.pdf`"" return $false } elseif ([bool]$webedia.Where({ $url.StartsWith($_) })) { $page = (New-Object net.webclient).DownloadString($url) $vid = (($page -split "videoId")[1] -split "`"")[2] return "https://www.dailymotion.com/embed/video/$vid" } elseif ($url.StartsWith("https://www.msn.com")) { $page = (New-Object net.webclient).DownloadString($url) $url = (($page -split ".ism/manifest")[0] -split "src=`"")[-1] + ".ism/manifest" $outTemp = "$(New-TemporaryFile).ismv" Start-Process -FilePath $ytdl -Wait -ArgumentList "-f `"bestvideo[height<=1080]+bestaudio`" -o `"$outTemp`" `"$url`"" doConvert -in $outTemp -out $out Remove-Item $outTemp -ErrorAction Ignore return $false } return $url } function getTitle($url) { $popup = showPopup -text "Leyendo información del vídeo..." $popup.Show() if ($url.StartsWith("https://www.atresplayer.com")) { $title = ($url -split "/")[7] } elseif ($url.StartsWith("https://www.rtve.es")) { $title = ($url -split "/")[6] } elseif ($url.Contains("://www.crtvg.es")) { $title = (($url -split "/")[-1] -split "\?")[0] } elseif ($url.StartsWith("https://elpais.com")) { $title = (($url -split "/")[-1] -split "\.")[0] } elseif ($url.StartsWith("https://www.lamoncloa.gob.es")) { $title = ((($url -split "/")[7]) -split "\.")[0] } elseif ($url.StartsWith("https://tv.uvigo.es")) { $page = Invoke-WebRequest -Uri $url -Method GET $title = (((($page -split 'qa-player-title title-for-crumbs always-hide">')[1]) -split "<")[0]).Replace("`n", "").Replace(" ", "") } elseif ($url.StartsWith("https://scribd.com") -or ($url -like "https://*.scribd.com/*")) { $title = ($url -split "/")[5] } elseif ($url.StartsWith("https://www.studocu.com")) { $title = ($url -split "/")[7] } elseif ($url.StartsWith("https://slideshare.net") -or ($url -like "https://*.slideshare.net/*")) { $title = ($url -split "/")[4] } elseif ([bool]$webedia.Where({ $url.StartsWith($_) })) { $title = ($url -split "/")[4] } elseif ($url.StartsWith("https://www.msn.com")) { $title = ($url -split "/")[6] } else { $title = (& $ytdl --get-title --encoding utf-16 $url) } $popup.Close() return $title } function getPathFromURL($url) { return (($url -split "/") | Select-Object -Skip 3) -join "/" } function fact($num, $div, $n) { $num = $num / $div $n += 1 if ($num -le 1) { return $n } return fact -num $num -div $div -n $n } function createTempDir($root, $suffix) { if ($root -eq $ENV:Temp) { $file = New-TemporaryFile Remove-Item -path $file -force return New-Item -ItemType Directory -Path "$($ENV:Temp)\$($file.Name)" } else { do { $dir = "$root\tmp_$([DateTimeOffset]::Now.ToUnixTimeSeconds())-$(Get-Random)" if ($suffix) { $dir = $dir + $suffix } } while (Test-Path -Path $dir -PathType Leaf) return New-Item -ItemType Directory -Path $dir } } function isDirectory($path) { return Test-Path -Path $path -PathType Container } function isImage($file) { $ext = (Get-Item $file).Extension return $ext -and (@(".png", ".jpg", ".jpeg", ".webp") -match $ext) } function hasVideo($file) { $streams = ffprobe -loglevel error -show_entries stream=codec_type -of csv=p=0 $file return $streams.contains("video") } function hasAudio($file) { $streams = ffprobe -loglevel error -show_entries stream=codec_type -of csv=p=0 $file return $streams.contains("audio") } function getFileDuration($in) { $r = & $ffmpeg -i $in 2>&1 for ($i = 0; $i -lt $r.Length; $i++) { if ($r[$i] -like "*Duration:*") { break } } return (($r[$i] -split ": ")[1] -split "\.")[0] } function hasExtension($str) { $sp = $str -split "\." if ($sp.length -ge 2) { if ($sp[-1] -match '^\w{3,4}$') { return $true } } return $false } function doConvert($in, $out) { $extra = "" if ($out.EndsWith('.gif')) { $extra = "-vf `"split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse`"" } Start-Process $ffmpeg -Wait "-hide_banner -y -i `"$in`" $extra `"$out`"" } function checkFilename($filename) { $index = $filename.IndexOfAny([System.IO.Path]::GetInvalidFileNameChars()) return $index -eq -1 } function removeInvalidChars($textbox) { $index = $textbox.Text.IndexOfAny([System.IO.Path]::GetInvalidFileNameChars()) $sel_idx = $textbox.SelectionStart if ($index -ge 0) { $textbox.Text = $textbox.Text.Remove($index, 1) $textbox.SelectionStart = $sel_idx - 1 } } function removeInvalidCharsString($name) { $invalidChars = [IO.Path]::GetInvalidFileNameChars() -join '' $re = "[{0}]" -f [RegEx]::Escape($invalidChars) $name = $name -replace $re return $name.subString(0, [System.Math]::Min(220, $name.Length)) } function checkFileExists($filepath) { if (Test-Path -Path $filepath -PathType Leaf) { $continue = [System.Windows.MessageBox]::Show("El archivo <$filepath> ya existe. ¿Sobreescribir?", "Advertencia", 'YesNo', "Warning"); if ($continue -eq 'Yes') { return $false } else { return $true } } return $false } function isNumeric ($value) { return $value -match "^[\d\.]+$" } function isInt ($value) { return $value -match "^[\d]+$" } function runKeylogger { return Start-Process powershell -PassThru -ArgumentList "-windowstyle Hidden -file $keylogger" } function showPopup($text) { Add-Type -AssemblyName System.Windows.Forms $popup = New-Object System.Windows.Forms.Form $popup.Text = "Info" $popup.Icon = $icon $popup.AutoSize = $true $popup.FormBorderStyle = 'FixedDialog' $popup.MaximizeBox = $false $popup.Font = "Microsoft Sans Serif, 9.35" $popup.Size = New-Object System.Drawing.Size(260, 100) # Add Label $label = New-Object System.Windows.Forms.Label $label.AutoSize = $true $label.Text = $text $label.Location = New-Object System.Drawing.Point(20, 20) $popup.Controls.Add($label) $popup.add_Load({ $nx = ($win_loc.X + $win_size.Width / 2) + $popup.Size.Width / 2 - 35 $ny = ($win_loc.Y + $win_size.Height / 2) + $popup.Size.Height / 2 + 30 $popup.Location = New-Object System.Drawing.Point($nx, $ny) }) return $popup } # https://stackoverflow.com/questions/65156768/how-to-stop-a-windows-10-machine-from-sleeping-hibernating-down-when-running-a-p function startAlwaysOn { $schemeGuid = 'e03c2dc5-fac9-4f5d-9948-0a2fb9009d67' $schemeName = 'Always ON' $schemeDescr = 'Custom power scheme to keep the system awake indefinitely.' $prevGuid = (powercfg -getactivescheme) -replace '^.+([-0-9a-f]{36}).+$', '$1' powercfg -setactive $schemeGuid 2>$null if ($LASTEXITCODE -ne 0) { $null = powercfg -duplicatescheme $prevGuid $schemeGuid $null = powercfg -changename $schemeGuid $schemeName $schemeDescr powercfg -setactive $schemeGuid $settings = 'standby-timeout-ac', 'standby-timeout-dc', 'hibernate-timeout-ac', 'hibernate-timeout-dc' foreach ($setting in $settings) { powercfg -change $setting 0 } } return $prevGuid } function endAlwaysOn($code) { powercfg -setactive $code } function printLog { $(Get-Content $log_temp_file)+"`r`n" | Out-File $log_file -Append -Encoding "utf8" } function selectFolder($path) { $fsd = New-Object FolderSelect.FolderSelectDialog $fsd.Title = "Seleccionar carpeta" $fsd.InitialDirectory = $path $fsd.ShowDialog() | Out-Null return $fsd.FileName } function selectFile($path, $formats, $multi) { $dialog_inp = New-Object System.Windows.Forms.OpenFileDialog $dialog_inp.InitialDirectory = $path $dialog_inp.filter = $formats $dialog_inp.MultiSelect = $multi $result = $dialog_inp.ShowDialog() if ($result -eq [Windows.Forms.DialogResult]::OK) { if ($multi) { return $dialog_inp.FileNames } else { return $dialog_inp.FileName } } } function selectSaveFile($filename, $extension) { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.SaveFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = "All files (*.*)| *.*" $OpenFileDialog.FileName = $filename # Default file name $OpenFileDialog.DefaultExt = ".$extension" # Default file extension $result = $OpenFileDialog.ShowDialog() if ($result -eq [Windows.Forms.DialogResult]::OK) { return $OpenFileDialog.filename } return $false } function saveFile($data, $filename, $extension) { $filename = selectSaveFile -filename $filename -extension $extension if ($filename) { Set-Content -Path $filename -Value $data } } function getRelativeLocation($parent, $child) { $x = ($child.Location.X + $child.Size.Width / 2) - $parent.Size.Width / 2 $y = ($child.Location.Y + $child.Size.Height / 2) - $parent.Size.Height / 2 return New-Object System.Drawing.Point($x, $y) } function optimizeTranscriber { Write-Host "Optimizando el modelo de ASR, por favor, espere..." function testTranscriber($trans_version) { $bench = $trans_version -replace $transcriber_exe, $transcriber_bench $model = $transcriber_models -replace "\*\.bin", $transcriber_ref_model $output = Start-ProcessWithOutput -command $bench -arguments "-m $model" # $output = (& $bench -m $model) 2>&1 $pattern = 'whisper_print_timings:\s+total time =\s+(\d+\.\d+) ms' $matchingLine = $output | Select-String -Pattern $pattern if ($matchingLine) { $totalTimeString = $matchingLine.Matches.Groups[1].Value $totalTime = [double]$totalTimeString return $totalTime } return [Double]::PositiveInfinity } $best_transcriber = $null $best_time = [Double]::PositiveInfinity foreach ($name in $transcribers.Keys) { $time = testTranscriber -trans_version $transcribers[$name] if ($time -lt $best_time) { $best_time = $time $best_transcriber = $transcribers[$name] } } $transcriber_cpu = $best_transcriber $transcriber_cpu | Set-Content -Path $transcriber_save write-host "Optimizado: $transcriber_cpu" } function getTranscriber($paths) { if (Test-Path $transcriber_save) { $transs = Get-Content $transcriber_save if (Test-Path $transs) { $transcriber_cpu = $transs } } try { $oldPath = $env:PATH; $env:PATH += ";$($paths -join ";")" $output = (& $transcriber_gpu --help) 2>&1 $env:PATH = $oldPath $isGpuAvailable = [bool]($output -match "--language") } catch { $isGpuAvailable = $false } if ($isGpuAvailable) { return $transcriber_gpu } else { return $transcriber_cpu } } $webedia = @( "https://www.xataka.com", "https://www.vidaextra.com", "https://www.espinof.com", "https://www.genbeta.com", "https://www.directoalpaladar.com", "https://www.xatakaciencia.com", "https://www.trendencias.com", "https://www.applesfera.com", "https://www.xatakamovil.com", "https://decoracion.trendencias.com", "https://www.vitonica.com", "https://www.xatakafoto.com", "https://www.trendenciashombre.com", "https://www.xatakandroid.com", "https://www.xatakahome.com", "https://www.xatakawindows.com", "https://magnet.xataka.com", "https://www.compradiccion.com", "https://www.3djuegos.com", "https://www.sensacine.com", "https://www.poprosa.com", "https://www.mundoxiaomi.com", "https://www.3djuegospc.com", "https://www.3djuegosguias.com" )