sourcecode

Powershell 이미지를 https://www.artstation.com/ 에 업로드합니다.

copyscript 2023. 9. 1. 21:14
반응형

Powershell 이미지를 https://www.artstation.com/ 에 업로드합니다.

내용물

  • 질문.
  • 질문 정보
  • 배경 / 연구
  • 코드 블록
  • 자원.


질문:.

이미지를 Artstation에 자동으로 업로드/프로그래밍하는 방법\파워셸을 이용한 프로젝트 페이지?

업로드하는 동안 파일을 선택하기 위한 사용자 입력이 없습니다.미리 정의된 미디어 데이터만.파워셸의 내장 기능으로 할 수 있다면 선호합니다.

(아래 웹 페이지 참조 이미지 'ArtStation 업로드 페이지' 참조)



질문 정보:

환경 컨텍스트:

  • OS: Windows 10, V: 1803, 빌드: 17134.165
  • 플랫폼: PC
  • Powershell: V:5.1.17134.165(데스크톱 버전), 빌드: 10.0.17134.165, (관리자, 실행 정책 원격 서명으로 실행)
  • Internet Explorer 11: V:11.165.17134.0, 업데이트 V:11.0.75(KB4339093)
  • 사이트: https://www.artstation.com/myartstation/projects/new


아트스테이션은 중앙에 파일 브라우저를 여는 '업로드 버튼'이 있는 '끌어서 놓기' 코너가 있습니다.(이미지 아트스테이션 업로드 페이지 참조).

몇 가지 방법이 있습니다.

  1. 드래그 영역으로 파일 드래그 시뮬레이션(가장 간단한 것으로 보임)
  2. button을 사용하지 않고 파일 브라우저에 업로드할 파일을 전달합니다.click()
  3. Button.click() 파일 브라우저를 엽니다. 별도의 파워셸 프로세스를 사용하여 파일 브라우저를 캡처하고 업로드할 파일을 찾아 선택합니다.
  4. 프로젝트 페이지에 새 하위 '아트-워크' 요소를 수동으로 생성/추가합니다.


배경 - 연구:

안녕, 내 첫 번째 게시물.

저는 새로운 파워셸 사용자이자 새로운 프로그래머입니다.저는 파워셸을 통해 아트스테이션에 이미지를 업로드하기 위해 삶의 질 애플리케이션을 수정하려고 했습니다.

저는 지금 약 2주 동안(80시간 이상) 수익률이 없는 수백 개의 포럼과 사이트를 보면서 어떻게 해야 할지 고민하고 있습니다.어쩌면 제가 무엇을 찾고 있는지, 아니면 질문을 사용하지 않는지 알 수 없기 때문에 답변에 대한 답변을 얻을 수 있습니다.그래서 저는 선을 긋고 제가 도움을 받을 수 있는지 볼 때라고 생각했습니다.제가 바보인 것처럼 설명해 주세요, 처음부터요.

파워셸을 통해 이미지를 업로드하는 방법에 대해 아직 아무것도 찾지 못했습니다.아니면 적어도 내가 이해할 수 있는 것은 아무것도 없습니다.


지금까지 제가 생각했던 작동 가능성에 대해 살펴본 모든 것은 파일을 어디로 보내야 하는지 알아야 합니다.Invoke-WebRequest / Invoke-RestMethod, Copy-item-session, Drag-drop JavaScript.유일한 문제는 제가 모른다는 입니다.그리고 제가 가진 유일한 것은 '끌어서 놓기 영역' 개체와 '파일 업로드 버튼' 개체에 대한 변수가 있는 internet Explorer.application ComObject입니다.둘 다 설정 방법이나 필요한 데이터 구조를 알 수 없는 메서드와 속성을 가지고 있습니다.


과거 쿼리: (MFF, IE 및 Chrome;)

