Search in sources :

Example 1 with SpecifyFileIdException

use of se.light.assembly64.model.SpecifyFileIdException in project assembly64fx by freabemania.

the class SidifyMainContoller method playSong.

private SidTune playSong(PlaylistEntry song) throws InterruptedException, SongNotAvailableException, SpecifyFileIdException {
    // Ugly, but needed for the nextsub to know
    SidTune sidTune = null;
    setIconPlaying(true);
    Platform.runLater(() -> nowPlaying.setText(song.getNameMasked()));
    try {
        int retries = 0;
        while (true) {
            try {
                File sid = Support.getSid(song);
                if (!sid.exists() && isOffline()) {
                    throw new SongNotAvailableException();
                } else if (!sid.exists()) {
                    downloadService.downloadTo(sid, song.getId(), song.getCategory(), song.getFileId());
                    Platform.runLater(() -> {
                        // update downloaded status
                        songlist.getColumns().get(0).setVisible(false);
                        songlist.getColumns().get(0).setVisible(true);
                    });
                }
                sidTune = sidPlayService.getSidTune(sid);
                sidPlayService.playSid(sidTune, getSongIndex(sidTune) + 1);
                break;
            } catch (Exception e) {
                if (e instanceof SpecifyFileIdException) {
                    throw e;
                } else if (retries > 3 || e instanceof SongNotAvailableException) {
                    throw e;
                }
                retries++;
            }
        }
        // load image async
        ReturningTask<Void> task = () -> {
            if (!Support.isOffline()) {
                Set<TargetAndPath> images = MetadataService.getInstance().resolve(song).getImages();
                if (images.size() > 0) {
                    imageView.setImage(new Image(imageCache.getImage(images.iterator().next())));
                }
            } else {
                imageView.setImage(MetadataService.getInstance().getNoPreview());
            }
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(task, 1);
    } catch (Exception e) {
        if (e instanceof SpecifyFileIdException) {
            throw new SpecifyFileIdException();
        }
        setIconPlaying(false);
        progressUpdater.stop();
        GenericMessageDialogController.withErrorProps("Sidify", "Sid seems to be broken!", true).showAndWait();
        throw new InterruptedException();
    }
    return sidTune;
}
Also used : SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) Set(java.util.Set) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Image(javafx.scene.image.Image) SidTune(libsidplay.sidtune.SidTune) File(java.io.File) SearchException(se.light.assembly64.model.SearchException) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException)

Example 2 with SpecifyFileIdException

use of se.light.assembly64.model.SpecifyFileIdException in project assembly64fx by freabemania.

the class DownloadArtifactsService method downloadTo.

public File downloadTo(File location, String contentId, Integer category, String fileId) throws IOException, SpecifyFileIdException {
    Analytics.sendEvent("download", "downloadfile");
    String encodedId = fileId != null ? Support.urlEncode(fileId) : "na";
    Response response = getClient().target(getBackendServer()).path("/leet/search/get/" + contentId + "/" + category + "/" + encodedId).request().header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).get();
    if (response.getStatus() != 200) {
        response.close();
        if (response.getStatus() == 426) {
            throw new SpecifyFileIdException();
        } else {
            throw new RuntimeException("Err:" + response.getStatus());
        }
    }
    InputStream readEntity = response.readEntity(InputStream.class);
    FileUtils.forceMkdir(location.getParentFile());
    FileUtils.writeByteArrayToFile(location, IOUtils.toByteArray(readEntity));
    return location;
}
Also used : Response(javax.ws.rs.core.Response) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) InputStream(java.io.InputStream)

Aggregations

SpecifyFileIdException (se.light.assembly64.model.SpecifyFileIdException)2 File (java.io.File)1 InputStream (java.io.InputStream)1 Set (java.util.Set)1 Image (javafx.scene.image.Image)1 Response (javax.ws.rs.core.Response)1 SidTune (libsidplay.sidtune.SidTune)1 SearchException (se.light.assembly64.model.SearchException)1 SongNotAvailableException (se.light.assembly64.model.SongNotAvailableException)1