2017-03-01 18:47:52 +01:00
|
|
|
package org.schabi.newpipe.extractor.search;
|
|
|
|
|
2017-11-11 12:17:14 +01:00
|
|
|
import org.schabi.newpipe.extractor.*;
|
2018-02-24 22:20:50 +01:00
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
|
2017-08-11 03:23:09 +02:00
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
|
2017-03-01 18:47:52 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2017-11-11 12:17:14 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2018-02-24 22:20:50 +01:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
|
2017-08-16 02:11:38 +02:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
|
2018-02-24 22:20:50 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
2017-06-29 20:12:55 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/*
|
2017-03-01 18:47:52 +01:00
|
|
|
* Created by Christian Schabesberger on 12.02.17.
|
|
|
|
*
|
|
|
|
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
|
2018-02-24 22:20:50 +01:00
|
|
|
* InfoItemsSearchCollector.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/>.
|
|
|
|
*/
|
|
|
|
|
2017-11-11 12:17:14 +01:00
|
|
|
/**
|
|
|
|
* Collector for search results
|
|
|
|
*
|
|
|
|
* This collector can handle the following extractor types:
|
|
|
|
* <ul>
|
|
|
|
* <li>{@link StreamInfoItemExtractor}</li>
|
|
|
|
* <li>{@link ChannelInfoItemExtractor}</li>
|
|
|
|
* <li>{@link PlaylistInfoItemExtractor}</li>
|
|
|
|
* </ul>
|
|
|
|
* Calling {@link #extract(InfoItemExtractor)} or {@link #commit(Object)} with any
|
|
|
|
* other extractor type will raise an exception.
|
|
|
|
*/
|
2018-02-24 22:20:50 +01:00
|
|
|
public class InfoItemsSearchCollector extends InfoItemsCollector<InfoItem, InfoItemExtractor> {
|
2017-08-08 17:01:50 +02:00
|
|
|
private String suggestion = "";
|
2018-02-24 22:20:50 +01:00
|
|
|
private final StreamInfoItemsCollector streamCollector;
|
|
|
|
private final ChannelInfoItemsCollector userCollector;
|
|
|
|
private final PlaylistInfoItemsCollector playlistCollector;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2018-02-24 22:20:50 +01:00
|
|
|
InfoItemsSearchCollector(int serviceId) {
|
2017-03-01 18:47:52 +01:00
|
|
|
super(serviceId);
|
2018-02-24 22:20:50 +01:00
|
|
|
streamCollector = new StreamInfoItemsCollector(serviceId);
|
|
|
|
userCollector = new ChannelInfoItemsCollector(serviceId);
|
|
|
|
playlistCollector = new PlaylistInfoItemsCollector(serviceId);
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSuggestion(String suggestion) {
|
|
|
|
this.suggestion = suggestion;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SearchResult getSearchResult() throws ExtractionException {
|
2017-11-11 12:17:14 +01:00
|
|
|
return new SearchResult(getServiceId(), suggestion, getItemList(), getErrors());
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-08-16 02:11:38 +02:00
|
|
|
|
2017-11-11 12:17:14 +01:00
|
|
|
@Override
|
|
|
|
public InfoItem extract(InfoItemExtractor extractor) throws ParsingException {
|
|
|
|
// Use the corresponding collector for each item extractor type
|
|
|
|
if(extractor instanceof StreamInfoItemExtractor) {
|
|
|
|
return streamCollector.extract((StreamInfoItemExtractor) extractor);
|
|
|
|
} else if(extractor instanceof ChannelInfoItemExtractor) {
|
|
|
|
return userCollector.extract((ChannelInfoItemExtractor) extractor);
|
|
|
|
} else if(extractor instanceof PlaylistInfoItemExtractor) {
|
|
|
|
return playlistCollector.extract((PlaylistInfoItemExtractor) extractor);
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Invalid extractor type: " + extractor);
|
2017-08-16 02:11:38 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|