(여러 세션에서 사용한 단어)
"powershell", v5, https, 업로드, 이미지, 파일, 아트스테이션, 데이터 전송, onDropEvent, copy-item, html, javascript, drag&drop 함수, 입력 함수, 정의, ondrop, 객체 형식, https 파일 전송, 변환, 이미지 투 바이트, 패키지, 객체, $ie.document.getelementId('image-input-uppload').값 =".\$myImage" , 탐지, 탐지, 캡처, 추적, 찾기, 새, 하위, 프로세스, 파일 탐색기, 브라우저, 탐색, 파일 선택, 할당, CTS, 업로더, dllhost, sendkeys, AssemblyName, System.창문들.양식, 마이크로소프트.VisualBasic, multiPartContent, set-clipboard, get-clipboard, fileAsBinaryString



코드 블록:

이게 못생겼거나 말이 안 된다면 죄송합니다.그에 대한 간단한 대답은 제가 도대체 뭘 하고 있는지 모른다는 것입니다.저는 그저 잘 될 수 있는 무언가를 함께 폐기하고 있을 뿐입니다.

#< START_GLOBAL-VARIABLES >#

#< Secure Document >#
    #TODO: Clean up memory before setting to null
    #If Either list exists on script run set to null
    if($CredList.Keys){$CredList = $null}
    if($keyWord.Count){$keyWord = $null}

    $CredList = @{}
    #TODO: remove debug elements
    #Debug Variable 'easy select has key'
    $keyWord = @()

    #Pull and Parse Security Data from file
    $CredBody = Get-Content $CertFile
    $CredBody | ForEach-Object {
        $s = $_ -split ", "
        $keyWord += [REGEX]::Match($s[0], "(?<=www.).*?(?=.com)").groups[0].value
        $CredList.add($s[0],($s[1],$s[2]))
    }

#TODO: remove debug elements
#< Debug Option >#
    #Split security file data and repack in hashtable
    $keyWord = $keyWord.GetEnumerator() | Sort-Object
    $httpHost = ($CredList.Keys -imatch $keyWord[0])
    $ActiveKey = ($CredList[$CredList.Keys -imatch $keyWord[0]])

###< END_GLOBAL-VARIABLES >###


###< START_ARTSTATION >###


