473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

java.lang.IllegalArgumentException

Expand|Select|Wrap|Line Numbers
  1.  public static void download(String url, String fileName) throws Exception {
  2.         String id = url.split("v=")[1].split("&")[0];
  3.         System.out.println(url + " " + id);
  4.         String nid = getDownloadId(id);
  5.         if (nid == null) {
  6.             throw new Exception("Invalud url");
  7.         }
  8.         url = "http://www.youtube.com/watch?v=" + id;
  9.         downloadStreamData(url, fileName);
  10.     }
  11.     /*
  12.      * returns the id of the video data
  13.      */
  14.     private static String getDownloadId(String videoId) throws MalformedURLException, IOException {
  15.         String url = "http://www.youtube.com/watch?v=" + videoId;
  16.         URL tU = new URL(url);
  17.         HttpURLConnection conn = (HttpURLConnection) tU.openConnection();
  18.         InputStream ins = conn.getInputStream();
  19.         BufferedReader rd = new BufferedReader(new InputStreamReader(ins));
  20.         String line;
  21.         StringBuffer content = new StringBuffer();
  22.         while ((line = rd.readLine()) != null) {
  23.             content.append(line);
  24.         }
  25.         String sContent = URLDecoder.decode(content.toString(), "UTF-8");
  26.         String[] tokens = sContent.split("&");
  27.         for (int i = 0; i < tokens.length - 1; i++) {
  28.             if (tokens[i] == null) {
  29.                 continue;
  30.             }
  31.             String param1 = tokens[i].substring(0, tokens[i].indexOf("="));
  32.             String param2 = tokens[i].substring(param1.length() + 1);
  33.             if (param1.equals("token")) {
  34.                 return param2;
  35.             }
  36.         }
  37.         return "";
  38.     }
  39. /*
  40.      * this function will download the file after the stream is found
  41.      */
  42.     private static void downloadStreamData(String url, String fileName) throws Exception {
  43.         URL tU = new URL(url);
  44.         HttpURLConnection conn = (HttpURLConnection) tU.openConnection();
  45.  
  46.         String type = conn.getContentType();
  47.         InputStream ins = conn.getInputStream();
  48.         FileOutputStream fout = new FileOutputStream(new File(fileName));
  49.         byte[] outputByte = new byte[4096];
  50.         int bytesRead;
  51.         int length = conn.getContentLength();
  52.         int read = 0;
  53.         while ((bytesRead = ins.read(outputByte, 0, 4096)) != -1) {
  54.             read += bytesRead;
  55.             System.out.println(read + " out of " + length);
  56.             fout.write(outputByte, 0, bytesRead);
  57.         }
  58.         fout.flush();
  59.         fout.close();
  60.     }
  61.  
  62.  

I get this error on the console when I run it:
http://www.youtube.com/watch?v=jUEOWVjnIR8 jUEOWVjnIR8
Exception in thread "main" java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "">"
at java.net.URLDecoder.decode(Unknown Source)
at youtube.file.YouTube.getDownloadId(YouTube.java:52 )
at youtube.file.YouTube.download(YouTube.java:30)
at youtube.file.YouTube.main(YouTube.java:21)
Apr 20 '13 #1
1 6605
r035198x
13,262 8TB
The string you are trying to decode is illegal according to the rules specified here http://docs.oracle.com/javase/6/docs...RLDecoder.html
Apr 22 '13 #2

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

Similar topics

0
by: Shawn | last post by:
I am getting the following error with a Java Applet being served out by IIS over HTTPS/SSL using a Verisign certificate: java.lang.NoClassDefFoundError: javax/help/HelpSetException at...
1
by: greg.knaddison | last post by:
Hi, I'm trying to use the httpclient within Jython (see http://jakarta.apache.org/commons/httpclient/ for more information on the httpclient). My Jython version is: Jython 2.1 on...
0
by: snkssa | last post by:
Hi, I got the following error while building an application with ant. please can you give the solution or reason why it is failing? Thank you create_zip_linux: ...
3
by: jayattarde | last post by:
Hi, While running .jar file I get the following error. Please helpme to sort it out. ption in thread "main" java.lang.NoClassDefFoundError: while resolving class: Cutter at...
2
by: cloudy | last post by:
First at all, i'm sorry, i not good in writing english. i want to retrieve a string from my applet via Javascript. I use a method named ReadAll. public String ReadAll(String StrOut, String...
4
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp...
1
Ganesh9u
by: Ganesh9u | last post by:
Hi All, import org.sf.feeling.swt.win32.extension.hook.Hook; import org.sf.feeling.swt.win32.extension.hook.data.HookData; import org.sf.feeling.swt.win32.extension.hook.data.MouseHookData; ...
1
by: ramprakashjava | last post by:
hi , while am opening my netbeans IDE it shows this java.lang.IllegalArgumentException: Project module is not open and cannot be set as main. at...
1
by: rajujrk | last post by:
Hai All, I am Having a problem in the following... import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.io.FileUtils; import...
1
by: James Kalmadge | last post by:
I have a test program that compiles but does not run. Here is the code which I grabbed from from a web site: import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.