423,822 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,822 IT Pros & Developers. It's quick & easy.

Youtube Video Downloader

P: 79
Hi all,
I m going to make a Youtube Video Downloader in JAVA, but i dont know where to start and how to do this... i have googled a lot to find any help in this case but i didn't find any helpful material...

Thanx
ARUZ
Apr 5 '09 #1
Share this Question
Share on Google+
11 Replies


dmjpro
100+
P: 2,476
First you need to have the swf file then use URL class API then i think you can get the help.
If you want to incorporate the Java file with the Youtube player then i think it's not possible ;)
Ok i m also trying, let's see what happens with URL class ;)
Apr 6 '09 #2

dmjpro
100+
P: 2,476
See i tested this code but i could not able to download ..i able to save the SWF file but it's not playing and even not saying that this is an invalid file.
My code goes here.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.io.BufferedInputStream;
  3. import java.io.BufferedOutputStream;
  4. import java.io.FileOutputStream;
  5. import java.net.InetAddress;
  6. import java.net.InetSocketAddress;
  7. import java.net.Proxy;
  8. import java.net.SocketAddress;
  9. import java.net.URL;
  10.  
  11. /*
  12.  * To change this template, choose Tools | Templates
  13.  * and open the template in the editor.
  14.  */
  15. import java.net.URLConnection;
  16.  
  17. /**
  18.  *
  19.  * @author Admin
  20.  */
  21. public class SWfDowloader {
  22.     public static void main(String a[]) throws Exception{
  23.         String swf_path = "http://s.ytimg.com/yt/swf/watch_v8-vfl87635.swf";
  24.         URL swf_url = new URL(swf_path);
  25.         byte address[] = {(byte)144,(byte)16,(byte)192,(byte)245};
  26.         SocketAddress socket_address = new InetSocketAddress(InetAddress.getByAddress(address),8080);
  27.         Proxy proxy = new Proxy(Proxy.Type.HTTP,socket_address);
  28.         URLConnection url_conn = swf_url.openConnection(proxy);
  29.         url_conn.connect();
  30.         BufferedInputStream swf_in_stream = new BufferedInputStream(url_conn.getInputStream());
  31.         FileOutputStream swf_file = new FileOutputStream("d:/test.swf");
  32.         BufferedOutputStream swf_out_stream = new BufferedOutputStream(swf_file);
  33.         byte bytes[] = new byte[512];
  34.         int read_bytes = 0;
  35.         while((read_bytes=swf_in_stream.read(bytes))!=-1)
  36.             swf_out_stream.write(bytes, 0,read_bytes);
  37.  
  38.         swf_in_stream.close();
  39.         swf_file.close();
  40.         swf_out_stream.close();
  41.     }
  42. }
  43.  
I think the part of the SWF file downloaded.you know when you play a video in Youtube then it takes time to play the full one ...but i am not sure that the whole content i am getting here .. you also try ...i also keep searching. Le's see what happens ;)
Apr 6 '09 #3

P: 79
The swf file you are downloading is the flv player while we need the flv file not the swf file...

ARUZ
Apr 6 '09 #4

P: 79
but they havnt included the feature for download :)
I have a youtube downloader on vb i m thinking to convert that into java.... may be that logic works for java too....
Apr 6 '09 #6

dmjpro
100+
P: 2,476
@EYE4U
I didn't get you what you meant ;)
What you need ..Flash View Player?
Apr 6 '09 #7

P: 79
I need to download videos from youtube.. this is what i want.
I didnt want to build a youtube client application...
Apr 6 '09 #8

dmjpro
100+
P: 2,476
How do you incorporate your Java code into the Youtube player?
What i did that's not downloading the full one.
Let's try with another file..what my code says ;)
Apr 7 '09 #9

dmjpro
100+
P: 2,476
See..Just now i tried with one link.
"http://www.java2s.com/Code/JavaDownload/EJB-servlet-stateless-ear.zip"
I tried to download it using my code.
But it's not working :(
When i tried to unzip it then it said "unexpected end of archive" but it shown me the proper file structure.
Could anyone tell me what happened? ;)

One more thing .. The file was 17K and my calculations was also 17.48 K on the basis of read bytes :) I don't what went wrong?
Apr 7 '09 #10

dmjpro
100+
P: 2,476
I tried with one more link "http://www.prototypejs.org/assets/2008/1/25/prototype-1.6.0.2.js"
That's the plain text file so that i could check the easily how much left to download.
Right now i saw that some of the bytes left to download ... the same thing happened with ZIP file ;) What would be the reason? Where i did wrong so that it behaved like this?
Apr 7 '09 #11

P: 1
Why do not you use the tubemate youtube downloader app
Nov 5 '17 #12

Post your reply

Sign in to post your reply or Sign up for a free account.