if($httpHost -imatch 'artstation')
{
    #Todo: Move this to a global scope to reuse for other art sites.
        #Or create once and use navigate? More/less secure?

    #< Create IE window and poit at Artstation >#
        $ie = New-Object -ComObject 'InternetExplorer.Application'
        $ie.visible=$true
        $ie.navigate($httpHost)

        while($ie.ReadyState -ne 4) {start-sleep -m 100}


    ##< START_LOGIN >##

    if($ie.Document.location.href -eq 'https://www.artstation.com/users/sign_in')
    {
        #Todo: Encrypt Data Source + pass information securly to webpage
            #Pass data through windows security window?

        #< Find Desired Cert Elements >#
            $forms = $ie.Document.forms | ForEach-Object { $_ | ForEach-Object { if($_.id -imatch 'email'-or $_.id -imatch 'password'){return $_ } } }

        # UserName
            $UserForm = $forms | Where-Object {$_.id -imatch 'email'}
            $UserForm[0].focus()
            $ie.Document.activeElement.value = $ActiveKey[0][0]

        # Password
            $PassForm = $forms | Where-Object {$_.id -imatch 'password'}
            $PassForm[0].focus()
            $ie.Document.activeElement.value = $ActiveKey[0][1]

        #Submit Form
            $submitForm = $ie.Document.forms[1].elements | Where-Object { $_.name -imatch 'button'}
            $submitForm.focus()
            $submitForm.click()

            while($ie.ReadyState -ne 4) {start-sleep -m 100}
    }

    ##< END_LOGIN >##

    #TODO: remove debug elements
    #< Debug Option >#
        #Navigate to an Existing or New project page
        $result = UserPrompt $ie 'Is this a new project?' 'Project Setup' 'Question' {$ie.navigate("https://www.artstation.com/myartstation/projects/new")} {$ie.navigate("https://www.artstation.com/marketplace/manage/products/new")} {$null}
        while($ie.ReadyState -ne 4) {start-sleep -m 100}


    ##< START_UPLOAD >##


    #"Drag & Drop Rect"
        #<div class="well drop-files text-center hidden-sm hidden-xs" id="dropzone"><label class="btn btn-default" for="upload-image-input"><i class="far fa-arrow-from-bottom fa-pad-right"></i>Upload your images</label><div class="separator-sm"></div><div class="text-muted">Upload or drag &amp; drop images</div></div>
    #Pictures:
        #<input accept="image/jpeg,image/png,image/gif" id="upload-image-input" multiple="multiple" name="asset[image][]" type="file">
    #Video:
        #<a class="btn btn-default" id="project-add-video-btn" data-toggle="modal" data-target="#add-video-modal" href="#"><i class="far fa-film fa-pad-right"></i>Add Video</a>
    #SketchFab
        #<a class="btn btn-default" id="project-add-3dmodel-btn" data-toggle="modal" data-target="#add-3dmodel-modal" href="#"><i class="far fa-cube fa-pad-right"></i>Add Sketchfab</a>
    #Marmoset
        #<input multiple="multiple" name="asset[image][]" type="file">
    #Pano
        #<a class="btn btn-default" id="project-add-pano-btn" href="#"><i class="far icon-pano fa-pad-right"></i>Add 360 Pano</a>
    #ProjectThumbnail
        #<label class="upload-thumbnail-placeholder" for="upload-thumbnail"><i class="far fa-image fa-2x"></i><div class="small">Upload or drag &amp; drop image</div></label>


    ##< START_POPULATE-FIELDS >##

        #< Art-Image >#
            #Image
            #Upload
            #Captions
            #ImageFitting

        #< Thumbnail-Image >#
            #Image
            #Upload

        #< VARIABLES >#
            $fielfToken = 'title','description', 'medium','Matter', 'adult','albmus','portfolio', 'software', 'Tags'
            $Values = 'This is my title',
                      'This painting was done for my Twitch stream! come stop on by some time.',
                      'digital 3d'

        #< TITLE >#
            #Text Field [a-z,0-9]
            $titleToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[0]} }
            $titleToken[0].value = $Values[0]

        #< DESCRIPTION >#
            #Text Field [a-z,0-9]
            $descriptionToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[1]} }
            $descriptionToken.value = $Values[1]

        #< MEDIUM >#
            #dropdown[v]
            #Pull dropdown choices
            $mediumToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[2]} }
            #Set medium dropdown to $mediumToken.tostring()

        #< SUBJECT-MATTERr >#
            #dropdown[v]
            #Pull dropdown choices
            #$subjectToken
            #$subjectToken

        #< ADULT-CONTENT >#
            #checkbox[x]
            $adultToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[4]} }
            $adultToken.click()

        #< SOFTWARE >#
            #Dropdown[v]
            #Pull software list
            #$softwareToken
            #$softwareToken

        #< START_TAGS >#
            #Option 1: Previous[] pr Previous[X]
            #Option 2:  'tag1' 'tag2' 'tag3'. . .

            #if Previous ticked checkbox[x]
            #$foundToken[1].click()

            #if extra Tags = @()
            #$foundToken[0].length

        #< END_TAGS >#

        #< ALBUMS >#
            #checkbox[x] list ( AlbumsA[], AlbumsB[], AlbumsC[] )
            #Get list of available albums
            $albumsToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.classname -imatch 'col-md-3'} }
            $albumsToken.click()

        #< START_PORTFOLIO >#

            #ArtStation.com checkbox[x]
            #$adultToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[4]} }
            #$adulToken.click()

            #MyWebsite checkbox[x]
            #$adultToken = $ie.Document.forms | ForEach-Object{ $_ | Where-Object {$_.id -imatch $fielfToken[4]} }
            #$adulToken.click()

        #< END_PORTFOLIO >#

        #< Review >#
            #click ok when done reviewing
            #Edit text
            #Re-upload media

        #< Publish >#
            #Save.click()
            #Publish.click()


    ##< END_POPULATE-FIELDS >##


    #< Logout >#

    #$signOut = $ie.Document.all | Where-Object {$_.classname -imatch 'far fa-sign-out fa-fw fa-pad-right-x2'}
    #$signOut.focus()
    #$signOut.click()

    ###< END_ARTSTATION >###
}


