[xiph-commits] r15217 - in trunk/oggPusher: . firefox-extension/chrome/content

nithin at svn.xiph.org nithin at svn.xiph.org
Thu Aug 28 17:04:17 PDT 2008


Author: nithin
Date: 2008-08-28 17:04:16 -0700 (Thu, 28 Aug 2008)
New Revision: 15217

Modified:
   trunk/oggPusher/firefox-extension/chrome/content/op_Window.js
   trunk/oggPusher/firefox-extension/chrome/content/op_Window.xul
   trunk/oggPusher/oggPusher.xpi
Log:
Recognizes if input is ogg or not.
If ogg Jst uploads, If not first transcodes and then uploads
Problem with file consisting of spaces.


Modified: trunk/oggPusher/firefox-extension/chrome/content/op_Window.js
===================================================================
--- trunk/oggPusher/firefox-extension/chrome/content/op_Window.js	2008-08-28 18:27:16 UTC (rev 15216)
+++ trunk/oggPusher/firefox-extension/chrome/content/op_Window.js	2008-08-29 00:04:16 UTC (rev 15217)
@@ -1,4 +1,4 @@
-var opwindowCommon={leafName:null, timer:null,isOgg:null,
+var opwindowCommon={leafName:null, timer:null,isOgg:null,targetPathToUpload:null,
 	openFileWindowDialog:function()
     {
 		//alert("Inside openFileWindowDialog");
@@ -6,7 +6,11 @@
            	const nsIFilePicker = Components.interfaces.nsIFilePicker;
 			var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
         	fp.init(window, "Choose a File", nsIFilePicker.modeOpen);
-           	fp.appendFilters(nsIFilePicker.filterAll | nsIFilePicker.filterText);
+           	fp.appendFilters(nsIFilePicker.filterAll );
+            fp.appendFilter("Video Files","*.mpeg;*.mpg;*.avi;*.asf;*.flv;*.mov;*.mkv;*.wmv");
+            fp.appendFilter("Audio Files","*.mp3;*.wma");
+            fp.appendFilter("Free Format","*.ogg;*.ogv;*.oga;*.ogx")
+            //fp.appendFilter("mpg","*.mpg");
 		}	
 		catch(err){
 			alert(err);
@@ -20,12 +24,23 @@
             //alert(fp.file.leafName);
             this.leafName = fp.file.leafName;
 			parent.document.getElementById("file-path").value = path;
+            this.isOggFormat();
             this.appendActionButton();    
             
         }
         
     },
     isOggFormat:function(){
+        var file_name = document.getElementById("file-path").value;
+        var _1 = file_name.lastIndexOf('.');
+        var file_extension = file_name.substr(_1 + 1);
+        if( file_extension == "ogg" || file_extension == "ogx" || file_extension == "ogv" || file_extension == "oga")
+        {
+            this.isOgg = true;
+            this.targetPathToUpload = file_name;
+        }else{
+            this.isOgg = false;        
+        }
         
     },
     appendActionButton:function(){
@@ -34,19 +49,62 @@
         
         var actionButton = document.getElementById("action-button");
         if(actionButton == null){
-            actionButton = document.createElement("button");
-            actionButton.setAttribute("id","action-button");
-            actionButton.setAttribute("oncommand","actionButtonHandler();");
-            actionButton.setAttribute("image","chrome://oggPusher/content/images/xiph.ico");
-            actionButton.setAttribute("orient","vertical");
-            actionButton.setAttribute("label","Upload Audio/Video");
-            hboxParent.appendChild(actionButton);
+            if(this.isOgg){        
+                actionButton = document.createElement("button");
+                actionButton.setAttribute("id","action-button");
+                actionButton.setAttribute("oncommand","opwindowCommon.actionButtonHandler();");
+                actionButton.setAttribute("image","chrome://oggPusher/content/images/xiph.ico");
+                actionButton.setAttribute("orient","vertical");
+                actionButton.setAttribute("label","Upload Audio/Video");
+                hboxParent.appendChild(actionButton);
+            }
+            else
+            {
+                actionButton = document.createElement("button");
+                actionButton.setAttribute("id","action-button");
+                actionButton.setAttribute("oncommand","opwindowCommon.actionButtonHandler();");
+                actionButton.setAttribute("image","chrome://oggPusher/content/images/xiph.ico");
+                actionButton.setAttribute("orient","vertical");
+                actionButton.setAttribute("label","Transcode & Upload");
+                hboxParent.appendChild(actionButton);
+                
+            }
         }
+        else
+        {
+            hboxParent.removeChild(actionButton);
+            if(this.isOgg){        
+                actionButton = document.createElement("button");
+                actionButton.setAttribute("id","action-button");
+                actionButton.setAttribute("oncommand","opwindowCommon.actionButtonHandler();");
+                actionButton.setAttribute("image","chrome://oggPusher/content/images/xiph.ico");
+                actionButton.setAttribute("orient","vertical");
+                actionButton.setAttribute("label","Upload Audio/Video");
+                hboxParent.appendChild(actionButton);
+            }
+            else
+            {
+                actionButton = document.createElement("button");
+                actionButton.setAttribute("id","action-button");
+                actionButton.setAttribute("oncommand","opwindowCommon.actionButtonHandler();");
+                actionButton.setAttribute("image","chrome://oggPusher/content/images/xiph.ico");
+                actionButton.setAttribute("orient","vertical");
+                actionButton.setAttribute("label","Transcode & Upload");
+                hboxParent.appendChild(actionButton);
+                
+            }
+                
+        }
     },
     actionButtonHandler:function(){
-        
-        
-        
+        if(this.isOgg){
+            this.uploadFile();
+        }
+        else{
+            this.convertToTheora();
+            
+                   
+        }
     },
 	chooseDestination:function()
 	{
@@ -73,6 +131,7 @@
                         this.timer = setTimeout( function(el) { return function(){el.processHandler(process);}}(this), 10000 );
                 }else{
                         alert("done with transcoding");
+                        this.uploadFile();
                 }
     },
 	convertToTheora:function()
