mirror of https://github.com/TeamNewPipe/NewPipe
120 lines
3.4 KiB
Java
120 lines
3.4 KiB
Java
package org.schabi.newpipe.playlist;
|
|
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfo;
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
import org.schabi.newpipe.util.ExtractorHelper;
|
|
|
|
import java.io.Serializable;
|
|
|
|
import io.reactivex.Single;
|
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
import io.reactivex.functions.Consumer;
|
|
import io.reactivex.schedulers.Schedulers;
|
|
|
|
public class PlayQueueItem implements Serializable {
|
|
final public static long RECOVERY_UNSET = Long.MIN_VALUE;
|
|
|
|
final private String title;
|
|
final private String url;
|
|
final private int serviceId;
|
|
final private long duration;
|
|
final private String thumbnailUrl;
|
|
final private String uploader;
|
|
final private StreamType streamType;
|
|
|
|
private long recoveryPosition;
|
|
private Throwable error;
|
|
|
|
private transient Single<StreamInfo> stream;
|
|
|
|
PlayQueueItem(@NonNull final StreamInfo info) {
|
|
this(info.getName(), info.getUrl(), info.getServiceId(), info.getDuration(),
|
|
info.getThumbnailUrl(), info.getUploaderName(), info.getStreamType());
|
|
this.stream = Single.just(info);
|
|
}
|
|
|
|
PlayQueueItem(@NonNull final StreamInfoItem item) {
|
|
this(item.getName(), item.getUrl(), item.getServiceId(), item.getDuration(),
|
|
item.getThumbnailUrl(), item.getUploaderName(), item.getStreamType());
|
|
}
|
|
|
|
private PlayQueueItem(final String name, final String url, final int serviceId,
|
|
final long duration, final String thumbnailUrl, final String uploader,
|
|
final StreamType streamType) {
|
|
this.title = name;
|
|
this.url = url;
|
|
this.serviceId = serviceId;
|
|
this.duration = duration;
|
|
this.thumbnailUrl = thumbnailUrl;
|
|
this.uploader = uploader;
|
|
this.streamType = streamType;
|
|
|
|
this.recoveryPosition = RECOVERY_UNSET;
|
|
}
|
|
|
|
@NonNull
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
@NonNull
|
|
public String getUrl() {
|
|
return url;
|
|
}
|
|
|
|
public int getServiceId() {
|
|
return serviceId;
|
|
}
|
|
|
|
public long getDuration() {
|
|
return duration;
|
|
}
|
|
|
|
@NonNull
|
|
public String getThumbnailUrl() {
|
|
return thumbnailUrl;
|
|
}
|
|
|
|
@NonNull
|
|
public String getUploader() {
|
|
return uploader;
|
|
}
|
|
|
|
public StreamType getStreamType() {
|
|
return streamType;
|
|
}
|
|
|
|
public long getRecoveryPosition() {
|
|
return recoveryPosition;
|
|
}
|
|
|
|
@Nullable
|
|
public Throwable getError() {
|
|
return error;
|
|
}
|
|
|
|
@NonNull
|
|
public Single<StreamInfo> getStream() {
|
|
return stream == null ? stream = getInfo() : stream;
|
|
}
|
|
|
|
@NonNull
|
|
private Single<StreamInfo> getInfo() {
|
|
return ExtractorHelper.getStreamInfo(this.serviceId, this.url, false)
|
|
.subscribeOn(Schedulers.io())
|
|
.doOnError(throwable -> error = throwable);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
// Item States, keep external access out
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
/*package-private*/ void setRecoveryPosition(final long recoveryPosition) {
|
|
this.recoveryPosition = recoveryPosition;
|
|
}
|
|
}
|