use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class YouTubeExtractor method extractLinksFromDashManifest.
private List<LinkInfo> extractLinksFromDashManifest(String dashManifestUrl, YouTubeSig ytSig, String filename, Date date, String videoId, String userName, String channelName, ThumbnailLinks thumbnailLinks) throws IOException, ParserConfigurationException, SAXException {
dashManifestUrl = dashManifestUrl.replace("\\/", "/");
Pattern p = Pattern.compile("/s/([a-fA-F0-9\\.]+)/");
Matcher m = p.matcher(dashManifestUrl);
if (m.find()) {
String sig = m.group(1);
String signature = ytSig.calc(sig);
dashManifestUrl = dashManifestUrl.replaceAll("/s/([a-fA-F0-9\\.]+)/", "/signature/" + signature + "/");
} else if (dashManifestUrl.contains("/signature/")) {
// dashManifestUrl as it is, empty block to review
} else {
return Collections.emptyList();
}
HttpClient httpClient = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.SEARCH);
String dashDoc = httpClient.get(dashManifestUrl);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(dashDoc)));
NodeList nodes = doc.getElementsByTagName("BaseURL");
List<LinkInfo> infos = new ArrayList<LinkInfo>();
for (int i = 0; i < nodes.getLength(); i++) {
Node item = nodes.item(i);
String url = item.getTextContent();
int contentLength = -1;
try {
contentLength = Integer.parseInt(item.getAttributes().item(0).getTextContent());
} catch (Throwable e) {
// ignore
}
int fmt = Integer.parseInt(new Regex(url, "itag=(\\d+)").getMatch(0));
Format format = FORMATS.get(fmt);
if (format == null) {
continue;
}
LinkInfo info = new LinkInfo(url, fmt, filename, contentLength, date, videoId, userName, channelName, thumbnailLinks, format);
infos.add(info);
}
return infos;
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class YouTubeExtractor method getYouTubeSig.
private YouTubeSig getYouTubeSig(String html5playerUrl) {
// concurrency issues are not important in this point
YouTubeSig sig = null;
if (!YT_SIG_MAP.containsKey(html5playerUrl)) {
String jscode = "";
try {
html5playerUrl = html5playerUrl.replace("\\", "");
HttpClient httpClient = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.SEARCH);
jscode = httpClient.get(html5playerUrl);
sig = new YouTubeSig(jscode);
YT_SIG_MAP.put(html5playerUrl, sig);
} catch (Throwable t) {
LOG.error("Could not getYouTubeSig");
// LOG.error("jscode:\n" + jscode);
}
} else {
// cache hit, it worked with this url.
sig = YT_SIG_MAP.get(html5playerUrl);
}
return sig;
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class CreateTorrentDialog method checkWebSeedMirror.
/**
* Sends HEAD request to the mirror location along with the test path to see if the file exists.
* Read http://getright.com/seedtorrent.html to find out how mirror urls are interpreted
*/
private boolean checkWebSeedMirror(String mirror, create_torrent torrent, boolean isMultiFile) {
String urlPath = getWebSeedTestPath(mirror, torrent, isMultiFile);
HttpClient browser = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
int responseCode = 500;
try {
responseCode = browser.head(urlPath, 2000, null);
System.out.println(responseCode + ": " + urlPath);
} catch (IOException e) {
e.printStackTrace();
}
return responseCode == 200;
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class ShareTorrentDialog method performAsyncURLShortening.
private void performAsyncURLShortening(final URLShortenerHttpClientListener listener) {
final HttpClient browser = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
browser.setListener(listener);
ThreadExecutor.startThread(listener.getHttpRequestRunnable(browser), "ShareTorrentDialog-performAsyncURLShortening");
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class ImageCache method loadFromUrl.
private void loadFromUrl(final URL url, final OnLoadedListener listener) {
ThreadExecutor.startThread(new Thread(new Runnable() {
public void run() {
try {
BufferedImage image = null;
HttpClient newInstance = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
byte[] data = newInstance.getBytes(url.toString());
if (data == null) {
throw new IOException("ImageCache.loadUrl() got nothing at " + url.toString());
}
if (data != null) {
image = ImageIO.read(new ByteArrayInputStream(data));
saveToCache(url, image, System.currentTimeMillis());
}
if (listener != null && image != null) {
listener.onLoaded(url, image, false, false);
}
} catch (Throwable e) {
LOG.error("Failed to load image from: " + url, e);
listener.onLoaded(url, null, false, true);
}
}
}), "ImageCache.loadFromUrl");
}
Aggregations