public boolean retry(Throwable e) { if (e == null) return true; if (e instanceof DownloadIOCodeError) { DownloadIOCodeError c = (DownloadIOCodeError) e; switch (c.getCode()) { case HttpURLConnection.HTTP_FORBIDDEN: case 416: // 416 Requested Range Not Satisfiable return true; default: return false; } } return false; }
public boolean done(AtomicBoolean stop) { if (stop.get()) throw new DownloadInterruptedError("stop"); if (Thread.currentThread().isInterrupted()) throw new DownloadInterruptedError("interrupted"); return false; }
public String getContentExt(DownloadInfo dinfo) { String ct = dinfo.getContentType(); if (ct == null) throw new DownloadRetry("null content type"); // for multi file download keep content type and extension. some video can have same extensions for booth // audio/video streams ct = ct.replaceFirst("/", "."); return "." + ct.replaceAll("x-", "").toLowerCase(); }
decodeScript.append(decodeFunctionMatch.group(1)).append(';'); } else { throw new DownloadError("Unable to extract the main decode function!"); decodeScript.append(decodeFunctionHelperMatch.group(1)); } else { throw new DownloadError("Unable to extract the helper decode functions!"); throw new DownloadError("Unable to determine the name of the helper decode function!");
throw new DownloadRetry("empty video download list," + " wait until youtube will process the video"); throw new DownloadError("no video user quality found");
for (Part ee : e.getInfo().getParts()) { throw new DownloadError(f);
throw new DownloadError(e); throw new DownloadInterruptedError("stop"); if (Thread.currentThread().isInterrupted()) throw new DownloadInterruptedError("interrupted"); Thread.sleep(1000); } catch (InterruptedException ee) { throw new DownloadInterruptedError(ee);
boolean a = c.contains("audio/"); if (!v && !a) { throw new DownloadRetry( "unable to download video, bad content " + dinfo.getContentType()); throw new DownloadInterruptedError(e); throw new DownloadInterruptedError(e);
@Override public void printStackTrace(PrintStream s) { for (VideoFileInfo i : list) { if (i.getException() != null) { i.getException().printStackTrace(s); } } super.printStackTrace(s); }
void checkRetry(DownloadMultipartError e) { for (Part ee : e.getInfo().getParts()) { if (!retry(ee.getException())) { throw e; } } }
public class ProxySetup { public HttpURLConnection proxySetup(String urlInput) { URL url; try { url = new URL(urlInput); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.66.182.100", 80)); // or whatever your proxy is HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy); System.setProperty("https.proxyHost", "10.66.182.100"); System.setProperty("https.proxyPort", "80"); System.setProperty("http.proxyHost", "10.66.182.100"); System.setProperty("http.proxyPort", "80"); String encoded = new String(Base64.encodeBase64(("domain\\Username" + ":" + "Password").getBytes())); uc.setRequestProperty("Proxy-Authorization", "Basic " + encoded); Authenticator.setDefault(new ProxyAuth("domain\\Username", "Password")); System.out.println("ProxySetup : proxySetup"); return uc; } catch (Exception e) { // TODO Auto-generated catch block System.out.println("ProxySetup : proxySetup - Failed"); e.printStackTrace(); } return null; } }
/** * Decodes the youtube video signature using the decode functions provided in the html5player script. */ public String decrypt(AtomicBoolean stop, Runnable notify) { ScriptEngineManager manager = new ScriptEngineManager(); // use a js script engine ScriptEngine engine = manager.getEngineByName("JavaScript"); final String playerScript = getHtml5PlayerScript(stop, notify); final String decodeFuncName = getMainDecodeFunctionName(playerScript); final String decodeScript = extractDecodeFunctions(playerScript, decodeFuncName); String decodedSignature = null; try { // evaluate script engine.eval(decodeScript); Invocable inv = (Invocable) engine; // execute the javascript code directly decodedSignature = (String) inv.invokeFunction(decodeFuncName, sig); } catch (Exception e) { throw new DownloadError("Unable to decrypt signature!"); } return decodedSignature; } }
throw new DownloadRetry("empty video download list," + " wait until youtube will process the video"); throw new DownloadError("no video with required quality found," + " increace VideoInfo.setVq to the maximum and retry download");
public String getExt(DownloadInfo dinfo) { String ct = dinfo.getContentType(); if (ct == null) throw new DownloadRetry("null content type"); // for single file download keep only extension ct = ct.replaceFirst("video/", ""); ct = ct.replaceFirst("audio/", ""); return "." + ct.replaceAll("x-", "").toLowerCase(); }
@Override public void printStackTrace(PrintWriter s) { for (VideoFileInfo i : list) { if (i.getException() != null) { i.getException().printStackTrace(s); } } super.printStackTrace(s); } }
@Override public List<VideoFileInfo> extract(VideoInfo vinfo, AtomicBoolean stop, Runnable notify) { List<VideoDownload> sNextVideoURL = extractLinks(vinfo, stop, notify); Collections.sort(sNextVideoURL, new VideoContentFirst()); for (int i = 0; i < sNextVideoURL.size();) { VideoDownload v = sNextVideoURL.get(i); VimeoInfo yinfo = (VimeoInfo) vinfo; yinfo.setVideoQuality(v.vq); VideoFileInfo info = new VideoFileInfo(v.url); vinfo.setInfo(Arrays.asList(info)); vinfo.setSource(v.url); return vinfo.getInfo(); } // throw download stop if user choice not maximum quality and we have no // video rendered by throw new DownloadError("no video with required quality found"); }
throw new VideoDeleted("error code 100"); throw new DownloadError(r);
throw new DownloadError("Do not use setTarget file on multiply source download");
throw new DownloadError("unknown url"); Matcher um = u.matcher(html); if (!um.find()) { throw new DownloadError("unknown config vimeo respond");