use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class Lbry method fileList.
public static List<LbryFile> fileList(String claimId, boolean downloads, int page, int pageSize) throws ApiCallException {
List<LbryFile> files = new ArrayList<>();
Map<String, Object> params = new HashMap<>();
if (!Helper.isNullOrEmpty(claimId)) {
params.put("claim_id", claimId);
}
if (downloads) {
params.put("download_path", null);
params.put("comparison", "ne");
}
if (page > 0) {
params.put("page", page);
}
if (pageSize > 0) {
params.put("page_size", pageSize);
}
try {
JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_FILE_LIST, params));
JSONArray items = result.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject fileObject = items.getJSONObject(i);
LbryFile file = LbryFile.fromJSONObject(fileObject);
files.add(file);
String fileClaimId = file.getClaimId();
if (!Helper.isNullOrEmpty(fileClaimId)) {
ClaimCacheKey key = new ClaimCacheKey();
key.setClaimId(fileClaimId);
if (claimCache.containsKey(key)) {
claimCache.get(key).setFile(file);
}
}
}
} catch (LbryRequestException | LbryResponseException | JSONException ex) {
throw new ApiCallException("Could not execute resolve call", ex);
}
return files;
}
use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class UploadImageTask method doInBackground.
protected String doInBackground(Void... params) {
String thumbnailUrl = null;
try {
File file = new File(filePath);
String fileName = file.getName();
int dotIndex = fileName.lastIndexOf('.');
String extension = "jpg";
if (dotIndex > -1) {
extension = fileName.substring(dotIndex + 1);
}
String fileType = String.format("image/%s", extension);
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("name", Helper.makeid(24)).addFormDataPart("file", fileName, RequestBody.create(file, MediaType.parse(fileType))).build();
Request request = new Request.Builder().url("https://spee.ch/api/claim/publish").post(body).build();
OkHttpClient client = new OkHttpClient.Builder().writeTimeout(300, TimeUnit.SECONDS).readTimeout(300, TimeUnit.SECONDS).build();
Response response = client.newCall(request).execute();
JSONObject json = new JSONObject(response.body().string());
if (json.has("success") && Helper.getJSONBoolean("success", false, json)) {
JSONObject data = json.getJSONObject("data");
String url = Helper.getJSONString("url", null, data);
if (Helper.isNullOrEmpty(url)) {
throw new LbryResponseException("Invalid thumbnail url returned after upload.");
}
thumbnailUrl = String.format("%s.%s", url, extension);
} else if (json.has("error") || json.has("message")) {
JSONObject error = Helper.getJSONObject("error", json);
String message = null;
if (error != null) {
message = Helper.getJSONString("message", null, error);
}
if (Helper.isNullOrEmpty(message)) {
message = Helper.getJSONString("message", null, json);
}
throw new LbryResponseException(Helper.isNullOrEmpty(message) ? "The image failed to upload." : message);
}
} catch (IOException | JSONException | LbryResponseException ex) {
error = ex;
}
return thumbnailUrl;
}
use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class FileViewFragment method getStreamingUrlAndInitializePlayer.
private void getStreamingUrlAndInitializePlayer(Claim theClaim) {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> {
try {
// Get the streaming URL
Map<String, Object> params = new HashMap<>();
params.put("uri", theClaim.getPermanentUrl());
JSONObject result = (JSONObject) Lbry.parseResponse(Lbry.apiCall(Lbry.METHOD_GET, params));
String sourceUrl = (String) result.get("streaming_url");
currentMediaSourceUrl = sourceUrl;
// Get the stream type
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url(sourceUrl).head().build();
try (Response response = client.newCall(request).execute()) {
String contentType = response.header("Content-Type");
// m3u8
MainActivity.videoIsTranscoded = contentType.equals("application/x-mpegurl");
}
new Handler(Looper.getMainLooper()).post(() -> initializePlayer(sourceUrl));
} catch (LbryRequestException | LbryResponseException | JSONException | IOException ex) {
// TODO: How does error handling work here
ex.printStackTrace();
}
});
executor.shutdown();
}
use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class CommentEnabled method call.
@Override
public Boolean call() {
Map<String, Object> params = new HashMap<>(3);
params.put("claim_id", channelId);
params.put("channel_id", channelId);
params.put("channel_name", channelName);
try {
JSONObject result = (JSONObject) Lbry.parseResponse(Comments.performRequest(Lbry.buildJsonParams(params), METHOD_COMMENT_LIST));
if (result == null || result.has("error")) {
return false;
}
} catch (LbryResponseException | IOException e) {
Log.e(TAG, "Error while fetching comments", e);
return false;
}
return true;
}
use of com.odysee.app.exceptions.LbryResponseException in project odysee-android by OdyseeTeam.
the class Lbry method directApiCall.
public static Object directApiCall(String method, String authToken) throws ApiCallException {
Map<String, Object> params = new HashMap<>();
params.put("auth_token", authToken);
Object response = null;
try {
response = parseResponse(apiCall(method, params, API_CONNECTION_STRING));
} catch (LbryRequestException | LbryResponseException ex) {
throw new ApiCallException(String.format("Could not execute %s call: %s", method, ex.getMessage()), ex);
}
return response;
}
Aggregations