Comment Telecharger Une Video De You Tube

comment télécharger des vidéos du YouTube dessus Java? besoin d"une classer (ou d"un morceau de code) qui décrit comment? ou quoi le faire. Merci.


import Java.io.BufferedReader;import Java.io.File;import Java.io.FileOutputStream;import Java.io.IOException;import Java.io.InputStream;import Java.io.InputStreamReader;import Java.io.Reader;import Java.io.StringWriter;import Java.io.UnsupportedEncodingException;import Java.io.Writer;import Java.net.URI;import Java.net.URISyntaxException;import Java.util.ArrayList;import Java.util.List;import Java.util.Scanner;import Java.util.logging.Formatter;import Java.util.logging.Handler;import Java.util.logging.Level;import Java.util.logging.LogRecord;import Java.util.logging.Logger;import Java.util.regex.Pattern;import org.Apache.http.HttpEntity;import org.Apache.http.HttpResponse;import org.Apache.http.NameValuePair;import org.Apache.http.client.CookieStore;import org.Apache.http.client.HttpClient;import org.Apache.http.client.methods.HttpGet;import org.Apache.http.client.protocol.ClientContext;import org.Apache.http.client.utils.URIUtils;import org.Apache.http.client.utils.URLEncodedUtils;import org.Apache.http.impl.client.BasicCookieStore;import org.Apache.http.impl.client.DefaultHttpClient;import org.Apache.http.message.BasicNameValuePair;import org.Apache.http.protocol.BasicHttpContext;import org.Apache.http.protocol.HttpContext;public course JavaYoutubeDownloader { auditeur static wire newline = System.getProperty("line.separator"); exclusive static final Logger log = Logger.getLogger(JavaYoutubeDownloader.class.getCanonicalName()); private static final Level defaultLogLevelSelf = Level.FINER; personal static définitif Level defaultLogLevel = Level.WARNING; personal static définitif Logger rootlog = Logger.getLogger(""); exclusive static final String plan = "http"; exclusive static définitif String hold = "www.youtube.com"; private static final Pattern commaPattern = Pattern.compile(","); personal static définitif Pattern pipePattern = Pattern.compile("\|"); exclusive static final char<> ILLEGAL_FILENAME_CHARACTERS = ", """, ":" ; exclusive static void usage(String error) si (error != null) System.err.println("Error: " + error); System.err.println("usage: JavaYoutubeDownload VIDEO_ID DESTINATION_DIRECTORY"); System.exit(-1); public static void main(String<> args) si (args == null personal static wire getExtension(int format) // TODO revenir "mp4"; private static void play(String videoId, int format, string encoding, cable userAgent, la gestion outputdir, string extension) throws Throwable log.fine("Retrieving " + videoId); list qparams = nouveau ArrayList(); qparams.add(new BasicNameValuePair("video_id", videoId)); qparams.add(new BasicNameValuePair("fmt", "" + format)); URI uri = getUri("get_video_info", qparams); CookieStore cookieStore = new BasicCookieStore(); HttpContext localContext = new BasicHttpContext(); localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpClient httpclient = nouveau DefaultHttpClient(); HttpGet httpget = new HttpGet(uri); httpget.setHeader("User-Agent", userAgent); log.finer("Executing " + uri); HttpResponse response = httpclient.execute(httpget, localContext); HttpEntity entity = response.getEntity(); si (entity != null && response.getStatusLine().getStatusCode() == 200) InputStream instream = entity.getContent(); cable videoInfo = getStringFromInputStream(encoding, instream); si (videoInfo != null && videoInfo.length() > 0) list infoMap = new ArrayList(); URLEncodedUtils.parse(infoMap, nouveau Scanner(videoInfo), encoding); String token = null; wire downloadUrl = null; string filename = videoId; pour (NameValuePair égal : infoMap) String key = pair.getName(); wire val = pair.getValue(); log.finest(key + "=" + val); if (key.equals("token")) jeton = val; else si (key.equals("title")) filename = val; else si (key.equals("fmt_url_map")) String<> format = commaPattern.split(val); pour (String fmt : formats) String<> fmtPieces = pipePattern.split(fmt); si (fmtPieces.length == 2) // in auto end, download somethin! downloadUrl = fmtPieces<1>; int pieceFormat = Integer.parseInt(fmtPieces<0>); si (pieceFormat == format) // discovered what conditions météorologiques want downloadUrl = fmtPieces<1>; break; filename = cleanFilename(filename); si (filename.length() == 0) filename = videoId; else filename += "_" + videoId; filename += "." + extension; file outputfile = new File(outputdir, filename); si (downloadUrl != null) downloadWithHttpClient(userAgent, downloadUrl, outputfile); private static void downloadWithHttpClient(String userAgent, cable downloadUrl, ligne outputfile) litter Throwable HttpGet httpget2 = nouveau HttpGet(downloadUrl); httpget2.setHeader("User-Agent", userAgent); log.finer("Executing " + httpget2.getURI()); HttpClient httpclient2 = nouveau DefaultHttpClient(); HttpResponse response2 = httpclient2.execute(httpget2); HttpEntity entity2 = response2.getEntity(); si (entity2 != null && response2.getStatusLine().getStatusCode() == 200) longue length = entity2.getContentLength(); InputStream instream2 = entity2.getContent(); log.finer("Writing " + length + " bytes to " + outputfile); si (outputfile.exists()) outputfile.delete(); FileOutputStream outstream = new FileOutputStream(outputfile); shot byte<> buffer = nouveau byte<2048>; int counting = -1; while ((count = instream2.read(buffer)) != -1) outstream.write(buffer, 0, count); outstream.flush(); finally outstream.close(); exclusive static cable cleanFilename(String filename) pour (char c : ILLEGAL_FILENAME_CHARACTERS) filename = filename.replace(c, "_"); return filename; private static URI getUri(String path, perform qparams) litter URISyntaxException URI uri = URIUtils.createURI(scheme, Host, -1, "/" + path, URLEncodedUtils.format(qparams, "UTF-8"), null); return uri; personal static void setupLogging() { changeFormatter(new Formatter() {