Search in sources :

Example 6 with HttpClient

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
    }
}
Also used : HttpClient(com.frostwire.util.http.HttpClient)

Example 7 with HttpClient

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);
    }
}
Also used : HttpRangeException(com.frostwire.util.http.HttpClient.HttpRangeException) IOException(java.io.IOException) HttpClient(com.frostwire.util.http.HttpClient) List(java.util.List) File(java.io.File)

Example 8 with HttpClient

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();
            }
        }
    });
}
Also used : HashMap(java.util.HashMap) HttpClient(com.frostwire.util.http.HttpClient) List(java.util.List) LinkedList(java.util.LinkedList) IOException(java.io.IOException)

Example 9 with HttpClient

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;
}
Also used : HttpClient(com.frostwire.util.http.HttpClient) ArrayList(java.util.ArrayList) SoundcloudSearchResult(com.frostwire.search.soundcloud.SoundcloudSearchResult)

Aggregations

HttpClient (com.frostwire.util.http.HttpClient)9 IOException (java.io.IOException)4 List (java.util.List)2 SoundcloudSearchResult (com.frostwire.search.soundcloud.SoundcloudSearchResult)1 Regex (com.frostwire.search.youtube.jd.Regex)1 HttpRangeException (com.frostwire.util.http.HttpClient.HttpRangeException)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 StringReader (java.io.StringReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1