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;
}
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;
}
Aggregations