2017-08-29 02:38:37 +02:00
|
|
|
package org.schabi.newpipe.playlist;
|
|
|
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
import java.io.Serializable;
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
import io.reactivex.Single;
|
2017-08-29 02:38:37 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
|
import io.reactivex.functions.Consumer;
|
|
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
public class PlayQueueItem implements Serializable {
|
|
|
|
|
|
|
|
final public static int DEFAULT_QUALITY = -1;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-03 04:30:34 +02:00
|
|
|
final private String title;
|
|
|
|
final private String url;
|
|
|
|
final private int serviceId;
|
2017-09-04 19:23:56 +02:00
|
|
|
final private long duration;
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
// Externally mutable, not sure if this is a good idea here
|
|
|
|
private int sortedQualityIndex;
|
|
|
|
|
2017-08-29 02:38:37 +02:00
|
|
|
private Throwable error;
|
2017-09-05 21:27:12 +02:00
|
|
|
|
|
|
|
PlayQueueItem(final StreamInfo streamInfo, final int sortedQualityIndex) {
|
|
|
|
this.title = streamInfo.name;
|
|
|
|
this.url = streamInfo.url;
|
|
|
|
this.serviceId = streamInfo.service_id;
|
|
|
|
this.duration = streamInfo.duration;
|
|
|
|
|
|
|
|
this.sortedQualityIndex = sortedQualityIndex;
|
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
|
2017-09-03 04:30:34 +02:00
|
|
|
PlayQueueItem(final StreamInfoItem streamInfoItem) {
|
2017-09-04 19:23:56 +02:00
|
|
|
this.title = streamInfoItem.name;
|
|
|
|
this.url = streamInfoItem.url;
|
2017-08-29 02:38:37 +02:00
|
|
|
this.serviceId = streamInfoItem.service_id;
|
|
|
|
this.duration = streamInfoItem.duration;
|
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
this.sortedQualityIndex = DEFAULT_QUALITY;
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
|
2017-08-29 02:38:37 +02:00
|
|
|
@NonNull
|
|
|
|
public String getTitle() {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getUrl() {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getServiceId() {
|
|
|
|
return serviceId;
|
|
|
|
}
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
public long getDuration() {
|
2017-08-29 02:38:37 +02:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2017-09-05 21:27:12 +02:00
|
|
|
public int getSortedQualityIndex() {
|
|
|
|
return sortedQualityIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSortedQualityIndex(int sortedQualityIndex) {
|
|
|
|
this.sortedQualityIndex = sortedQualityIndex;
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:38:37 +02:00
|
|
|
@Nullable
|
|
|
|
public Throwable getError() {
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2017-09-04 19:23:56 +02:00
|
|
|
public Single<StreamInfo> getStream() {
|
2017-08-29 02:38:37 +02:00
|
|
|
final Consumer<Throwable> onError = new Consumer<Throwable>() {
|
|
|
|
@Override
|
|
|
|
public void accept(Throwable throwable) throws Exception {
|
|
|
|
error = throwable;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-04 19:23:56 +02:00
|
|
|
return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false)
|
2017-08-29 02:38:37 +02:00
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
2017-09-04 04:15:11 +02:00
|
|
|
.retry(3)
|
2017-09-04 19:23:56 +02:00
|
|
|
.doOnError(onError);
|
2017-09-03 04:30:34 +02:00
|
|
|
}
|
2017-08-29 02:38:37 +02:00
|
|
|
}
|