리소스:

링크:
* community.box.com/t5/Platform-and-Development-Forum/Upload-a-file-using-API-in-PowerShell/td-p/35660
* app.box.com/s/46hwgi48n31g42vuqjk67d01abceypij
* stackoverflow.com/questions/23059945/upload-a-file-to-box-com-using-powershell
* get-powershellblog.blogspot.com/2017/09/multipartform-data-support-for-invoke.html
* blog.majcica.com/2016/01/13/powershell-tips-and-tricks-multipartform-data-requests/
* blog.majcica.com/2016/01/15/uploading-xl-deploy-dar-package-via-powershell/
* github.com/react-dropzone/react-dropzone

오래 전에 이 질문을 게시한 것으로 알고 있습니다. 하지만 여기 어떤 방식으로든 활용할 수 있는 가능한 접근 방식이 있습니다.

function Click-DragControl
{
Param(
    [Parameter(Position=0,Mandatory=$TRUE)]
    [UIAutomation.UiElement]
    $ObjectDragFrom,

    [Parameter(Position=1,Mandatory=$TRUE)]
    [UIAutomation.UiElement]
    $ObjectDragTo
    )

$newX=[Int]($ObjectDragFrom.Current.BoundingRectangle.X+($ObjectDragFrom.Current.BoundingRectangle.Width/2))
$newY=[Int]($ObjectDragFrom.Current.BoundingRectangle.Y+($ObjectDragFrom.Current.BoundingRectangle.Height/2))

# In the event the object is inside a collapsible window, or is otherwise off-screen, the pixels we get back will be <0,0>.
# So we'll revert to our older method of clicking, because it can crawl through the control and still obtain the item.
if ($newX -eq 0 -and $newY -eq 0)
{
    $ObjectDragFrom.Mouse.LeftButtonClick()
    return $true
}

[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($newX,$newY)
$signature=
@'
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@
$SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru
Try
{
    $SendMouseClick::mouse_event(0x00000002, 0, 0, 0, 0); # Left Mouse Down
}
Catch
{
    Write-Host("ERROR: Caught an Unhandled Exception in Click-Control. Originating Error:`n$Global:Error[0]")
    return $FALSE
}   

$newX=[Int]($ObjectDragTo.Current.BoundingRectangle.X+($ObjectDragTo.Current.BoundingRectangle.Width/2))
$newY=[Int]($ObjectDragTo.Current.BoundingRectangle.Y+($ObjectDragTo.Current.BoundingRectangle.Height/2))

# In the event the object is inside a collapsable window, or is otherwise off-screen, the pixels we get back will be <0,0>.
# So we'll revert to our older method of clicking, because it can crawl through the control and still obtain the item.
if($newX -eq 0 -and $newY -eq 0){
    $ObjectDragTo.Mouse.LeftButtonClick()
    return $TRUE
}

[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($newX,$newY)
$signature=
@'
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@
$SendMouseClick = Add-Type -memberDefinition $signature -name "Win32MouseEventNew" -namespace Win32Functions -passThru
Try
{
    $SendMouseClick::mouse_event(0x00000004, 0, 0, 0, 0); # Left Mouse Up
    return $TRUE
}
Catch
{
    Write-Host("ERROR: Caught an Unhandled Exception in Click-DragControl. Originating Error:`n$Global:Error[0]")
    return $FALSE
}

}

언급URL : https://stackoverflow.com/questions/51513892/powershell-upload-image-to-https-www-artstation-com

반응형