1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

make colector hirarchicall

remove broken commit()
This commit is contained in:
Christian Schabesberger 2017-02-12 13:33:03 +01:00
parent ef15902ec4
commit 5c8bcf15ba
14 changed files with 170 additions and 59 deletions

View File

@ -46,6 +46,7 @@ import org.schabi.newpipe.Localization;
import org.schabi.newpipe.R;
import org.schabi.newpipe.ReCaptchaActivity;
import org.schabi.newpipe.download.DownloadDialog;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.stream_info.AudioStream;
@ -536,7 +537,7 @@ public class VideoItemDetailFragment extends Fragment {
private void initSimilarVideos(final StreamInfo info) {
LinearLayout similarLayout = (LinearLayout) activity.findViewById(R.id.similar_streams_view);
for (final StreamInfoItem item : info.related_streams) {
for (final InfoItem item : info.related_streams) {
similarLayout.addView(infoItemBuilder.buildView(similarLayout, item));
}
infoItemBuilder.setOnItemSelectedListener(new InfoItemBuilder.OnItemSelectedListener() {

View File

@ -1,9 +1,5 @@
package org.schabi.newpipe.extractor;
import android.icu.text.IDNA;
import static org.schabi.newpipe.extractor.InfoItem.InfoType.STREAM;
/**
* Created by the-scrabi on 11.02.17.
*
@ -30,6 +26,8 @@ public interface InfoItem {
PLAYLIST,
CHANNEL
}
void setInfoType(InfoType iT);
InfoType getInfoType();
InfoType infoType();
String getTitle();
String getLink();
}

View File

@ -0,0 +1,66 @@
package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import java.util.List;
import java.util.Vector;
/**
* Created by Christian Schabesberger on 12.02.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* InfoItemCollector.java is part of NewPipe.
*
* 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/>.
*/
public class InfoItemCollector {
private List<InfoItem> itemList = new Vector<>();
private List<Throwable> errors = new Vector<>();
private UrlIdHandler urlIdHandler;
private int serviceId = -1;
public InfoItemCollector(UrlIdHandler handler, int serviceId) {
urlIdHandler = handler;
this.serviceId = serviceId;
}
public List<InfoItem> getItemList() {
return itemList;
}
public List<Throwable> getErrors() {
return errors;
}
public void addFromCollector(InfoItemCollector otherC) throws ExtractionException {
if(serviceId != otherC.serviceId) {
throw new ExtractionException("Service Id does not equal: "
+ NewPipe.getNameOfService(serviceId)
+ " and " + NewPipe.getNameOfService(otherC.serviceId));
}
errors.addAll(otherC.errors);
itemList.addAll(otherC.itemList);
}
protected void addError(Exception e) {
errors.add(e);
}
protected void addItem(InfoItem item) {
itemList.add(item);
}
protected int getServiceId() {
return serviceId;
}
protected UrlIdHandler getUrlIdHandler() {
return urlIdHandler;
}
}

View File

@ -75,7 +75,7 @@ public class ChannelInfo {
public String avatar_url = "";
public String banner_url = "";
public String feed_url = "";
public List<StreamInfoItem> related_streams = null;
public List<InfoItem> related_streams = null;
public boolean hasNextPage = false;
public List<Throwable> errors = new Vector<>();

View File

@ -1,8 +1,38 @@
package org.schabi.newpipe.extractor.channel;
import org.schabi.newpipe.extractor.InfoItem;
/**
* Created by the-scrabi on 11.02.17.
* Created by Christian Schabesberger on 11.02.17.
*
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* ChannelInfoItem.java is part of NewPipe.
*
* 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/>.
*/
public class ChannelInfoItem {
public class ChannelInfoItem implements InfoItem {
public InfoType infoType() {
return InfoType.CHANNEL;
}
public String getTitle() {
return "";
}
public String getLink() {
return "";
}
}

View File

@ -1,13 +1,13 @@
package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.InfoItemCollector;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItemCollector;
/**
* Created by Christian Schabesberger on 11.05.16.
* Created by Christian Schabesberger on 12.02.17.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* StreamInfoSearchItemCollector.java is part of NewPipe.
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org>
* InfoItemSearchCollector.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,11 +23,10 @@ import org.schabi.newpipe.extractor.stream_info.StreamInfoItemCollector;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class StreamInfoSearchItemCollector extends StreamInfoItemCollector {
public class InfoItemSearchCollector extends InfoItemCollector {
private String suggestion = "";
public StreamInfoSearchItemCollector(UrlIdHandler handler, int serviceId) {
InfoItemSearchCollector(UrlIdHandler handler, int serviceId) {
super(handler, serviceId);
}

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItemCollector;
import java.io.IOException;
@ -32,18 +33,23 @@ public abstract class SearchEngine {
}
}
private StreamInfoSearchItemCollector collector;
private StreamInfoItemCollector streamCollector;
private InfoItemSearchCollector collector;
public SearchEngine(UrlIdHandler urlIdHandler, int serviceId) {
collector = new StreamInfoSearchItemCollector(urlIdHandler, serviceId);
streamCollector = new StreamInfoItemCollector(urlIdHandler, serviceId);
collector = new InfoItemSearchCollector(urlIdHandler, serviceId);
}
protected StreamInfoSearchItemCollector getStreamPreviewInfoSearchCollector() {
protected StreamInfoItemCollector getStreamPreviewInfoCollector() {
return streamCollector;
}
protected InfoItemSearchCollector getInfoItemSearchCollector() {
return collector;
}
//Result search(String query, int page);
public abstract StreamInfoSearchItemCollector search(
public abstract InfoItemSearchCollector search(
String query, int page, String contentCountry)
throws ExtractionException, IOException;
}

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItem;
@ -45,6 +46,6 @@ public class SearchResult {
}
public String suggestion = "";
public List<StreamInfoItem> resultList = new Vector<>();
public List<InfoItem> resultList = new Vector<>();
public List<Throwable> errors = new Vector<>();
}

View File

@ -7,8 +7,9 @@ import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.InfoItemSearchCollector;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.StreamInfoSearchItemCollector;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItemExtractor;
import java.net.URLEncoder;
@ -45,9 +46,11 @@ public class YoutubeSearchEngine extends SearchEngine {
}
@Override
public StreamInfoSearchItemCollector search(String query, int page, String languageCode)
public InfoItemSearchCollector search(String query, int page, String languageCode)
throws IOException, ExtractionException {
StreamInfoSearchItemCollector collector = getStreamPreviewInfoSearchCollector();
StreamInfoItemCollector streamCollector = getStreamPreviewInfoCollector();
InfoItemSearchCollector collector = getInfoItemSearchCollector();
Downloader downloader = NewPipe.getDownloader();
@ -97,13 +100,13 @@ public class YoutubeSearchEngine extends SearchEngine {
// video item type
} else if ((el = item.select("div[class*=\"yt-lockup-video\"").first()) != null) {
collector.commit(extractPreviewInfo(el));
streamCollector.commit(extractPreviewInfo(el));
} else {
//noinspection ConstantConditions
collector.addError(new Exception("unexpected element found:\"" + el + "\""));
throw new ExtractionException("unexpected element found:\"" + el + "\"");
}
}
collector.addFromCollector(streamCollector);
return collector;
}

View File

@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.stream_info;
import org.schabi.newpipe.extractor.AbstractStreamInfo;
import org.schabi.newpipe.extractor.DashMpdParser;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -246,7 +247,7 @@ public class StreamInfo extends AbstractStreamInfo {
StreamInfoItemExtractor nextVideo = extractor.getNextVideo();
c.commit(nextVideo);
if(c.getItemList().size() != 0) {
streamInfo.next_video = c.getItemList().get(0);
streamInfo.next_video = (StreamInfoItem) c.getItemList().get(0);
}
streamInfo.errors.addAll(c.getErrors());
}
@ -285,7 +286,7 @@ public class StreamInfo extends AbstractStreamInfo {
public int dislike_count = -1;
public String average_rating = "";
public StreamInfoItem next_video = null;
public List<StreamInfoItem> related_streams = null;
public List<InfoItem> related_streams = null;
//in seconds. some metadata is not passed using a StreamInfo object!
public int start_position = 0;

View File

@ -21,8 +21,21 @@ package org.schabi.newpipe.extractor.stream_info;
*/
import org.schabi.newpipe.extractor.AbstractStreamInfo;
import org.schabi.newpipe.extractor.InfoItem;
/**Info object for previews of unopened videos, eg search results, related videos*/
public class StreamInfoItem extends AbstractStreamInfo {
public class StreamInfoItem extends AbstractStreamInfo implements InfoItem {
public int duration;
public InfoType infoType() {
return InfoType.STREAM;
}
public String getTitle() {
return title;
}
public String getLink() {
return webpage_url;
}
}

View File

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor.stream_info;
import org.schabi.newpipe.extractor.InfoItemCollector;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
@ -28,39 +29,24 @@ import java.util.Vector;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class StreamInfoItemCollector {
private List<StreamInfoItem> itemList = new Vector<>();
private List<Throwable> errors = new Vector<>();
private UrlIdHandler urlIdHandler;
private int serviceId = -1;
public class StreamInfoItemCollector extends InfoItemCollector {
public StreamInfoItemCollector(UrlIdHandler handler, int serviceId) {
urlIdHandler = handler;
this.serviceId = serviceId;
}
public List<StreamInfoItem> getItemList() {
return itemList;
}
public List<Throwable> getErrors() {
return errors;
}
public void addError(Exception e) {
errors.add(e);
super(handler, serviceId);
}
public void commit(StreamInfoItemExtractor extractor) throws ParsingException {
try {
StreamInfoItem resultItem = new StreamInfoItem();
// importand information
resultItem.service_id = serviceId;
resultItem.service_id = getServiceId();
resultItem.webpage_url = extractor.getWebPageUrl();
if (urlIdHandler == null) {
if (getUrlIdHandler() == null) {
throw new ParsingException("Error: UrlIdHandler not set");
} else if(!resultItem.webpage_url.isEmpty()) {
resultItem.id = NewPipe.getService(serviceId).getUrlIdHandlerInstance().getId(resultItem.webpage_url);
resultItem.id = NewPipe.getService(getServiceId())
.getUrlIdHandlerInstance()
.getId(resultItem.webpage_url);
}
resultItem.title = extractor.getTitle();
resultItem.stream_type = extractor.getStreamType();
@ -91,7 +77,7 @@ public class StreamInfoItemCollector {
} catch (Exception e) {
addError(e);
}
itemList.add(resultItem);
addItem(resultItem);
} catch(FoundAdException ae) {
System.out.println("AD_WARNING: " + ae.getMessage());
} catch (Exception e) {

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.info_list;
import android.app.Activity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,6 +12,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
import org.schabi.newpipe.ImageErrorLoadingListener;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.AbstractStreamInfo;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItem;
/**
@ -55,7 +57,11 @@ public class InfoItemBuilder {
this.onItemSelectedListener = onItemSelectedListener;
}
public void buildByHolder(InfoItemHolder holder, final StreamInfoItem info) {
public void buildByHolder(InfoItemHolder holder, final InfoItem i) {
final StreamInfoItem info = (StreamInfoItem) i;
if(info.infoType() != InfoItem.InfoType.STREAM) {
Log.e("InfoItemBuilder", "Info type not yet supported");
}
// fill holder with information
holder.itemVideoTitleView.setText(info.title);
if(info.uploader != null && !info.uploader.isEmpty()) {
@ -97,7 +103,7 @@ public class InfoItemBuilder {
});
}
public View buildView(ViewGroup parent, final StreamInfoItem info) {
public View buildView(ViewGroup parent, final InfoItem info) {
View streamPreviewView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.video_item, parent, false);
InfoItemHolder holder = new InfoItemHolder(streamPreviewView);

View File

@ -7,6 +7,7 @@ import android.view.View;
import android.view.ViewGroup;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.stream_info.StreamInfoItem;
import java.util.List;
@ -35,7 +36,7 @@ import java.util.Vector;
public class InfoListAdapter extends RecyclerView.Adapter<InfoItemHolder> {
private final InfoItemBuilder infoItemBuilder;
private final List<StreamInfoItem> streamList;
private final List<InfoItem> streamList;
public InfoListAdapter(Activity a, View rootView) {
infoItemBuilder = new InfoItemBuilder(a, rootView);
@ -47,7 +48,7 @@ public class InfoListAdapter extends RecyclerView.Adapter<InfoItemHolder> {
infoItemBuilder.setOnItemSelectedListener(onItemSelectedListener);
}
public void addStreamItemList(List<StreamInfoItem> videos) {
public void addStreamItemList(List<InfoItem> videos) {
if(videos!= null) {
streamList.addAll(videos);
notifyDataSetChanged();