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

107 lines
3.4 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.stream;
2017-03-01 18:47:52 +01:00
2017-08-13 00:58:29 +02:00
import org.schabi.newpipe.extractor.InfoItem;
2018-02-24 22:20:50 +01:00
import org.schabi.newpipe.extractor.InfoItemsCollector;
2017-03-01 18:47:52 +01:00
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2017-08-13 00:58:29 +02:00
import java.util.List;
import java.util.Vector;
/*
2017-03-01 18:47:52 +01:00
* Created by Christian Schabesberger on 28.02.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
2018-02-24 22:20:50 +01:00
* StreamInfoItemsCollector.java is part of NewPipe.
2017-03-01 18:47:52 +01:00
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
2018-02-24 22:20:50 +01:00
public class StreamInfoItemsCollector extends InfoItemsCollector<StreamInfoItem, StreamInfoItemExtractor> {
2017-03-01 18:47:52 +01:00
2018-02-24 22:20:50 +01:00
public StreamInfoItemsCollector(int serviceId) {
2017-03-01 18:47:52 +01:00
super(serviceId);
}
@Override
public StreamInfoItem extract(StreamInfoItemExtractor extractor) throws ParsingException {
if (extractor.isAd()) {
2017-03-01 18:47:52 +01:00
throw new FoundAdException("Found ad");
}
2017-06-29 19:34:21 +02:00
// important information
2017-11-11 02:55:56 +01:00
int serviceId = getServiceId();
String url = extractor.getUrl();
String name = extractor.getName();
StreamType streamType = extractor.getStreamType();
StreamInfoItem resultItem = new StreamInfoItem(serviceId, url, name, streamType);
2017-03-01 18:47:52 +01:00
// optional information
try {
2017-11-11 02:55:56 +01:00
resultItem.setDuration(extractor.getDuration());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
addError(e);
}
try {
2017-11-11 02:55:56 +01:00
resultItem.setUploaderName(extractor.getUploaderName());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
addError(e);
}
try {
2017-11-11 02:55:56 +01:00
resultItem.setUploadDate(extractor.getUploadDate());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
addError(e);
}
try {
2017-11-11 02:55:56 +01:00
resultItem.setViewCount(extractor.getViewCount());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
addError(e);
}
try {
2017-11-11 02:55:56 +01:00
resultItem.setThumbnailUrl(extractor.getThumbnailUrl());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
addError(e);
}
2017-11-11 12:46:14 +01:00
try {
resultItem.setUploaderUrl(extractor.getUploaderUrl());
} catch (Exception e) {
addError(e);
}
2017-03-01 18:47:52 +01:00
return resultItem;
}
@Override
public void commit(StreamInfoItemExtractor extractor) {
2017-03-01 18:47:52 +01:00
try {
addItem(extract(extractor));
} catch (FoundAdException ae) {
2017-03-01 18:47:52 +01:00
//System.out.println("AD_WARNING: " + ae.getMessage());
} catch (Exception e) {
addError(e);
}
}
2017-08-13 00:58:29 +02:00
public List<StreamInfoItem> getStreamInfoItemList() {
List<StreamInfoItem> siiList = new Vector<>();
for(InfoItem ii : super.getItems()) {
2017-08-13 00:58:29 +02:00
if(ii instanceof StreamInfoItem) {
siiList.add((StreamInfoItem) ii);
}
}
return siiList;
}
2017-03-01 18:47:52 +01:00
}