Fix issue #403
This commit is contained in:
parent
8f641fba77
commit
cf6c86e0c6
|
@ -482,7 +482,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
||||||
loader.setVisibility(View.GONE);
|
loader.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null) == null) {
|
if (apiResponse.getPeertubes() == null || apiResponse.getPeertubes().get(0) == null || apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService()) == null) {
|
||||||
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
Toasty.error(getApplicationContext(), getString(R.string.toast_error), Toast.LENGTH_LONG).show();
|
||||||
loader.setVisibility(View.GONE);
|
loader.setVisibility(View.GONE);
|
||||||
return;
|
return;
|
||||||
|
@ -630,7 +630,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
||||||
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
||||||
|
|
||||||
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
||||||
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null)));
|
.createMediaSource(Uri.parse(apiResponse.getPeertubes().get(0).getFileUrl(null, apiResponse.getPeertubes().get(0).isStreamService())));
|
||||||
|
|
||||||
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
player = ExoPlayerFactory.newSimpleInstance(PeertubeActivity.this);
|
||||||
playerView.setPlayer(player);
|
playerView.setPlayer(player);
|
||||||
|
@ -648,10 +648,10 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
||||||
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
if (ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(PeertubeActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||||
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
ActivityCompat.requestPermissions(PeertubeActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, Helper.EXTERNAL_STORAGE_REQUEST_CODE);
|
||||||
} else {
|
} else {
|
||||||
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null));
|
Helper.manageDownloads(PeertubeActivity.this, peertube.getFileDownloadUrl(null, peertube.isStreamService()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -846,7 +846,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube
|
||||||
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
Util.getUserAgent(getApplicationContext(), "Mastalab"), null);
|
||||||
|
|
||||||
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
ExtractorMediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
|
||||||
.createMediaSource(Uri.parse(peertube.getFileUrl(res)));
|
.createMediaSource(Uri.parse(peertube.getFileUrl(res, peertube.isStreamService())));
|
||||||
player.prepare(videoSource);
|
player.prepare(videoSource);
|
||||||
player.seekTo(0, position);
|
player.seekTo(0, position);
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
|
|
|
@ -358,13 +358,27 @@ public class API {
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
JSONArray files = resobj.getJSONArray("files");
|
|
||||||
ArrayList<String> resolutions = new ArrayList<>();
|
ArrayList<String> resolutions = new ArrayList<>();
|
||||||
|
if( resobj.has("streamingPlaylists")){
|
||||||
|
JSONArray files = resobj.getJSONArray("streamingPlaylists").getJSONObject(0).getJSONArray("files");
|
||||||
|
|
||||||
for (int j = 0; j < files.length(); j++) {
|
for (int j = 0; j < files.length(); j++) {
|
||||||
JSONObject attObj = files.getJSONObject(j);
|
JSONObject attObj = files.getJSONObject(j);
|
||||||
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
||||||
}
|
}
|
||||||
peertube.setResolution(resolutions);
|
peertube.setResolution(resolutions);
|
||||||
|
peertube.setStreamService(true);
|
||||||
|
}else {
|
||||||
|
JSONArray files = resobj.getJSONArray("files");
|
||||||
|
|
||||||
|
for (int j = 0; j < files.length(); j++) {
|
||||||
|
JSONObject attObj = files.getJSONObject(j);
|
||||||
|
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
||||||
|
}
|
||||||
|
peertube.setResolution(resolutions);
|
||||||
|
peertube.setStreamService(false);
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -3356,17 +3370,13 @@ public class API {
|
||||||
try {
|
try {
|
||||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||||
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/videos/%s", videoId), 10, null, null);
|
String response = httpsConnection.get(String.format("https://" + instance + "/api/v1/videos/%s", videoId), 10, null, null);
|
||||||
|
Helper.largeLog(response);
|
||||||
JSONObject jsonObject = new JSONObject(response);
|
JSONObject jsonObject = new JSONObject(response);
|
||||||
peertube = parseSinglePeertube(context, instance, jsonObject);
|
peertube = parseSinglePeertube(context, instance, jsonObject);
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
setError(e.getStatusCode(), e);
|
setError(e.getStatusCode(), e);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (KeyManagementException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
List<Peertube> peertubes = new ArrayList<>();
|
List<Peertube> peertubes = new ArrayList<>();
|
||||||
|
|
|
@ -14,12 +14,15 @@
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
package app.fedilab.android.client.Entities;
|
package app.fedilab.android.client.Entities;
|
||||||
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import app.fedilab.android.helper.Helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Thomas on 29/09/2018.
|
* Created by Thomas on 29/09/2018.
|
||||||
* Manage how to videos
|
* Manage how to videos
|
||||||
|
@ -56,6 +59,7 @@ public class Peertube {
|
||||||
private String headerType = null;//For overview timeline
|
private String headerType = null;//For overview timeline
|
||||||
private String headerTypeValue = null;//For overview timeline
|
private String headerTypeValue = null;//For overview timeline
|
||||||
private JSONObject cache;
|
private JSONObject cache;
|
||||||
|
private boolean streamService;
|
||||||
|
|
||||||
public Peertube() {
|
public Peertube() {
|
||||||
}
|
}
|
||||||
|
@ -174,12 +178,17 @@ public class Peertube {
|
||||||
this.account = account;
|
this.account = account;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileUrl(String resolution) {
|
public String getFileUrl(String resolution, boolean streamService) {
|
||||||
if (resolution == null)
|
if (resolution == null)
|
||||||
resolution = this.getResolution().get(0);
|
resolution = this.getResolution().get(0);
|
||||||
if (resolution == null)
|
if (resolution == null)
|
||||||
return null;
|
return null;
|
||||||
|
if( streamService) {
|
||||||
|
return "https://" + this.host + "/static/streaming-playlists/hls/" + getUuid() + "/" + getUuid() + "-" + resolution + "-fragmented.mp4";
|
||||||
|
}else{
|
||||||
return "https://" + this.host + "/static/webseed/" + getUuid() + "-" + resolution + ".mp4";
|
return "https://" + this.host + "/static/webseed/" + getUuid() + "-" + resolution + ".mp4";
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,14 +210,19 @@ public class Peertube {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileDownloadUrl(String resolution) {
|
public String getFileDownloadUrl(String resolution, boolean streamService) {
|
||||||
if (resolution == null)
|
if (resolution == null)
|
||||||
resolution = this.getResolution().get(0);
|
resolution = this.getResolution().get(0);
|
||||||
if (resolution == null)
|
if (resolution == null)
|
||||||
return null;
|
return null;
|
||||||
|
if( streamService) {
|
||||||
|
return "https://" + this.host + "/download/streaming-playlists/hls/videos/" + getUuid() + "/" + getUuid() + "-" + resolution + "-fragmented.mp4";
|
||||||
|
}else{
|
||||||
return "https://" + this.host + "/download/videos/" + getUuid() + "-" + resolution + ".mp4";
|
return "https://" + this.host + "/download/videos/" + getUuid() + "-" + resolution + ".mp4";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getResolution() {
|
public List<String> getResolution() {
|
||||||
return resolution;
|
return resolution;
|
||||||
}
|
}
|
||||||
|
@ -338,4 +352,12 @@ public class Peertube {
|
||||||
public void setHeaderTypeValue(String headerTypeValue) {
|
public void setHeaderTypeValue(String headerTypeValue) {
|
||||||
this.headerTypeValue = headerTypeValue;
|
this.headerTypeValue = headerTypeValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isStreamService() {
|
||||||
|
return streamService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreamService(boolean streamService) {
|
||||||
|
this.streamService = streamService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -364,12 +364,25 @@ public class PeertubeAPI {
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
JSONArray files = resobj.getJSONArray("files");
|
|
||||||
ArrayList<String> resolutions = new ArrayList<>();
|
ArrayList<String> resolutions = new ArrayList<>();
|
||||||
|
if( resobj.has("streamingPlaylists")){
|
||||||
|
JSONArray files = resobj.getJSONArray("streamingPlaylists").getJSONObject(0).getJSONArray("files");
|
||||||
|
|
||||||
for (int j = 0; j < files.length(); j++) {
|
for (int j = 0; j < files.length(); j++) {
|
||||||
JSONObject attObj = files.getJSONObject(j);
|
JSONObject attObj = files.getJSONObject(j);
|
||||||
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
||||||
}
|
}
|
||||||
|
peertube.setResolution(resolutions);
|
||||||
|
peertube.setStreamService(true);
|
||||||
|
}else {
|
||||||
|
JSONArray files = resobj.getJSONArray("files");
|
||||||
|
for (int j = 0; j < files.length(); j++) {
|
||||||
|
JSONObject attObj = files.getJSONObject(j);
|
||||||
|
resolutions.add(attObj.getJSONObject("resolution").get("id").toString());
|
||||||
|
}
|
||||||
|
peertube.setResolution(resolutions);
|
||||||
|
peertube.setStreamService(false);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
LinkedHashMap<String, String> langue = new LinkedHashMap<>();
|
LinkedHashMap<String, String> langue = new LinkedHashMap<>();
|
||||||
LinkedHashMap<Integer, String> category = new LinkedHashMap<>();
|
LinkedHashMap<Integer, String> category = new LinkedHashMap<>();
|
||||||
|
|
Loading…
Reference in New Issue