NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/stream/Stream.java

107 lines
2.5 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.stream;
import java.io.Serializable;
import java.util.List;
2018-12-30 10:30:57 +01:00
import org.schabi.newpipe.extractor.MediaFormat;
2019-03-23 15:02:06 +01:00
/**
* Creates a stream object from url, format and optional torrent url
*/
public abstract class Stream implements Serializable {
private final MediaFormat mediaFormat;
2017-11-11 02:55:56 +01:00
public final String url;
2018-12-30 10:30:57 +01:00
public final String torrentUrl;
/**
* @deprecated Use {@link #getFormat()} or {@link #getFormatId()}
*/
@Deprecated
2017-11-11 02:55:56 +01:00
public final int format;
2019-03-23 14:41:51 +01:00
/**
* Instantiates a new stream object.
*
* @param url the url
* @param format the format
*/
public Stream(String url, MediaFormat format) {
2018-12-30 10:30:57 +01:00
this(url, null, format);
}
2019-03-23 14:41:51 +01:00
/**
* Instantiates a new stream object.
*
* @param url the url
* @param torrentUrl the url to torrent file, example https://webtorrent.io/torrents/big-buck-bunny.torrent
* @param format the format
*/
2018-12-30 10:30:57 +01:00
public Stream(String url, String torrentUrl, MediaFormat format) {
this.url = url;
2018-12-30 10:30:57 +01:00
this.torrentUrl = torrentUrl;
this.format = format.id;
this.mediaFormat = format;
}
/**
2017-08-06 22:20:15 +02:00
* Reveals whether two streams have the same stats (format and bitrate, for example)
*/
public boolean equalStats(Stream cmp) {
return cmp != null && getFormatId() == cmp.getFormatId();
}
/**
* Reveals whether two Streams are equal
*/
public boolean equals(Stream cmp) {
return equalStats(cmp) && url.equals(cmp.url);
}
/**
* Check if the list already contains one stream with equals stats
*/
public static boolean containSimilarStream(Stream stream, List<? extends Stream> streamList) {
if (stream == null || streamList == null) return false;
for (Stream cmpStream : streamList) {
if (stream.equalStats(cmpStream)) return true;
}
return false;
}
2019-03-23 14:41:51 +01:00
/**
* Gets the url.
*
* @return the url
*/
public String getUrl() {
return url;
}
2018-12-30 10:53:24 +01:00
2019-03-23 14:41:51 +01:00
/**
* Gets the torrent url.
*
* @return the torrent url, example https://webtorrent.io/torrents/big-buck-bunny.torrent
*/
2018-12-30 10:53:24 +01:00
public String getTorrentUrl() {
return torrentUrl;
}
2019-03-23 14:41:51 +01:00
/**
* Gets the format.
*
* @return the format
*/
public MediaFormat getFormat() {
return mediaFormat;
}
2019-03-23 14:41:51 +01:00
/**
* Gets the format id.
*
* @return the format id
*/
public int getFormatId() {
return mediaFormat.id;
}
}