<%@ page import="java.util.*,java.net.*,java.io.*,java.sql.*,java.util.Date,java.util.Calendar,sample.progress.MyUploadListener"%> <%@ page language="java" import="javazoom.upload.*,java.util.*,java.io.*" %> <%@ page errorPage="ExceptionHandler.jsp" %> <%@ include file="ConnectDB.jsp"%> <% session.setAttribute("countpage","0"); String username=(String)session.getAttribute("User_Name"); String userid=(String)session.getAttribute("User_id"); String password=(String)session.getAttribute("Password"); if(username==null || password==null) { response.sendRedirect("user_login.jsp?ref=kc"); } %> <% String path=application.getRealPath("/");//+"Convert"; String path2=application.getRealPath("/")+"tmp";//+"Convert"+"/tmp"; %> <% String directory = path; %> <% String tmpdirectory = path2; %> <% boolean createsubfolders = true; %> <% boolean allowresume = true; %> <% boolean allowoverwrite = true; %> <% String encoding = "ISO-8859-1"; %> <% boolean keepalive = false; %> <% upBean.addUploadListener(upListener); %> <% //request.setCharacterEncoding(encoding); //response.setContentType("text/html; charset="+encoding); String method = request.getMethod(); // Head processing to support resume and overwrite features. if (method.equalsIgnoreCase("head")) { String filename = request.getHeader("relativefilename"); if (filename == null) filename = request.getHeader("filename"); if (filename!=null) { if (keepalive == false) response.setHeader("Connection","close"); String account = request.getHeader("account"); if (account == null) account=""; else if (!account.startsWith("/")) account = "/"+account; File fhead = new File(directory+account+"/"+filename); if (fhead.exists()) { response.setHeader("size", String.valueOf(fhead.length())); String checksum = request.getHeader("checksum"); if ((checksum != null) && (checksum.equalsIgnoreCase("crc"))) { long crc = upBean.computeCRC32(fhead,-1); if (crc != -1) response.setHeader("checksum", String.valueOf(crc)); } else if ((checksum != null) && (checksum.equalsIgnoreCase("md5"))) { String md5 = upBean.hexDump(upBean.computeMD5(fhead,-1)).toLowerCase(); if ((md5 != null) && (!md5.equals(""))) response.setHeader("checksum", md5); } } else response.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } %> Dil Khol Ke Bol Videos - Upload Videos <% if (MultipartFormDataRequest.isMultipartFormData(request)) { Vector listeners = new Vector(); listeners.addElement(upListener); String err = null; // Parse multipart HTTP POST request. MultipartFormDataRequest mrequest = null; try { mrequest = new MultipartFormDataRequest(request,listeners,-1,MultipartFormDataRequest.CFUPARSER,encoding,allowresume); } catch (Exception e) { upListener.cancel(); err = e.getMessage(); // Cancel current upload (e.g. Stop transfer) // Only if allowresume = false } String todo = null; if (mrequest != null) todo = mrequest.getParameter("todo"); else throw new Exception(err); if ( (todo != null) && (todo.equalsIgnoreCase("upload")) ) { String account = mrequest.getParameter("account"); if (account == null) account=""; else if (!account.startsWith("/")) account = "/"+account; upBean.setFolderstore(directory+account); Hashtable files = mrequest.getFiles(); if ( (files != null) && (!files.isEmpty()) ) { UploadFile file = (UploadFile) files.get("uploadfile"); if (file != null){ //out.println("
  • Form field : uploadfile"+"
    Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"
    Content Type : "+file.getContentType()); long size=(file.getFileSize())/1000000; //out.print("size============"+(size)); if(size>=101) { response.sendRedirect("KConvert.jsp?i=0"); } // out.print("size>1============"+(size>1)); } String relative = mrequest.getParameter("relativefilename"); if ((createsubfolders == true) && (relative != null)) { int inda=relative.length(); int indb=file.getFileName().length(); if (inda > indb) { String subfolder = relative.substring(0,(inda-indb)-1); subfolder = subfolder.replace('\\','/').replace('/',java.io.File.separatorChar); upBean.setFolderstore(directory+account+java.io.File.separator+subfolder); } } if (keepalive == false) response.setHeader("Connection","close"); // Chunks recomposion support. String chunkidStr = mrequest.getParameter("chunkid"); String chunkamountStr = mrequest.getParameter("chunkamount"); String chunkbaseStr = mrequest.getParameter("chunkbase"); if ((chunkidStr != null) && (chunkamountStr != null) && (chunkbaseStr != null)) { // Always overwrite chunks. upBean.setOverwrite(true); upBean.store(mrequest, "uploadfile"); upBean.setOverwrite(allowoverwrite); int chunkid = Integer.parseInt(chunkidStr); int chunkamount = Integer.parseInt(chunkamountStr); if (chunkid == chunkamount) { // recompose file. String fname = upBean.getFolderstore()+java.io.File.separator+chunkbaseStr; File fread = new File(fname); if (fread.canRead() && (upBean.getOverwrite()==false)) fname = upBean.loadOverwriteFilter().process(fname); FileOutputStream fout = new FileOutputStream(fname); byte[] buffer = new byte[4096]; for (int c=1;c<=chunkamount;c++) { File filein = new File(upBean.getFolderstore()+java.io.File.separator+chunkbaseStr+"."+c); FileInputStream fin = new FileInputStream(filein); int read = -1; while ((read = fin.read(buffer)) > 0) fout.write(buffer,0,read); fin.close(); filein.delete(); } fout.close(); } } else upBean.store(mrequest, "uploadfile"); upBean.setFolderstore(directory+account); String uploadfilename=file.getFileName(); Runtime r = Runtime.getRuntime(); Process p = null; try { String separator = System.getProperty("file.separator"); String path1=application.getRealPath("/"); //+ "Convert" + separator; // out.println(path1); String ext=""; String exepath= "/usr/local/bin/ffmpeg -i" ; // String exepath= "E:\\Project\\videos.dilkholkebol\\build\\web\\ffmpeg -i" ; String FF=path1 + uploadfilename; File f1=new File(FF); uploadfilename=uploadfilename.replace(' ','_'); String NewFile=path1 + uploadfilename; Calendar cal=Calendar.getInstance(); int day=cal.get(Calendar.DATE); int month=cal.get(Calendar.MONTH); int year=cal.get(Calendar.YEAR); int hrs=cal.get(Calendar.HOUR); int min=cal.get(Calendar.MINUTE); int sec=cal.get(Calendar.SECOND); int msec=cal.get(Calendar.MILLISECOND); String vname_postfix=day+"-"+month+"-"+year+"-"+hrs+"-"+min+"-"+sec+"-"+msec; File New = new File(NewFile); f1.renameTo(New); String Fname=path1 + uploadfilename; //out.print("uploadfilename=========="+uploadfilename); String temp=uploadfilename.substring(0,uploadfilename.lastIndexOf(".")); String FlvFname=""; FlvFname= path1 +"Flv"+separator+ temp+vname_postfix+ ".flv"; FlvFname=FlvFname.replace("(",""); FlvFname=FlvFname.replace(")",""); //out.print("FlvFname================================"+FlvFname); // String cmde=exepath + " " + Fname + " -r 25 -ar 22050 -ab 32 -f flv -sameq -y " + FlvFname; //String cmde=exepath + " " + Fname + " -r 25 -ar 22050 -ab 32 -f flv -qmin 7 -qmax 7 -y " + FlvFname; String cmde=exepath + " " + Fname + " -r 25 -ar 22050 -ab 32 -b 256 -f flv -qmax 10 -s 480*360 -y " + FlvFname; // if (ext.equals(".mp3")||ext.equals(".mp4") ) { // cmde=exepath+ " "+ Fname + " -ab 128 -ar 44100 -y " + FlvFname; // } String Fjpgname=path1 +"Flv"+separator + temp + vname_postfix+".jpg"; Fjpgname=Fjpgname.replace("(",""); Fjpgname=Fjpgname.replace(")",""); String cmdjpg= exepath + " " +Fname + " -vcodec png -vframes 1 -an -f rawvideo -s 120*90 -ss 00:00:01 -y " + Fjpgname; try{ p=r.exec(cmdjpg); // out.print(cmde); p = r.exec(cmde); } catch(Exception e){e.printStackTrace(); } String outputline="hello"; InputStream stderr = p.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; out.println(""); while ( (line = br.readLine()) != null) outputline=outputline + " " +line; out.println(""); int exitVal = p.waitFor(); //out.println("Process exitValue: " + exitVal); int idx=outputline.indexOf("Lsize="); if(idx<0) { idx=outputline.lastIndexOf("size="); } String lastline=outputline.substring(idx); int idxtime=lastline.indexOf("time="); int idxbit=lastline.indexOf("bitrate="); String time=lastline.substring(idxtime+5,idxbit); int idxlsize=lastline.indexOf("Lsize="); String size=lastline.substring(idxlsize+6,idxtime); String video=NewFile; int index2=video.lastIndexOf("."); int index3=video.lastIndexOf("/"); String videoname=video.substring(index3+1,index2); videoname=videoname.replace("(",""); videoname=videoname.replace(")",""); String insertPath=video; String insertName=videoname+vname_postfix+".flv"; String insertImage=videoname+vname_postfix+".jpg"; String category=mrequest.getParameter("cats"); String headline=mrequest.getParameter("headline"); String description=mrequest.getParameter("description"); out.println("category-------"+category); String purpose=mrequest.getParameter("purpose"); out.println("-purpose-----------"+purpose); String keyword=mrequest.getParameter("keyword"); if(headline==""){headline="Video";} String date=year+"-"+(month+1)+"-"+day+" "+hrs+":"+min+":00"; out.println("date"+date); Statement state=con.createStatement(); String query=null; ResultSet result=null; String s=null; String keyid=""; if(keyword!=null) { s="select Keyword_id from keywords where Keyword_name='"+keyword+"'"; out.println("Query"+s); result=null; if(state == null) out.println("state is null"); else out.println("state is not null"); result=state.executeQuery(s); out.println("state is null......"); if(result.next()) { keyid=result.getString("Keyword_id"); out.println("keyid"+keyid); } if(keyid.equals("")) { s="insert into keywords(Keyword_name)values('"+keyword+"')"; out.println("keywords query"+s); state.executeUpdate(s); s="select Keyword_id from keywords where Keyword_name='"+keyword+"'"; out.println("keyid query"+s); result=null; result=state.executeQuery(s); if(result.next()) { keyid=result.getString("Keyword_id"); out.println("keyid---"+keyid); } } } s="insert into videopath(VideoPath,VideoImage,VideoFlashPath,User_id,Category_id,Video_time,Video_size,Keyword_id,Video_date,Purpose,video_headline,video_detail,upload_date)values('"+insertPath+"','"+insertImage+"','"+insertName+"','"+userid+"','"+category+"','"+time+"','"+size+"','"+keyid+"','"+date+"','"+purpose+"','"+headline+"','"+description+"','"+date+"')"; //out.print(s); state.executeUpdate(s); //con.close(); New.delete(); //response.sendRedirect("Convert.jsp?uploadfilename="+insertName); response.sendRedirect("videoPreview.jsp?uploadfilename="+insertName); } catch(Exception e) { out.println("Videos Error -------"+e.getMessage()); response.sendRedirect("KConvert.jsp?j=0"); } } else { String emptydirectory = mrequest.getParameter("emptydirectory"); if ((emptydirectory != null) && (!emptydirectory.equals(""))) { File dir = new File(directory+account+"/"+emptydirectory); dir.mkdirs(); } out.println("
  • No uploaded files"); } } else out.println("
    todo="+todo); } %> <%@ include file="header.jsp" %>

    <%@ include file="leftpanelcommon.jsp" %>
    Upload Videos

    Upload Video*
    You can upload files upto 100 MB
    Tags/Keywords
    Video Headline*
    Description
    Not more than 250 words
    Category* <% try { Statement state = con.createStatement(); String query="select Category_id,Category_name from category"; //out.print(query); ResultSet rs=state.executeQuery(query); //out.print("dsfds"); %> <% } catch(Exception e) { } %>
    General purpose   Personal purpose
    <% if((request.getParameter("i"))!=null) { %> File size can not be more than 100 mb <% } else if((request.getParameter("j"))!=null) { %> There is some problem with video please upload any other video. <% } %>

    Please wait.....
    <%@ include file="rightpanel.jsp" %>
    <%@ include file="footer.jsp" %>