use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class MultimediaSlideshowPanel method load.
private void load(final String url) {
try {
HttpClient client = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
String jsonString = client.get(url);
if (jsonString != null) {
final SlideList slideList = JsonUtils.toObject(jsonString, SlideList.class);
try {
setup(slideList.slides);
} catch (Exception e) {
LOG.info("Failed load of Slide Show:" + url, e);
setup(fallbackSlides);
// nothing happens
}
} else {
setup(fallbackSlides);
}
} catch (Exception e) {
LOG.info("Failed load of Slide Show:" + url, e);
setup(fallbackSlides);
// nothing happens
}
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class InstallerUpdater method handleHttpDownload.
private void handleHttpDownload() {
File updateFolder = UpdateSettings.UPDATES_DIR;
String fileName = _updateMessage.getSaveAs() != null ? _updateMessage.getSaveAs() : getFileNameFromHttpUrl();
File installerFileLocation = new File(updateFolder, fileName);
if (!updateFolder.exists()) {
updateFolder.mkdir();
updateFolder.setWritable(true);
}
try {
HttpClient httpClient = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
httpClient.setListener(new HttpClient.HttpClientListener() {
long contentLength;
long downloaded = 0;
@Override
public void onError(HttpClient client, Throwable e) {
}
@Override
public void onData(HttpClient client, byte[] buffer, int offset, int length) {
downloaded += length;
downloadProgress = (int) ((float) downloaded / contentLength * 100.0);
}
@Override
public void onComplete(HttpClient client) {
}
@Override
public void onCancel(HttpClient client) {
}
@Override
public void onHeaders(HttpClient httpClient, Map<String, List<String>> headerFields) {
if (headerFields.containsKey("Content-Length")) {
contentLength = Long.valueOf(headerFields.get("Content-Length").get(0));
}
}
});
try {
httpClient.save(_updateMessage.getInstallerUrl(), installerFileLocation, true);
} catch (HttpRangeException e) {
// recovery in case the server does not support resume
httpClient.save(_updateMessage.getInstallerUrl(), installerFileLocation, false);
} catch (IOException e2) {
if (e2.getMessage().contains("416")) {
// HTTP Request Range error came through IOException.
httpClient.save(_updateMessage.getInstallerUrl(), installerFileLocation, false);
}
}
isDownloadingUpdate = false;
downloadComplete();
} catch (Throwable e) {
isDownloadingUpdate = false;
LOG.error("Failed to download installer: " + _updateMessage.getInstallerUrl(), e);
}
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class MPlayer method doOpen.
public void doOpen(String fileOrUrl, int initialVolume) {
MPlayerInstance instance;
synchronized (this) {
doStop(false);
instance = current_instance = new MPlayerInstance();
}
reportNewState(MediaPlaybackState.Opening);
firstLengthReceived = false;
firstVolumeReceived = false;
if (fileOrUrl.startsWith("http://")) {
// perform a 302 check, mplayer having issues with redirects.
final HttpClient httpClient = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.MISC);
Map<String, List<String>> responseHeaders = new HashMap<>();
try {
int responseCode = httpClient.head(fileOrUrl, 5000, responseHeaders);
if (responseCode == 302 && responseHeaders.containsKey("Location") && responseHeaders.get("Location").get(0) != null) {
fileOrUrl = responseHeaders.get("Location").get(0);
}
} catch (IOException ioException) {
}
}
instance.doOpen(fileOrUrl, initialVolume, new MPlayerInstance.OutputConsumer() {
public void consume(String line) {
synchronized (output) {
output.add(line);
output.notifyAll();
}
}
});
}
use of com.frostwire.util.http.HttpClient in project frostwire by frostwire.
the class DownloadSoundcloudFromUrlTask method doInBackground.
@Override
protected List<SoundcloudSearchResult> doInBackground() {
List<SoundcloudSearchResult> results = new ArrayList<>();
try {
String url = soundcloudUrl;
if (soundcloudUrl.contains("?in=")) {
url = soundcloudUrl.substring(0, url.indexOf("?in="));
}
String resolveURL = SoundcloudSearchPerformer.resolveUrl(url);
HttpClient client = HttpClientFactory.getInstance(HttpClientFactory.HttpContext.DOWNLOAD);
String json = client.get(resolveURL, 10000);
results = SoundcloudSearchPerformer.fromJson(json);
} catch (Throwable e) {
e.printStackTrace();
}
return results;
}
Aggregations