Jump to content

Youtube API To upload videos


 Share

Recommended Posts

I've been working on getting the Youtube API into Autoit specifically to make an uploader. I'm having trouble with this part- uploading the actual video file.

Link to the API:

http://code.google.com/apis/youtube/2.0/...l_direct_uploading.html#Direct_uploading

Code I'm trying:

youtube_test.au3

You'll need to change this line:

$auth_token = _YouTube_Login("", "", $Descriptor)

to have a correct username and password in the form of:

$auth_token = _YouTube_Login("Username", "Password", $Descriptor).

Also the developerkey is my personal one, so if you plan on using this code for you own project, get your own.

Sorry if its massively long and makes no sense... >_<

Ideas?

Cheers,

Brett

Edited by BrettF
Link to comment
Share on other sites

I don't have time to take a close look, but here's a possible error:

When you're including the binary into the request you're just conjugating it with the '&' operator, this will the binary look like this:

"0xDEADBEEF" while I guess youtube wants it like this: "DEADBEEF".

Just a guess.

Edit: Btw, your avatar aint working.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Tried that and nothing... >_<

New function is:

Func _YouTube_Upload($auth_token, $developer_key, $szPath, $sXML)
    If $internet == 0 Then
        MsgBox(0, "Error", "Setup Error")
    EndIf

    $boundary_string = _RandString(8)
    $file_name = StringRight($szPath, StringLen($szPath) - StringInStr($szPath, "\", 0, -1))
    $ext = StringRight ($file_name, StringLen ($file_name) - StringInStr ($file_name, ".", 1, -1))
    MsgBox (0, "", $ext)

    $file_mime = _FIleGetMimeType($ext)
    If $file_mime = -1 Then $file_mime = "application/octet-stream"

    $fHandle = FileOpen($szPath, 16)
    $file_binary = FileRead($fHandle)
    FileClose($fHandle)

    $content = "--" & $boundary_string & @CRLF
    $content &= "Content-Type: application/atom+xml; charset=UTF-8" & @CRLF
    $content &= @CRLF
    $content &= $sXML & @CRLF
    $content &= "--" & $boundary_string & @CRLF
    $content &= "Content-Type: " & $file_mime & @CRLF
    $content &= "Content-Transfer-Encoding: binary" & @CRLF
    $content &= @CRLF
    $content &= StringTrimLeft ($file_binary, 2) & @CRLF
    $content &= "--" & $boundary_string & "--" & @CRLF
    $content &= @CRLF

    $length = StringLen($content)

    $header = "Authorization: AuthSub token=""" & $auth_token & """" & @CRLF
    $header &= "GData-Version: 2" & @CRLF
    $header &= "X-GData-Key: key=" & $developer_key & @CRLF
    $header &= "Slug: " & $file_name & @CRLF
    $header &= "Content-Type: multipart/related; boundary=""" & $boundary_string & """" & @CRLF
    $header &= "Content-Length: " & $length & @CRLF
    $header &= "Connection: close" & @CRLF & @CRLF

    $host = "uploads.gdata.youtube.com"
    $internetconnect = _WinINet_InternetConnect($internet, $INTERNET_SERVICE_HTTP, $host, 443)
    If @error Then MsgBox(0, "Error", "Error 2")

    $httprequest = _WinINet_HttpOpenRequest($internetconnect, "POST", "/feeds/api/users/default/uploads", $INTERNET_FLAG_SECURE)

    $addheader = _WinINet_HttpAddRequestHeaders($httprequest, $header, $HTTP_ADDREQ_FLAG_ADD)

    $sendrequest = _WinINet_HttpSendRequest($httprequest, Default, StringToBinary ($content))

    Local $readfile = Binary("")
    Do
        $readfile &= _WinINet_InternetReadFile($httprequest, 5000)
    Until @error <> 0 Or Not @extended

    $ret = BinaryToString($readfile)
    _WinINet_InternetCloseHandle($internetconnect)
    Return $ret
EndFunc   ;==>_YouTube_Upload

It seems that the _WinINet_HttpSendRequest line is failing. _WinAPI_GetLastError() is returning 0- I'm not sure what that means...

EDIT: OH THANKS! I decided to add a redirect from http://signa5.com to http://www.signa5.com... seemed to have missed that :( CHEERS!

Edited by BrettF
Link to comment
Share on other sites

Im working on the same thing, figured id first check forum to see if theres something about it yet, but its all downloaders nothing about this.

I only just finnished the login bit >_<

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$oHTTP.Open("POST", "https://www.google.com/youtube/accounts/ClientLogin" , False)
$oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
$oHTTP.Send("Email=USERNAME=PASSWORD&service=youtube&source=Upload")
$oReceived = $oHTTP.ResponseText
;checking if its working
MsgBox(0, 0, $oReceived)

Anyways, will post here also if find a working solution or notice why yours isnt working. =]

oh and BUMP

Edited by Hellstrong
Link to comment
Share on other sites

  • 3 months later...
  • 2 years later...

Hope you don´t mind that I revive this topic. But I also don´t get my Youtube Uploader to work and I guess it´s for the same reason BrettF failed. (At first, because he managed to get it running, see )

I have 2 problems at the moment and I guess both have the same source: The ANSII - UTF-8 encoding.

I tried several versions of the YouTube API in hope that one would work flawless. But sofaso farave 2 Versions of my uploader. One uses Browser based Upload (https://developers.google.com/youtube/2.0/developers_guide_protocol_browser_based_uploading) the other Resumable Upload (https://developers.google.com/youtube/2.0/developers_guide_protocol_resumable_uploads)

Both programs LogIn via oAuth.

Problems with the Browser based Upload

This program works fine, till it has to renew its accesstoken via the refreshtoken. The Post response from youtube is: error : invalid_grant

I did some research and it seems that the problem is relayed to the mentioned encoding.

See some references:

http://stackoverflow.com/questions/8433990/when-authenticating-with-oauth-and-youtube-always-get-error-invalid-grant-on

https://groups.google.com/forum/#!searchin/oauth2-dev/invalid_grant/oauth2-dev/eaOa6THER0k/z4eO-taUFxgJ

It seems like the Data i´m Iassing to Youtube must be URLEncoded. So my question is: How do i doIthat with AutoIt?

Problems with Resumable Upload

This Program works so far, that a File is Uploaded to youtube (Source File is an .Avi). Youtube recireceives XML which define things like the Name and DiscDescription properly assiassignt to the Uploaded file. Unfortunately, youtube dispdisplays "Upload abgebrochen" (Upload CancCanceledwhen i´m Iogged in my Youtube account to check my recently Uploaded videos.

I guess the Problem again, is wrong encoding. Youtube expects a file in Binary-Utf8 and I feed it....well I´m not perfectly sure.

I open the File as Binary:

$Dateihwnd = FileOpen("Movie.avi",16)

$binaryRead = FileRead($Dateihwnd)

and tried hundhundredferent combinations including binary(), stringtobinary, binarytostring and so on. All with the same result->Upload Canceled.

Since this is my first Post, i apIlogize if i caIe in confconflicth the autoscript terms of proper behabehaviorso I´m very (very very) sorry for my grammar. I´m german but(!) I used online spellcheck...

I really hope you guys (BrettF and MiserableLife) can help me by sharing your solution. That problem consumed till now way too much of my free time and gave me headaches... :)

Edited by stereospeaker
Link to comment
Share on other sites

  • Moderators

stereospeaker,

Welcome to the AutoIt forum. :)

Could I just point out that BrettF has not been online for nearly a year so I would not expect an answer any time soon! :D

In general we frown on posting in threads as old as this one - mainly because the language has changed a lot over the years and as a result the code may no longer be correct, or even needed. So please do not make a habit of it in future. ;)

i apIlogize if i caIe in confconflicth the autoscript terms of proper behabehavior

No need to apologise - but for future reference the Forum Rules are here. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you for the quick response Melba23.

To bad BrettF is not longer active. I was sure he has the key to this problem...

So would you suggest that I close this topic and start a new one regarding my Issuses with the Youtube API? Or shall i wait a few days to see if someone posts something helpfull here?

Link to comment
Share on other sites

  • Moderators

stereospeaker,

As the thread is now on the first page, wait a few days and see if you get any replies. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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