Jump to content
Sign in to follow this  
CFIHS

pics.lt

Recommended Posts

CFIHS

I want to automate the imagehoster pics.lt, unfortunately the used PHP-Script has no API.
 
http://pics.lt/index.php?lang=english

Thank you in advance.
 

^#include <WinHttp.au3>
#include <String.au3>

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "pics.lt")

$aHeader = _WinHttpSimpleRequest($hConnect, "GET", "/index.php?lang=english", $WINHTTP_NO_REFERER, $WINHTTP_NO_REQUEST_DATA, $WINHTTP_NO_ADDITIONAL_HEADERS, True)
$aCookie = _StringBetween($aHeader[0], "Cookie: ", ";")
$hImage = FileOpenDialog("", @ScriptDir, "(*.bmp; *.gif; *.png; *.jpg)")
$bImage = FileOpen($hImage, 16)

;$sHeader = ?!

_WinHttpSimpleRequest($hConnect, "POST", "/upload.php", "pics.lt/index.php?lang=english", $bImage, $sHeader)

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum :)

Search for the _WinHTTP_SimpleFormFill function, trancexx provided some examples on the forum.

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
hiho

This should work but i've no idea why it doesnt..

#include <Winhttp.au3>

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "pics.lt")
$sRead = _WinHttpSimpleFormFill($hConnect, "/upload.php", "", _
        "name:MAX_FILE_SIZE", 10485760, _
        "name:imgUrl", "", _
        "name:fileName[]", "animeg.jpg", _
        "name:file[]", @DesktopDir & "\animeg.jpg", _
        "name:alt[]", "animeg", _
        "name:new_height[]", "", _
        "name:new_width[]", "", _
        "name:submit", "Upload")
ConsoleWrite($sRead & @CRLF)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

or if it is working then i don't know how to get the url of the image.

Share this post


Link to post
Share on other sites
CFIHS

I just managed it.
 
Many thanks!
 

#include <WinHttp.au3>
#include <String.au3>

$hOpen = _WinHttpOpen()
$hConnect = _WinHttpConnect($hOpen, "pics.lt")

$hImage = FileOpenDialog("", @ScriptDir, "(*.bmp; *.gif; *.png; *.jpg)")

