2017-07-11 05:08:03 +02:00
|
|
|
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
|
|
|
|
*/
|
2017-07-11 05:08:03 +02:00
|
|
|
public abstract class Stream implements Serializable {
|
2017-11-11 01:21:43 +01:00
|
|
|
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;
|
2017-11-11 12:17:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getFormat()} or {@link #getFormatId()}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2017-11-11 02:55:56 +01:00
|
|
|
public final int format;
|
2017-07-11 05:08:03 +02:00
|
|
|
|
2019-03-23 14:41:51 +01:00
|
|
|
/**
|
|
|
|
* Instantiates a new stream object.
|
|
|
|
*
|
|
|
|
* @param url the url
|
|
|
|
* @param format the format
|
|
|
|
*/
|
2017-11-11 01:21:43 +01:00
|
|
|
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) {
|
2017-07-11 05:08:03 +02:00
|
|
|
this.url = url;
|
2018-12-30 10:30:57 +01:00
|
|
|
this.torrentUrl = torrentUrl;
|
2017-11-11 01:21:43 +01:00
|
|
|
this.format = format.id;
|
|
|
|
this.mediaFormat = format;
|
2017-07-11 05:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-06 22:20:15 +02:00
|
|
|
* Reveals whether two streams have the same stats (format and bitrate, for example)
|
2017-07-11 05:08:03 +02:00
|
|
|
*/
|
|
|
|
public boolean equalStats(Stream cmp) {
|
2017-11-11 12:17:14 +01:00
|
|
|
return cmp != null && getFormatId() == cmp.getFormatId();
|
2017-07-11 05:08:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2017-11-11 01:21:43 +01:00
|
|
|
|
2019-03-23 14:41:51 +01:00
|
|
|
/**
|
|
|
|
* Gets the url.
|
|
|
|
*
|
|
|
|
* @return the url
|
|
|
|
*/
|
2017-11-11 01:21:43 +01:00
|
|
|
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;
|
|
|
|
}
|
2017-11-11 01:21:43 +01:00
|
|
|
|
2019-03-23 14:41:51 +01:00
|
|
|
/**
|
|
|
|
* Gets the format.
|
|
|
|
*
|
|
|
|
* @return the format
|
|
|
|
*/
|
2017-11-11 01:21:43 +01:00
|
|
|
public MediaFormat getFormat() {
|
|
|
|
return mediaFormat;
|
|
|
|
}
|
2017-11-11 12:17:14 +01:00
|
|
|
|
2019-03-23 14:41:51 +01:00
|
|
|
/**
|
|
|
|
* Gets the format id.
|
|
|
|
*
|
|
|
|
* @return the format id
|
|
|
|
*/
|
2017-11-11 12:17:14 +01:00
|
|
|
public int getFormatId() {
|
|
|
|
return mediaFormat.id;
|
|
|
|
}
|
2017-07-11 05:08:03 +02:00
|
|
|
}
|