Skip to content
Browse files

First commit

  • Loading branch information...
0 parents commit a6a7538a2eda39e207357925b74b48a0287387c5 @ahmednuaman committed Sep 1, 2009
Showing with 550 additions and 0 deletions.
  1. +18 −0 .actionScriptProperties
  2. +2 −0 .flexProperties
  3. +25 −0 .project
  4. +3 −0 .settings/org.eclipse.core.resources.prefs
  5. +1 −0 debug
  6. +278 −0 src/App.mxml
  7. +44 −0 src/auth-response.html
  8. +125 −0 src/index.html
  9. +5 −0 src/server.rb
  10. +5 −0 src/styles.css
  11. +44 −0 src/upload-response.html
18 .actionScriptProperties
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<actionScriptProperties mainApplicationPath="App.mxml" version="3">
+ <compiler additionalCompilerArguments="-locale en_US" copyDependentFiles="true" enableModuleDebug="true" generateAccessible="false" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="false" htmlPlayerVersion="9.0.124" htmlPlayerVersionCheck="false" outputFolderPath="debug" sourceFolderPath="src" strict="true" useApolloConfig="false" verifyDigests="true" warn="true">
+ <compilerSourcePath>
+ <compilerSourcePathEntry kind="1" linkType="1" path="/Volumes/Sites/__Useful Stuff/Flash/AS3_OS"/>
+ </compilerSourcePath>
+ <libraryPath defaultLinkType="1">
+ <libraryPathEntry kind="4" path=""/>
+ <libraryPathEntry kind="1" linkType="1" path="libs"/>
+ </libraryPath>
+ <sourceAttachmentPath/>
+ </compiler>
+ <applications>
+ <application path="App.mxml"/>
+ </applications>
+ <modules/>
+ <buildCSSFiles/>
+</actionScriptProperties>
2 .flexProperties
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<flexProperties flexServerType="0" toolCompile="true" useServerFlexSDK="false" version="1"/>
25 .project
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>_ahmednuaman.com YouTube Auth and Upload</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.adobe.flexbuilder.project.flexbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.adobe.flexbuilder.project.flexnature</nature>
+ <nature>com.adobe.flexbuilder.project.actionscriptnature</nature>
+ </natures>
+ <linkedResources>
+ <link>
+ <name>[source path] AS3_OS</name>
+ <type>2</type>
+ <location>/Volumes/Sites/__Useful Stuff/Flash/AS3_OS</location>
+ </link>
+ </linkedResources>
+</projectDescription>
3 .settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Fri Aug 28 16:24:49 BST 2009
+eclipse.preferences.version=1
+encoding/<project>=utf-8
1 debug
@@ -0,0 +1 @@
+Subproject commit 347dd23913ed3eb6dbfb7139d8dfa606843f307b
278 src/App.mxml
@@ -0,0 +1,278 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" creationComplete="init()">
+
+ <mx:Script>
+ <![CDATA[
+
+ import com.firestartermedia.lib.as3.events.DataServiceEvent;
+ import com.firestartermedia.lib.as3.data.XMLDataService;
+
+ import mx.collections.ArrayCollection;
+ import mx.rpc.events.ResultEvent;
+ import mx.rpc.http.mxml.HTTPService;
+
+ [Bindable]
+ private var videoCategories:ArrayCollection;
+
+ private var browser:FileReference;
+ private var dataToken:String;
+ private var uploadToken:String;
+ private var uploadURL:String;
+
+ private function init():void
+ {
+ Security.loadPolicyFile( 'http://gdata.youtube.com/crossdomain.xml' );
+
+ loadVideoCategories();
+ }
+
+ private function loadVideoCategories():void
+ {
+ var service:XMLDataService = new XMLDataService();
+
+ service.addEventListener( DataServiceEvent.READY, handleVideoCategories );
+
+ service.send( 'http://gdata.youtube.com/schemas/2007/categories.cat' );
+ }
+
+ private function handleVideoCategories(e:DataServiceEvent):void
+ {
+ var data:XML = e.data as XML;
+ var categories:Array = [ ];
+
+ for each ( var category:XML in data..*::category )
+ {
+ categories.push( category.@term.toString() );
+ }
+
+ videoCategories = new ArrayCollection( categories );
+ }
+
+ private function handleLoginButtonClicked():void
+ {
+ ExternalInterface.addCallback( 'handleLoginComplete', handleLoginComplete );
+ ExternalInterface.addCallback( 'handleUploadComplete', handleUploadComplete );
+
+ ExternalInterface.call( 'doLogin' );
+ }
+
+ public function handleLoginComplete(token:String):void
+ {
+ dataToken = token;
+
+ stack.selectedIndex = 1;
+ }
+
+ private function sendVideoData():void
+ {
+ var service:HTTPService = new HTTPService();
+
+ service.contentType = 'application/atom+xml; charset=UTF-8';
+ service.headers[ 'Authorization' ] = 'AuthSub token="' + dataToken + '"';
+ service.headers[ 'GData-Version' ] = 2;
+ service.headers[ 'X-GData-Key' ] = 'key=ADD_YOUR_KEY_HERE';
+ service.method = 'POST';
+ service.request = '<?xml version="1.0"?><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">' + videoTitle.text + '</media:title><media:description type="plain">' + videoDescription.text
+ + '</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">' + ComboBox( videoCategory ).selectedItem.toString()
+ + '</media:category><media:keywords>' + videoKeywords.text + '</media:keywords></media:group></entry>';
+ service.resultFormat = 'e4x';
+ service.url = 'http://gdata.youtube.com/action/GetUploadToken';
+
+ service.addEventListener( ResultEvent.RESULT, handleVideoDataResult );
+
+ service.send();
+ }
+
+ private function handleVideoDataResult(e:ResultEvent):void
+ {
+ var data:XML = e.result as XML;
+
+ uploadToken = data..token;
+ uploadURL = data..url;
+
+ stack.selectedIndex = 2;
+
+ ExternalInterface.call( 'showUpload', uploadURL, uploadToken );
+ }
+
+ /* private function browseForFile():void
+ {
+ if ( !browser )
+ {
+ browser = new FileReference();
+
+ browser.addEventListener( Event.SELECT, handleFileSelected );
+ browser.addEventListener( ProgressEvent.PROGRESS, handleFileUploadProgress );
+ //browser.addEventListener( DataEvent.UPLOAD_COMPLETE_DATA, handleFileUploaded );
+ }
+
+ browser.browse();
+
+ videoUploadMessage.text = '';
+ }
+
+ private function handleFileSelected(e:Event):void
+ {
+ videoUploadMessage.text = browser.name;
+
+ videoUploadButton.visible = true;
+ }
+
+ private function handleFileUploadProgress(e:ProgressEvent):void
+ {
+ videoUploadProgress.maximum = e.bytesTotal;
+ videoUploadProgress.minimum = 0;
+
+ videoUploadProgress.setProgress( e.bytesLoaded, e.bytesTotal );
+
+ if ( e.bytesLoaded === e.bytesTotal )
+ {
+ handleFileUploaded();
+ }
+ }
+
+ private function handleFileUploaded(e:DataEvent=null):void
+ {
+ stack.selectedIndex = 4;
+ } */
+
+ private function uploadFile():void
+ {
+ /* var request:URLRequest = new URLRequest();
+ var vars:URLVariables = new URLVariables();
+
+ vars.token = uploadToken;
+
+ request.data = vars;
+ request.method = URLRequestMethod.POST;
+ request.url = uploadURL + '?nexturl=http://localhost:9852/upload-response.html';
+
+ browser.upload( request, 'file' ); */
+
+ ExternalInterface.call( 'doUpload' );
+
+ stack.selectedIndex = 3;
+ }
+
+ public function handleUploadComplete(videoId:String):void
+ {
+ videoUploadMessage.text = 'Your video has been upload and the id is: ' + videoId;
+
+ stack.selectedIndex = 4;
+ }
+
+ ]]>
+ </mx:Script>
+
+ <mx:Style source="styles.css" />
+
+ <mx:ViewStack id="stack" width="100%" height="100%" creationPolicy="all">
+ <mx:Box width="100%" height="100%">
+ <mx:Button id="loginButton" label="Click here to log in to YouTube" click="handleLoginButtonClicked()" />
+
+ </mx:Box>
+
+ <mx:Box width="100%" height="100%">
+ <mx:Grid>
+ <mx:GridRow>
+ <mx:GridItem>
+ <mx:Text text="Title" />
+
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:TextInput id="videoTitle" text="" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ <mx:GridRow>
+ <mx:GridItem>
+ <mx:Text text="Description" />
+
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:TextInput id="videoDescription" text="" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ <mx:GridRow>
+ <mx:GridItem>
+ <mx:Text text="Keywords" />
+
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:TextInput id="videoKeywords" text="" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ <mx:GridRow>
+ <mx:GridItem>
+ <mx:Text text="Category" />
+
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:ComboBox id="videoCategory" dataProvider="{videoCategories}" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ <mx:GridRow>
+ <mx:GridItem>
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:Button label="Submit" click="sendVideoData()" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ </mx:Grid>
+
+ </mx:Box>
+
+ <mx:Box width="100%" height="100%">
+ <!--<mx:Grid>
+ <mx:GridRow>
+ <mx:GridItem>
+ <mx:Button label="Browse for video..." id="videoUploadBrowseButton" click="browseForFile()" />
+
+ </mx:GridItem>
+
+ <mx:GridItem>
+ <mx:Text id="videoUploadMessage" />
+
+ </mx:GridItem>
+
+ </mx:GridRow>
+
+ </mx:Grid>-->
+
+ <mx:Button label="Upload this video" id="videoUploadButton" click="uploadFile()" />
+
+ </mx:Box>
+
+ <mx:Box width="100%" height="100%">
+ <mx:ProgressBar id="videoUploadProgress" width="300" indeterminate="true" />
+
+ </mx:Box>
+
+ <mx:Box width="100%" height="100%">
+ <mx:Text id="videoUploadMessage" />
+
+ </mx:Box>
+
+ </mx:ViewStack>
+
+</mx:Application>
44 src/auth-response.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <script type="text/javascript">
+ <!--
+ function getURLVar(name)
+ {
+ name = name.replace( /[\[]/, '\\\[' ).replace( /[\]]/ , '\\\]' );
+
+ var regexS = '[\\?&]' + name + '=([^&#]*)';
+ var regex = new RegExp( regexS );
+ var results = regex.exec( window.location.href );
+
+ if ( results == null )
+ {
+ return '';
+ }
+ else
+ {
+ return results[1];
+ }
+ }
+
+ function getToken()
+ {
+ var token = getURLVar( 'token' );
+
+ return token;
+ }
+ -->
+ </script>
+ <title>Auth Response</title>
+</head>
+<body>
+ Please wait...
+
+ <script type="text/javascript">
+ <!--
+ parent.handleLogin( getToken() );
+ -->
+ </script>
+</body>
+</html>
125 src/index.html
@@ -0,0 +1,125 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--
+/**
+ * @author Ahmed Nuaman (http://www.ahmednuaman.com)
+ * @langversion 1.1
+ *
+ * This work is licenced under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License.
+ * To view a copy of this licence, visit http://creativecommons.org/licenses/by-sa/2.0/uk/ or send a letter
+ * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
+*/
+-->
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <script type="text/javascript" src="http://www.google.com/jsapi"></script>
+ <script type="text/javascript">
+ <!--
+ var flash;
+
+ function embedFlash()
+ {
+ $('#uploadDiv').hide();
+ $('#youtubeIframe').hide();
+
+ swfobject.embedSWF( 'App.swf', 'flash', '100%', '500', '9.0.0' , '', { }, { 'menu': 'false' }, { 'id': 'flashApp' } );
+
+ flash = document.getElementById( 'flashApp' );
+ }
+
+ function doLogin()
+ {
+ $('#youtubeAuthForm').submit();
+
+ $('#youtubeIframe').show();
+ }
+
+ function handleLogin(token)
+ {
+ $('#youtubeIframe').hide();
+
+ flash.handleLoginComplete( token );
+ }
+
+ function showUpload(url, token)
+ {
+ $('#uploadDiv').show();
+
+ $('#youtubeUploadForm').attr( 'action', url + '?nexturl=http://localhost:9852/upload-response.html' );
+
+ $('#youtubeUploadForm input[name=token]').val( token );
+ }
+
+ function doUpload()
+ {
+ $('#uploadDiv').hide();
+
+ $('#youtubeUploadForm').submit();
+
+ $('#youtubeIframe').show();
+ }
+
+ function handleUpload(videoId)
+ {
+ $('#youtubeIframe').hide();
+
+ flash.handleUploadComplete( videoId );
+ }
+
+ google.setOnLoadCallback( embedFlash );
+
+ google.load( 'jquery', '1' );
+ google.load( 'swfobject', '2' );
+ -->
+ </script>
+ <style type="text/css" media="screen">
+ <!--
+ html, body
+ {
+ margin: 0;
+ padding: 0;
+ width: 100%;
+ height: 100%;
+ }
+ .hide
+ {
+ display: none;
+ visibility: hidden;
+ }
+ #uploadDiv
+ {
+ position: absolute;
+ display: block;
+ top: 100px;
+ width: 100%;
+ text-align: center;
+ }
+ #youtubeIframe
+ {
+ position: absolute;
+ top: 0;
+ }
+ -->
+ </style>
+ <title>YouTube Auth Test</title>
+</head>
+<body>
+ <div id="flash"></div>
+
+ <form id="youtubeAuthForm" action="https://www.google.com/accounts/AuthSubRequest" method="post" target="youtubeIframe" class="hide">
+ <input type="hidden" name="next" value="http://localhost:9852/auth-response.html" />
+ <input type="hidden" name="scope" value="http://gdata.youtube.com" />
+ <input type="hidden" name="session" value="0" />
+ <input type="hidden" name="secure" value="0" />
+ </form>
+
+ <div id="uploadDiv">
+ <form id="youtubeUploadForm" action="" method="post" enctype="multipart/form-data" target="youtubeIframe">
+ <input type="file" name="file" value="" />
+ <input type="hidden" name="token" value="" />
+ </form>
+ </div>
+
+ <iframe name="youtubeIframe" id="youtubeIframe" width="100%" height="500"></iframe>
+</body>
+</html>
5 src/server.rb
@@ -0,0 +1,5 @@
+require 'webrick'
+
+@server = WEBrick::HTTPServer.new :Port => 9852, :DocumentRoot => File.dirname(__FILE__)
+trap("INT"){ @server.shutdown }
+@server.start
5 src/styles.css
@@ -0,0 +1,5 @@
+Box
+{
+ horizontalAlign: center;
+ verticalAlign: middle;
+}
44 src/upload-response.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <script type="text/javascript">
+ <!--
+ function getURLVar(name)
+ {
+ name = name.replace( /[\[]/, '\\\[' ).replace( /[\]]/ , '\\\]' );
+
+ var regexS = '[\\?&]' + name + '=([^&#]*)';
+ var regex = new RegExp( regexS );
+ var results = regex.exec( window.location.href );
+
+ if ( results == null )
+ {
+ return '';
+ }
+ else
+ {
+ return results[1];
+ }
+ }
+
+ function getVideoId()
+ {
+ var token = getURLVar( 'id' );
+
+ return token;
+ }
+ -->
+ </script>
+ <title>Upload Response</title>
+</head>
+<body>
+ Please wait...
+
+ <script type="text/javascript">
+ <!--
+ parent.handleUpload( getVideoId() );
+ -->
+ </script>
+</body>
+</html>

0 comments on commit a6a7538

Please sign in to comment.
Something went wrong with that request. Please try again.