Jump to content

Recommended Posts

Posted (edited)

Hello everyone...

I've been writing code to upload my videos to YouTube automatically but

I don't understand what some of the header means...

Content-Length: <content_length> [solved]

Which part of the POST should I start counting?

The size that puts into $obj.Send()

WWW.W3.ORG

<Binary File Data>

What happens if I want to send the data separately? How do I do that?

From Google Code :

POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: AuthSub token="<authentication_token>"
GData-Version: 2
X-GData-Key: key=<developer_key>
Slug: <video_filename>
Content-Type: multipart/related; boundary="<boundary_string>"
Content-Length: <content_length>
Connection: close

--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8

API_XML_request
--<boundary_string>
Content-Type: <video_content_type>
Content-Transfer-Encoding: binary

<Binary File Data>
--<boundary_string>--

Here's my half-finished function

Func UploadVid($username, $token, $title, $des, $keywd, $filepath)
    $url = "http://uploads.gdata.youtube.com/feeds/api/users/"& $username &"/uploads"
    $filename = StringSplit($filepath,'\')
    $filename = $filename[$filename[0]]
    $boundaryStr = '91C1C186'

    $data = "--"& $boundaryStr & @LF
    $data &="Content-Type: application/atom+xml; charset=UTF-8"& @LF
    $tmp_f = FileRead(@ScriptDir & '\upload.xml')
    $tmp_f = StringReplace($tmp_f, '---Title---',$title)
    $tmp_f = StringReplace($tmp_f, '---description---',$des)
    $tmp_f = StringReplace($tmp_f, '---KEYWORD---',$keywd)
    $data &= $tmp_f & @LF
    $data &= "--"& $boundaryStr & @LF
    $data &= "Content-Type: video/mpeg"& @LF
    $data &= "Content-Transfer-Encoding: binary"& @LF
    $hFile = FileOpen($filepath, 16)
    $data &= FileRead($hFile)
    FileClose($hFile)
    $data &= "--"& $boundaryStr &"--"

    $obj = ObjCreate ("WinHttp.WinHttpRequest.5.1")
    $obj.Open("POST", $URL, false)
    $obj.SetRequestHeader("Authorization","GoogleLogin "& $token)
    $obj.SetRequestHeader("GData-Version","2")
    $obj.SetRequestHeader("X-GData-Key","key=" & $dev_key)
    $obj.SetRequestHeader("Slug","application/x-www-form-urlencoded")
    $obj.SetRequestHeader("Content-Type","multipart/related; boundary=" & $boundaryStr)
    $obj.SetRequestHeader("Content-Length","")
    $obj.SetRequestHeader("Connection","close")
    $obj.Send($data)
EndFunc
Edited by MiserableLife
Posted (edited)

Can someone give me an example on DllCall() with this WinAPI function,please?

WinHttpOpen Function

Edit:

Besides the return type, am I doing this right?

Should I put HANDLE in HINTERNET?

MSDN - HINTERNET

DllCall("Winhttp.dll","HINTERNET","WinHttpOpen", _
"wstr", $userAgent, "DWORD", $AccessType, _
"wstr", $ProxyName, "wstr", $ProxyBypass, "DWORD", $Flags)
Edited by MiserableLife
Posted (edited)

Could some body please help me here?

I've made the code to upload the file but the server gives me "406 Not Acceptable", what to do?

I already made sure that my headers and my bodies are correct(including new lines).

Now I'm just not sure if my parameters are correct in the functions.

Please do help me, I just need this one more step to complete. :(:) :) ;):D

Edit: attachment remove (I'll open a new post about this Youtube Uploader when I'm finnish)

Edited by MiserableLife
Posted

:( Problem found!!!

After doing some more search on Google... I managed to capture my package..

when I first saw my package,I was thinking....why "Accept:" is in my header. I haven't insert that into my script.

and now, I am sure it has something to do with my "406 - Not Acceptable" error!

:) :) ;) why is this happening :DB):) :)

POST /feeds/api/users/default/uploads HTTP/1.1
Accept: 
Authorization: GoogleLogin Auth=DQAAAJsAAACXPl3r8sHrxJqmoygNIuzcVRiSl7QyfAIt7n9caAxi5mPgMbpMo3fZLWaWxVxwZkaFCD4WKTAbRt106_XMu-xIFm1xooNRjeoaoI94bJQpFbDYtbwg2FbZMrl32d3zgA2LNtxNQnT-f9i6FSQkqkaIL6D2dncoW0X-gukY7rpPFG0COSO063GlxyNqSZBYfOoY5nOcQIOHM7m3mXyvJPDe
GData-Version: 2
X-GData-Key: key=AI39si5XOGX3DxWiELQJf_-36sJB4MEWPcF4LjtUSh711r541DfHMNr771t4Q8eIiOv_ePhEGkbAc0hTEJzHF7O6OBUX-I8Y1Q
Slug: MassEffect2.mp4
Content-Type: multipart/related; boundary="boundary"
Content-Length: 10550
Connection: close
User-Agent: Test
Host: uploads.gdata.youtube.com


--boundary
Content-Type: application/atom+xml; charset=UTF-8


<entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><media:group><media:title type="plain">Test upload</media:title><media:description type="plain">Just a upload test. Nothing to watch.</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:keywords>Upload</media:keywords></media:group></entry>
--boundary
Content-Type: video/mp4
Content-Transfer-Encoding: binary


masseffect2.mp4_in_binary
--boundary--
Posted (edited)

YES !!!!! I see my new video uploaded in youtube.com.

replace line 42 with

$Main_header = 'Accept: text/*' & @CRLF & _

Edit: = =" I for got to say.I added $WINHTTP_ADDREQ_FLAG_ADD to _WinHttpAddRequestHeaders().Sorry~

Edited by MiserableLife
Posted

YES !!!!! I see my new video uploaded in youtube.com.

replace line 42 with

$Main_header = 'Accept: text/*' & @CRLF & _

Edit: = =" I for got to say.I added $WINHTTP_ADDREQ_FLAG_ADD to _WinHttpAddRequestHeaders().Sorry~

You should post in examples.

♡♡♡

.

eMyvnE

  • 3 months later...

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...