@Override public void handleFree(final DownloadLink downloadLink) throws Exception, PluginException { requestFileInformation(downloadLink); downloadLink.setProperty("page_url", br.getURL()); /* * In case we got embedded links, we are already on the feed_url. Find- and access it if still needed. */ if (feed_url == null && mediagen_url == null) { throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); // br.getHeaders().put("Referer", player_url); // br.getPage(feed_url); } if (mediagen_url == null) { /* Find- and access mediagen. */ mediagen_url = feedGetMediagenURL(); if (mediagen_url == null) { /* Check if maybe we just got a nearly empty response --> Video won't load in the browser either! */ if (br.containsHTML("<rss xmlns:media=")) { throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error - video offline?"); } throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } /** * Sometimes there are spaces at the end of the link, undefined parameters or it's simply url * encoded though we need it plain --> This can lead to 404 errors! --> This function takes * care of these problems. */ mediagen_url = Encoding.htmlDecode(mediagen_url); mediagen_url = mediagen_url.trim(); } br.getHeaders().put("Referer", player_url); br.getPage(mediagen_url); if (br.getHttpConnection().getResponseCode() == 404) { /* Video temporarily or forever offline */ throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 404", 3 * 60 * 60 * 1000l); } else if (br.containsHTML("status=\"esiblocked\"") || br.containsHTML("/error_country_block") || br.containsHTML(">Sorry, content is not available for your country\\.") || br.containsHTML("copyright_error\\.flv") || br.containsHTML(">Copyrights restrict us from playing this video in your country") || br.containsHTML("errorslates/video_error")) { /* Geo block */ throw new PluginException( LinkStatus.ERROR_FATAL, "This video is not available from your location"); } else if (br.containsHTML( ">Sorry, this video is not found or no longer available due to date or rights restrictions")) { throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Video doesn't exist anymore (?)", 60 * 60 * 1000l); } else if (br.containsHTML("Sorry, we're unable to play this video")) { throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 'Sorry, we're unable to play this video'", 3 * 60 * 60 * 1000l); } /* Chose highest quality available */ final String[] srcs = br.getRegex("([a-z]+://[^<>\"]*?)</src>").getColumn(0); if (srcs == null || srcs.length == 0) { /* Very very rare case! */ throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Unknown server error", 1 * 60 * 60 * 1000l); } /* Now get the best quality (highest width) */ String src_url = null; int best_width = 0; int tempwidth = 0; for (final String tmpsrc : srcs) { final String width = new Regex(tmpsrc, "_(\\d+)x\\d+_").getMatch(0); if (width != null) { tempwidth = Integer.parseInt(width); if (tempwidth > best_width) { best_width = tempwidth; src_url = tmpsrc; } } } /* No width given? Grab the last element of the array - if this is not the best resolution, improve the upper function. */ if (src_url != null) { logger.info("Found BEST downloadlink"); } else { logger.info("Failed to find BEST downloadlink"); src_url = srcs[srcs.length - 1]; } String httpurl; if (src_url.startsWith("http")) { /* In very rare cases we already have http urls */ httpurl = src_url; } else { /* Prefer http - try to convert the rtmp(e) urls to http urls --> Works in about 50% of all cases! */ httpurl = convertRTMPtoHTTP(src_url); } if (httpurl != null) { downloadHTTP(downloadLink, httpurl); } else { downloadRTMP(downloadLink, src_url); } }