@@ -80,25 +139,29 @@
 		var data="";
 		try{
 			// the extension's id from install.rdf
-			 var MY_ID = "oggPusher at xiph.org";
-			 var em = Components.classes["@mozilla.org/extensions/manager;1"].
+			var MY_ID = "oggPusher at xiph.org";
+			var em = Components.classes["@mozilla.org/extensions/manager;1"].
 			          getService(Components.interfaces.nsIExtensionManager);
-			 // the path may use forward slash ("/") as the delimiter
-			 var file = em.getInstallLocation(MY_ID).getItemFile(MY_ID, "chrome/content/sample");
-			  // returns nsIFile for the extension's install.rdf
+			// the path may use forward slash ("/") as the delimiter
+			var file = em.getInstallLocation(MY_ID).getItemFile(MY_ID, "chrome/content/sample");
+			// returns nsIFile for the extension's install.rdf
 			var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess);
 			process.init(file);
-			alert(file.fileSize);
-			alert(file.permissions);
 			file.permissions = 0755;
-			alert(file.permissions);
-	 		var args_list = new Array(3);
-                	args_list[0] =  " -o "
-			args_list[1] = document.getElementById("target-path").value+"/"+this.leafName+".ogg " 
-			args_list[2] = document.getElementById("file-path").value ;
-			//alert(args_list[0]);
-	                alert("Before process.run");
-        	        alert(process.run(false,args_list, args_list.length));
+			var args_list = new Array(3);
+           	args_list[0] = " -o ";
+            var _1 = this.leafName.lastIndexOf('.');
+            var _2 = this.leafName.substr(0,_1);
+            //alert("_2"+ _2);
+            var _3 = _2.replace(/\s/g,'\\ ');
+            //alert("_3"+_3);
+			args_list[1] = "/tmp/"+_3+".ogv " ;
+            //alert(args_list[1]);
+            this.targetPathToUpload = "/tmp/"+_3 +".ogv";
+			args_list[2] = document.getElementById("file-path").value.replace(/\s/g,'\\ ');
+			//alert(args_list[2]);
+	         //alert("Before process.run");
+        	 alert(process.run(false,args_list, args_list.length));
 			//alert("Pid "+process.pid+" exit value "+process.exitValue+" Location "+process.location+" processName "+process.processName);
 			//alert("After the process.run");
 			//this.timer = setTimeout( function(){this.processHandler(process);}, 10000 );
@@ -130,13 +193,18 @@
 	},
 	uploadFile:function()
 	{
-		var textboxObj = document.getElementById("file-path");
-		//alert(textboxObj);
-		var filePath = textboxObj.value;
-		//alert(filePath);
+		/*var filePath;
+        if(this.isOgg){
+            filePath = document.getElementById("file-path").value;        
+        }
+        else{
+                
+        }*/
+		
+		alert(this.targetPathToUpload);
         
 		var file = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
-		file.initWithPath(filePath);
+		file.initWithPath(this.targetPathToUpload);
 		var fstream = Components.classes['@mozilla.org/network/file-input-stream;1'].createInstance(Components.interfaces.nsIFileInputStream);
 		fstream.init(file, 1, 1, Components.interfaces.nsIFileInputStream.CLOSE_ON_EOF);
 		var bstream = Components.classes['@mozilla.org/network/buffered-input-stream;1'].createInstance(Components.interfaces.nsIBufferedInputStream);
@@ -150,7 +218,7 @@
 		var boundaryString = 'capitano';
 		var boundary = '--' + boundaryString;
 		var requestbody = boundary + '\n' 
-		+ 'Content-Disposition: form-data; name="myfile"; filename="' + this.leafName+ '"'+'\n'
+		+ 'Content-Disposition: form-data; name="myfile"; filename="' + this.targetPathToUpload+ '"'+'\n'
 		+'Content-Type: application/octet-stream'+'\n'
 		+ '\n'
 		+ escape(binary.readBytes(binary.available()))

Modified: trunk/oggPusher/firefox-extension/chrome/content/op_Window.xul
===================================================================
--- trunk/oggPusher/firefox-extension/chrome/content/op_Window.xul	2008-08-28 18:27:16 UTC (rev 15216)
+++ trunk/oggPusher/firefox-extension/chrome/content/op_Window.xul	2008-08-29 00:04:16 UTC (rev 15217)
@@ -16,14 +16,14 @@
 	  	 <textbox id="file-path" control="browse-button" disabled="true" style="width:400px"/>
       	 <button id="browse-button" label="Browse..." oncommand="opwindowCommon.openFileWindowDialog();"/>
 	  </hbox>
-	  <hbox>
+	  <!--<hbox>
 		 <textbox id="target-path" control="destination-button" disabled="true" style="width:400px"/>
 		 <button id="destination-button" label="Choose Destination" oncommand="opwindowCommon.chooseDestination();"/>
 	  </hbox>
 	  <hbox>
 		 <button id="upload-button" label="Upload" oncommand="opwindowCommon.uploadFile();"/>
 		 <button id="convert-button" label="Convert" oncommand="opwindowCommon.convertToTheora();"/>
-	  </hbox>
+	  </hbox> -->
    </vbox>
 
 </window>

Modified: trunk/oggPusher/oggPusher.xpi
===================================================================
(Binary files differ)



More information about the commits mailing list