$aSS = StringSplit($hImage, "\") 
$aDescription = StringSplit($aSS[$aSS[0]], ".") 

$sSource = _WinHttpSimpleFormFill($hConnect, "/upload.php", Default, _
        "name:file[]", $hImage, _
        "name:alt[]", $aDescription[1])

$aSB = _StringBetween($sSource, '<div class="img_box">', '" title="' & $aDescription[1] & '" class="lightbox" >')
$aURL = StringSplit($aSB[0], '"')

ConsoleWrite("URL: " & $aURL[2])

_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

Share this post


Link to post
Share on other sites
hiho

C:\Users\--------\Desktop\AutoIT\msgboxtest.au3 (20) : ==> Subscript used with non-Array variable.:
$aURL = StringSplit($aSB[0], '"')
$aURL = StringSplit($aSB^ ERROR

Runnin your (or mine) script always returnrs the following output (which is why i sad that it should work)..

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>CF Image Host &lt;  - Image Gallery Page 1</title>
    <meta name="description" content="Free Image Hosting, Online image gallery of uploaded images" />
    <meta name="keywords" content="gallery, images, photos, image gallery, photo gallery, free image hosting"/>
    <meta name="robots" content="index,follow"/>
    <link href="http://pics.lt/favicon.ico" rel="icon" type="image/x-icon" />
    <link rel="alternate" type="application/rss+xml" title="CF Image Host Rss Feed" href="http://pics.lt/feed.php" />
    <link rel="stylesheet" href="http://pics.lt/themes/day5row/day5row.css?v=1.65" type="text/css" />
        
    <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-2925509-3']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</head>
<body id="gallery">
<div id="wrap">
    <div id="header" class="clear_both">
        <div id="logo">
            <h1><a href="http://pics.lt/index.php" title="CF Image Host PradЕѕia">CF Image Host</a></h1>
            <h2>Free CF Image Host</h2>
        </div>

        <div class="languages" onMouseOver="document.getElementById('language').style.display='block'" onMouseOut="document.getElementById('language').style.display='none'">
            <div class="lan_on"><span>Kalba :</span><img src="http://pics.lt/languages/lithuanian.png" width="23" height="15" alt="lithuanian" title="lithuanian" /></div>
            <div id="language" class="language" ><a href="http://pics.lt/index.php?lang=english" title="english" rel="nofollow"><img src="http://pics.lt/languages/english.png" alt="english" width="23" height="15" /></a> </div>
            <div class="clear_both"></div>
        </div>

            <div id="search">
            <form method="get" action="http://pics.lt/gallery.php">
                <input type="text" size="28" name="search" id="searchBox" class="text_input" onblur="if(this.value=='')value='Nuotraukos paieЕЎka';" onfocus="if(this.value=='Nuotraukos paieЕЎka')value=''" value="Nuotraukos paieЕЎka" /><input type="submit" value="IeЕЎkoti" class="button" />
            </form>
        </div>
            <div id="nav">
            <ul id="main-nav">  <li id="page_home"><a href="http://pics.lt/" title="PradЕѕia">PradЕѕia</a></li> <li id="page_gallery"><a href="http://pics.lt/gallery.php" title="Galerija">Galerija</a></li>   <li id="page_faq_page"><a href="http://pics.lt/faq.php" title="DUK">DUK</a></li>    <li id="page_tos_page"><a href="http://pics.lt/tos.php" title="Naudojimosi sД…lygos">Naudojimosi sД…lygos</a></li>    <li id="page_contact_page"><a href="http://pics.lt/contact.php" title="Kontaktai">Kontaktai</a></li></ul>       </div>
        <div class="clear_both"></div>
    </div>
    <div id="content">
<div id="msg"></div><h4 class="search">Sorry, No Results Found For <span class="search_for">Nuotraukos paieЕЎka</span></h4><p class="search_sug">Suggestions:<br/>Make sure all words in your query are spelled correctly<br/>Try a shorter query, or replace some keywords</p><div id="ImageWidget" class="boxpanel"></div>     <div class="clear_both"></div>
            </div>
    <div id="footer">
        <p>Copyright В© - All Rights Reserved.</p>
                    <div id="feed"><a href="http://pics.lt/feed.php" title="image Feed"><span>image Feed</span></a></div>
                <div class="sp"></div>
        <p>Powered By <a href="http://codefuture.co.uk/projects/imagehost/" title="Free PHP Image Hosting Script">CF Image Hosting script</a> | Design By <a href="http://codefuture.co.uk" title="codefuture.co.uk - online webmaster tools,code Generators">codefuture.co.uk</a></p>
    </div>
</div>

<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if necessary -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script>window.jQuery || document.write("<script src='js/jquery-1.7.1.min.js'>\x3C/script>")</script>
    <script type="text/javascript" src="http://pics.lt/js/user.js"></script>
    <script type="text/javascript">
            $(document).ready(function() {
                $('#ImageWidget').fadeOut('slow', function(){
                    $('#ImageWidget').load("http://pics.lt/cfajax.php",{widgit: 25}, function(){
                        $('#ImageWidget').fadeIn('slow');
                    });
                });
            });
        </script>
    <!--[if lt IE 7 ]>
        <script src="js/dd_belatedpng.js"></script>
        <script>DD_belatedPNG.fix("img, .png_bg"); // Fix any <img> or .png_bg bg-images. Also, please read goo.gl/mZiyb </script>
    <![endif]-->
</body>
</html>

Share this post


Link to post
Share on other sites
wakillon

I'm a bit late, but for those who are still interested, this way works.

#include <WinHTTP.au3>
#include <zlib.au3>

;~ http://pics.lt/index.php?lang=english

Global $sBoundary = '--' & _GenerateAlphaNumericRandomString ( 50 )

$sImagePath = FileOpenDialog ( 'Choose a pcture', @MyDocumentsDir, '(*.bmp; *.gif; *.png; *.jpg; *.jpeg ; *.psd)' ) ; Supported Image Formats: png, jpg, jpeg, bmp, psd, gif, animated gif.
If Not FileExists ( $sImagePath ) Then Exit
$sDirectLink = _PicsItUpload ( $sImagePath )
ConsoleWrite ( 'Direct Link : ' & $sDirectLink & @Crlf )
If $sDirectLink Then ShellExecute ( $sDirectLink )

Func _PicsItUpload ( $sImagePath )
    If FileGetSize ( $sImagePath ) > 10*1024*1024 Then Return -1 ; max 10 MB 
    Local $ReceivedData = Binary ( '' ), $chunk, $iExtended
    Local $hOpen = _WinHttpOpen ()
    Local $hConnect = _WinHttpConnect ( $hOpen, 'pics.lt' )
    Local $hRequest = _WinHttpOpenRequest ( $hConnect, 'POST', '/upload.php', 'HTTP/1.1' )
    _WinHttpAddRequestHeaders ( $hRequest, 'Referer: http://pics.lt/index.php?lang=english' )
    _WinHttpAddRequestHeaders ( $hRequest, 'Accept-Encoding: gzip, deflate' )
    Local $sDataToSend = _PicsItSetDataToSend ( $sImagePath )
    If Not @error Then
        _WinHttpAddRequestHeaders ( $hRequest, 'Content-Length: ' & StringLen ( $sDataToSend ) )
        Local $sContentType = 'Content-Type: multipart/form-data; boundary=' & StringTrimLeft ( $sBoundary, 2 )
        _WinHttpSendRequest ( $hRequest, $sContentType, $WINHTTP_NO_REQUEST_DATA, StringLen ( $sDataToSend ) )
        _UploadProgress ( $hRequest, $sImagePath, $sDataToSend )
        If Not @error Then
            _WinHttpReceiveResponse ( $hRequest )
            If _WinHttpQueryDataAvailable ( $hRequest ) Then
                While 1
                    $chunk = _WinHttpReadData ( $hRequest, 2, 1024 )
                    If Not @extended Then ExitLoop
                    $ReceivedData &= $chunk
                WEnd
                $ReceivedData = BinaryToString ( _ZLIB_GZUncompress ( $ReceivedData ), 1 )
            EndIf
        EndIf
    EndIf
    _WinHttpCloseHandle ( $hRequest )
    _WinHttpCloseHandle ( $hConnect )
    _WinHttpCloseHandle ( $hOpen )
    If $ReceivedData Then
        Local $aRet = StringRegExp ( $ReceivedData, '(?s)(?i)codedirect" value="(.*?)"', 3 )
        If Not @error Then Return $aRet[0]
    EndIf
EndFunc ;==> _PicsItUpload ()

Func _PicsItSetDataToSend ( $sFilePath )
    If Not FileExists ( $sFilePath ) Then Return SetError ( -1 )
    Local $hFile = FileOpen ( $sFilePath )
    If $hFile = -1 Then Return SetError ( 1, 0, 0 )
    Local $sData = FileRead ( $hFile )
    FileClose ( $hFile )
    Return $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="fileName[]"' & @CRLF & @CRLF & $sFilePath & @CRLF & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="file[]"; filename="' & _FileGetFullNameByFullPath ( $sFilePath ) & '"' & @CRLF & _
        'Content-Type: image/jpeg' & @CRLF & @CRLF & $sData & @CRLF & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="alt[]"' & @CRLF & @CRLF & _FileGetNameWithoutExtByFullPath ( $sFilePath ) & @CRLF & $sBoundary & @CRLF & _
        'Content-Disposition: form-data; name="submit"' & @CRLF & @CRLF & 'Upload' & @CRLF & $sBoundary
EndFunc ;==> _PicsItSetDataToSend ()

Func _UploadProgress ( $hRequest, $sPicPath, $sDataToSend )
    If Not FileExists ( $sPicPath ) Then Return SetError ( -1 )
    Local $sDatas = StringToBinary ( $sDataToSend )
    Local $iNumberOfBytesToSend = 1024
    Local $Bin, $iStart = 1, $iExtended = 0
    While 1
        $Bin = BinaryMid ( $sDatas, $iStart, $iNumberOfBytesToSend )
        If BinaryLen ( $Bin ) = 0 Then Return
        _WinHTTPWriteData ( $hRequest, $Bin, 1 )
        If Not @error Then
            $iExtended += @extended
            ConsoleWrite ( '+ $iPercent : ' & Round ( ( $iExtended  ) / ( StringLen ( $sDataToSend ) ) * 100, 2 ) & @Crlf )
            $iStart += $iNumberOfBytesToSend
        Else
            $Bin = 0
            Return SetError ( 1 )
        EndIf
    WEnd
EndFunc ;==> _UploadProgress ()

Func _FileGetNameWithoutExtByFullPath ( $sFullPath )
    Local $aPathSplit = StringSplit ( $sFullPath, '\' )
    If Not @error Then Return StringLeft ( $aPathSplit[UBound($aPathSplit)-1], StringInStr ( $aPathSplit[UBound($aPathSplit)-1], '.', 0, -1 ) - 1 )
EndFunc ;==> _FileGetNameWithoutExtByFullPath ()

Func _FileGetFullNameByFullPath ( $sFullPath )
    Local $aFileName = StringSplit ( $sFullPath, '\' )
    If Not @error Then Return $aFileName[$aFileName[0]]
EndFunc ;==> _FileGetFullNameByFullPath ()

Func _GenerateAlphaNumericRandomString ( $iLen )
    Local $sString = ''
    Do
        Switch Random ( 1, 3, 1 )
            Case 1
                $sString &= Chr ( Random ( 48, 57, 1 ) )  ; 0 to 9
            Case 2
                $sString &= Chr ( Random ( 65, 90, 1 ) )  ; A to Z
            Case 3
                $sString &= Chr ( Random ( 97, 122, 1 ) ) ; a to z
        EndSwitch
    Until StringLen ( $sString ) = $iLen
    Return $sString
EndFunc ;==> _GenerateAlphaNumericRandomString ()

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×