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

powershell #33

Open
nascentt opened this issue Sep 25, 2024 · 1 comment
Open

powershell #33

nascentt opened this issue Sep 25, 2024 · 1 comment

Comments

@nascentt
Copy link

I dont have python or node.js installed so i ported the code to powershell, which comes with windows.

function Main {
    $url = 'https://storage.googleapis.com/panels-api/data/20240916/media-1a-i-p~s'
    
    try {
        # Fetching JSON data
        $response = Invoke-RestMethod -Uri $url
        if ($null -eq $response) {
            throw "Failed to fetch JSON file"
        }
        $data = $response.data
        if ($null -eq $data) {
            throw "JSON does not have a 'data' property at its root."
        }
        # Create download directory
        $downloadDir = Join-Path -Path $PSScriptRoot -ChildPath 'downloads'
        if (-not (Test-Path $downloadDir)) {
            New-Item -ItemType Directory -Path $downloadDir | Out-Null
            Write-Host "Created directory: $downloadDir"
        }
        $fileIndex = 1
        # Iterate through each property in the $data object
        $data | Get-Member -MemberType NoteProperty | ForEach-Object {
            $key = $_.Name
            $subproperty = $data.$key
            
            # Check if the 'dhd' property exists in the subproperty
            if ($null -ne $subproperty.dhd) {
                $imageUrl = $subproperty.dhd
                Write-Host "Found image URL for key $key!"
                # Delay between requests
                Start-Sleep -Milliseconds 100
                # Get file extension and construct file path
                $ext = [System.IO.Path]::GetExtension((New-Object Uri($imageUrl)).AbsolutePath)
                if ([string]::IsNullOrEmpty($ext)) { 
                    $ext = '.jpg' 
                }
                $filename = "$fileIndex$ext"
                $filePath = Join-Path -Path $downloadDir -ChildPath $filename
                
                # Download and save the image
                DownloadImage -url $imageUrl -filePath $filePath
                Write-Host "Saved image to $filePath"
                # Increment file index and delay
                $fileIndex++
                Start-Sleep -Milliseconds 250
            }
        }
    } catch {
        Write-Error "Error: $_"
    }
}

function DownloadImage {
    param ($url, $filePath)

    try {
        # Downloading image
        $imageData = Invoke-RestMethod -Uri $url -Method Get -OutFile $filePath
    }
	catch {
        throw "Failed to download image: $_"
    }
}


function AsciiArt {
    Write-Host @'
 /$$      /$$ /$$   /$$ /$$$$$$$   /$$$$$$  /$$$$$$$
| $$$    /$$$| $$  /$$/| $$__  $$ /$$__  $$| $$__  $$
| $$$$  /$$$$| $$ /$$/ | $$  \ $$| $$  \__/| $$  \ $$
| $$ $$/$$ $$| $$$$$/  | $$$$$$$ |  $$$$$$ | $$  | $$
| $$  $$$| $$| $$  $$  | $$__  $$ \____  $$| $$  | $$
| $$\  $ | $$| $$\  $$ | $$  \ $$ /$$  \ $$| $$  | $$
| $$ \/  | $$| $$ \  $$| $$$$$$$/|  $$$$$$/| $$$$$$$/
|__/     |__/|__/  \__/|_______/  \______/ |_______/
'@
    Write-Host ""
    Write-Host "Starting downloads from your favorite sellout grifter's wallpaper app..."
}

AsciiArt
Start-Sleep -Seconds 5
Main

@0xvisualiris
Copy link

Haha, did the same lol

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