make less tests fail

This commit is contained in:
Christian Schabesberger 2018-07-01 16:21:40 +02:00
parent 17f46b8b12
commit bd5423fe2a
59 changed files with 582 additions and 399 deletions

View file

@ -2,6 +2,8 @@ package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.UIHandler;
import org.schabi.newpipe.extractor.uih.UIHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -14,27 +16,27 @@ public abstract class Extractor {
*/ */
private final StreamingService service; private final StreamingService service;
private final UIHFactory UIHFactory; private final org.schabi.newpipe.extractor.uih.UIHandler uIHandler;
@Nullable @Nullable
private boolean pageFetched = false; private boolean pageFetched = false;
private final Downloader downloader; private final Downloader downloader;
public Extractor(final StreamingService service, final UIHFactory UIHFactory) { public Extractor(final StreamingService service, final UIHandler uIHandler) {
if(service == null) throw new NullPointerException("service is null"); if(service == null) throw new NullPointerException("service is null");
if(UIHFactory == null) throw new NullPointerException("UIHFactory is null"); if(uIHandler == null) throw new NullPointerException("UIHandler is null");
this.service = service; this.service = service;
this.UIHFactory = UIHFactory; this.uIHandler = uIHandler;
this.downloader = NewPipe.getDownloader(); this.downloader = NewPipe.getDownloader();
if(downloader == null) throw new NullPointerException("downloader is null"); if(downloader == null) throw new NullPointerException("downloader is null");
} }
/** /**
* @return The {@link UIHFactory} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler). * @return The {@link UIHandler} of the current extractor object (e.g. a ChannelExtractor should return a channel url handler).
*/ */
@Nonnull @Nonnull
public UIHFactory getUIHFactory() { public UIHandler getUIHandler() {
return UIHFactory; return uIHandler;
} }
/** /**
@ -66,7 +68,7 @@ public abstract class Extractor {
@Nonnull @Nonnull
public String getId() throws ParsingException { public String getId() throws ParsingException {
return UIHFactory.getId(); return uIHandler.getId();
} }
/** /**
@ -79,12 +81,12 @@ public abstract class Extractor {
@Nonnull @Nonnull
public String getOriginalUrl() throws ParsingException { public String getOriginalUrl() throws ParsingException {
return UIHFactory.getOriginalUrl(); return uIHandler.getOriginalUrl();
} }
@Nonnull @Nonnull
public String getUrl() throws ParsingException { public String getUrl() throws ParsingException {
return UIHFactory.getUrl(); return uIHandler.getUrl();
} }
@Nonnull @Nonnull

View file

@ -1,6 +1,8 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.uih.UIHandler;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -18,7 +20,7 @@ public abstract class Info implements Serializable {
/** /**
* Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned url. * Different than the {@link #originalUrl} in the sense that it <i>may</i> be set as a cleaned url.
* *
* @see UIHFactory#getUrl() * @see UIHandler#getUrl()
* @see Extractor#getOriginalUrl() * @see Extractor#getOriginalUrl()
*/ */
private final String url; private final String url;
@ -48,11 +50,11 @@ public abstract class Info implements Serializable {
this.name = name; this.name = name;
} }
public Info(int serviceId, UIHFactory UIHFactory, String name) throws ParsingException { public Info(int serviceId, UIHandler uiHandler, String name) {
this(serviceId, this(serviceId,
UIHFactory.getId(), uiHandler.getId(),
UIHFactory.getUrl(), uiHandler.getUrl(),
UIHFactory.getOriginalUrl(), uiHandler.getOriginalUrl(),
name); name);
} }

View file

@ -1,8 +1,11 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.swing.plaf.ListUI;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -12,8 +15,8 @@ import java.util.List;
*/ */
public abstract class ListExtractor<R extends InfoItem> extends Extractor { public abstract class ListExtractor<R extends InfoItem> extends Extractor {
public ListExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public ListExtractor(StreamingService service, ListUIHandler uiHandler) {
super(service, urlIdHandler); super(service, uiHandler);
} }
/** /**
@ -50,8 +53,8 @@ public abstract class ListExtractor<R extends InfoItem> extends Extractor {
} }
@Override @Override
public ListUIHFactory getUIHFactory() { public ListUIHandler getUIHandler() {
return (ListUIHFactory) super.getUIHFactory(); return (ListUIHandler) super.getUIHandler();
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////

View file

@ -1,6 +1,7 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -8,7 +9,7 @@ import java.util.List;
public abstract class ListInfo<T extends InfoItem> extends Info { public abstract class ListInfo<T extends InfoItem> extends Info {
private List<T> relatedItems; private List<T> relatedItems;
private String nextPageUrl = null; private String nextPageUrl = null;
private List<String> contentFilter = new ArrayList<>(); private List<String> contentFilters = new ArrayList<>();
private String sortFilter = ""; private String sortFilter = "";
public ListInfo(int serviceId, public ListInfo(int serviceId,
@ -19,13 +20,13 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
List<String> contentFilter, List<String> contentFilter,
String sortFilter) { String sortFilter) {
super(serviceId, id, url, originalUrl, name); super(serviceId, id, url, originalUrl, name);
this.contentFilter = contentFilter; this.contentFilters = contentFilter;
this.sortFilter = sortFilter; this.sortFilter = sortFilter;
} }
public ListInfo(int serviceId, ListUIHFactory listUrlIdHandler, String name) throws ParsingException { public ListInfo(int serviceId, ListUIHandler listUrlIdHandler, String name) throws ParsingException {
super(serviceId, listUrlIdHandler, name); super(serviceId, listUrlIdHandler, name);
this.contentFilter = listUrlIdHandler.getContentFilter(); this.contentFilters = listUrlIdHandler.getContentFilters();
this.sortFilter = listUrlIdHandler.getSortFilter(); this.sortFilter = listUrlIdHandler.getSortFilter();
} }
@ -49,8 +50,8 @@ public abstract class ListInfo<T extends InfoItem> extends Info {
this.nextPageUrl = pageUrl; this.nextPageUrl = pageUrl;
} }
public List<String> getContentFilter() { public List<String> getContentFilters() {
return contentFilter; return contentFilters;
} }
public String getSortFilter() { public String getSortFilter() {

View file

@ -1,62 +0,0 @@
package org.schabi.newpipe.extractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.List;
public abstract class ListUIHFactory extends UIHFactory {
protected List<String> contentFilter = new ArrayList<>(0);
protected String sortFilter = "";
public ListUIHFactory setQuery(String id,
List<String> contentFilter,
String sortFilter) throws ParsingException {
setId(id);
this.contentFilter = contentFilter;
this.sortFilter = sortFilter;
return this;
}
public ListUIHFactory setQuery(String id) throws ParsingException {
setQuery(id, new ArrayList<String>(), "");
return this;
}
public ListUIHFactory setUrl(String url) throws ParsingException {
return (ListUIHFactory) super.setUrl(url);
}
public ListUIHFactory setId(String id) throws ParsingException {
return (ListUIHFactory) super.setId(id);
}
/**
* Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableContentFilter() {
return new String[0];
}
/**
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableSortFilter() {
return new String[0];
}
public List<String> getContentFilter() {
return contentFilter;
}
public String getSortFilter() {
return sortFilter;
}
}

View file

@ -6,7 +6,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.uih.*;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
@ -76,41 +76,41 @@ public abstract class StreamingService {
//////////////////////////////////////////// ////////////////////////////////////////////
// Extractor // Extractor
//////////////////////////////////////////// ////////////////////////////////////////////
public abstract SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry); public abstract SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry);
public abstract SuggestionExtractor getSuggestionExtractor(); public abstract SuggestionExtractor getSuggestionExtractor();
public abstract SubscriptionExtractor getSubscriptionExtractor(); public abstract SubscriptionExtractor getSubscriptionExtractor();
public abstract KioskList getKioskList() throws ExtractionException; public abstract KioskList getKioskList() throws ExtractionException;
public abstract ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) throws ExtractionException; public abstract ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) throws ExtractionException;
public abstract PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) throws ExtractionException; public abstract PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) throws ExtractionException;
public abstract StreamExtractor getStreamExtractor(UIHFactory UIHFactory) throws ExtractionException; public abstract StreamExtractor getStreamExtractor(UIHandler UIHFactory) throws ExtractionException;
public SearchExtractor getSearchExtractor(String query, List<String> contentFilter, String sortFilter, String contentCountry) throws ExtractionException { public SearchExtractor getSearchExtractor(String query, List<String> contentFilter, String sortFilter, String contentCountry) throws ExtractionException {
return getSearchExtractor(getSearchQIHFactory().setQuery(query, contentFilter, sortFilter), contentCountry); return getSearchExtractor(getSearchQIHFactory().fromQuery(query, contentFilter, sortFilter), contentCountry);
} }
public ChannelExtractor getChannelExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException { public ChannelExtractor getChannelExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException {
return getChannelExtractor(getChannelUIHFactory().setQuery(id, contentFilter, sortFilter)); return getChannelExtractor(getChannelUIHFactory().fromQuery(id, contentFilter, sortFilter));
} }
public PlaylistExtractor getPlaylistExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(String id, List<String> contentFilter, String sortFilter) throws ExtractionException {
return getPlaylistExtractor(getPlaylistUIHFactory().setQuery(id, contentFilter, sortFilter)); return getPlaylistExtractor(getPlaylistUIHFactory().fromQuery(id, contentFilter, sortFilter));
} }
public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException { public SearchExtractor getSearchExtractor(String query, String contentCountry) throws ExtractionException {
return getSearchExtractor(getSearchQIHFactory().setQuery(query), contentCountry); return getSearchExtractor(getSearchQIHFactory().fromQuery(query), contentCountry);
} }
public ChannelExtractor getChannelExtractor(String url) throws ExtractionException { public ChannelExtractor getChannelExtractor(String url) throws ExtractionException {
return getChannelExtractor(getChannelUIHFactory().setUrl(url)); return getChannelExtractor(getChannelUIHFactory().fromUrl(url));
} }
public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(String url) throws ExtractionException {
return getPlaylistExtractor(getPlaylistUIHFactory().setUrl(url)); return getPlaylistExtractor(getPlaylistUIHFactory().fromUrl(url));
} }
public StreamExtractor getStreamExtractor(String url) throws ExtractionException { public StreamExtractor getStreamExtractor(String url) throws ExtractionException {
return getStreamExtractor(getStreamUIHFactory().setUrl(url)); return getStreamExtractor(getStreamUIHFactory().fromUrl(url));
} }

View file

@ -1,10 +1,10 @@
package org.schabi.newpipe.extractor.channel; package org.schabi.newpipe.extractor.channel;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListUIHFactory;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
/* /*
* Created by Christian Schabesberger on 25.07.16. * Created by Christian Schabesberger on 25.07.16.
@ -28,7 +28,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
public abstract class ChannelExtractor extends ListExtractor<StreamInfoItem> { public abstract class ChannelExtractor extends ListExtractor<StreamInfoItem> {
public ChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public ChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) {
super(service, urlIdHandler); super(service, urlIdHandler);
} }

View file

@ -2,12 +2,13 @@ package org.schabi.newpipe.extractor.channel;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.utils.ExtractorHelper; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
@ -34,7 +35,7 @@ import java.io.IOException;
public class ChannelInfo extends ListInfo<StreamInfoItem> { public class ChannelInfo extends ListInfo<StreamInfoItem> {
public ChannelInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { public ChannelInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException {
super(serviceId, urlIdHandler, name); super(serviceId, urlIdHandler, name);
} }
@ -55,7 +56,7 @@ public class ChannelInfo extends ListInfo<StreamInfoItem> {
public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException { public static ChannelInfo getInfo(ChannelExtractor extractor) throws IOException, ExtractionException {
ChannelInfo info = new ChannelInfo(extractor.getServiceId(), ChannelInfo info = new ChannelInfo(extractor.getServiceId(),
extractor.getUIHFactory(), extractor.getUIHandler(),
extractor.getName()); extractor.getName());

View file

@ -21,10 +21,11 @@ package org.schabi.newpipe.extractor.kiosk;
*/ */
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -33,7 +34,7 @@ public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
private final String id; private final String id;
public KioskExtractor(StreamingService streamingService, public KioskExtractor(StreamingService streamingService,
ListUIHFactory urlIdHandler, ListUIHandler urlIdHandler,
String kioskId) { String kioskId) {
super(streamingService, urlIdHandler); super(streamingService, urlIdHandler);
this.id = kioskId; this.id = kioskId;

View file

@ -24,13 +24,15 @@ import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.utils.ExtractorHelper; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
public class KioskInfo extends ListInfo<StreamInfoItem> { public class KioskInfo extends ListInfo<StreamInfoItem> {
private KioskInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { private KioskInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException {
super(serviceId, urlIdHandler, name); super(serviceId, urlIdHandler, name);
} }
@ -67,7 +69,7 @@ public class KioskInfo extends ListInfo<StreamInfoItem> {
public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException { public static KioskInfo getInfo(KioskExtractor extractor) throws ExtractionException {
final KioskInfo info = new KioskInfo(extractor.getServiceId(), final KioskInfo info = new KioskInfo(extractor.getServiceId(),
extractor.getUIHFactory(), extractor.getUIHandler(),
extractor.getName()); extractor.getName());
final ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor); final ListExtractor.InfoItemsPage<StreamInfoItem> itemsPage = ExtractorHelper.getItemsPageOrLogError(info, extractor);

View file

@ -2,7 +2,7 @@ package org.schabi.newpipe.extractor.kiosk;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import java.io.IOException; import java.io.IOException;
@ -73,7 +73,7 @@ public class KioskList {
throw new ExtractionException("No kiosk found with the type: " + kioskId); throw new ExtractionException("No kiosk found with the type: " + kioskId);
} else { } else {
return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id), return ke.extractorFactory.createNewKiosk(NewPipe.getService(service_id),
ke.handler.setId(kioskId).getUrl(), kioskId); ke.handler.fromId(kioskId).getUrl(), kioskId);
} }
} }

View file

@ -1,14 +1,15 @@
package org.schabi.newpipe.extractor.playlist; package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.ListExtractor; import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> { public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {
public PlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public PlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) {
super(service, urlIdHandler); super(service, urlIdHandler);
} }

View file

@ -2,19 +2,20 @@ package org.schabi.newpipe.extractor.playlist;
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage; import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.utils.ExtractorHelper; import org.schabi.newpipe.extractor.utils.ExtractorHelper;
import java.io.IOException; import java.io.IOException;
public class PlaylistInfo extends ListInfo<StreamInfoItem> { public class PlaylistInfo extends ListInfo<StreamInfoItem> {
public PlaylistInfo(int serviceId, ListUIHFactory urlIdHandler, String name) throws ParsingException { public PlaylistInfo(int serviceId, ListUIHandler urlIdHandler, String name) throws ParsingException {
super(serviceId, urlIdHandler, name); super(serviceId, urlIdHandler, name);
} }
@ -41,7 +42,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
final PlaylistInfo info = new PlaylistInfo( final PlaylistInfo info = new PlaylistInfo(
extractor.getServiceId(), extractor.getServiceId(),
extractor.getUIHFactory(), extractor.getUIHandler(),
extractor.getName()); extractor.getName());
try { try {

View file

@ -5,6 +5,8 @@ import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.SearchQIHFactory;
import org.schabi.newpipe.extractor.uih.SearchQIHandler;
public abstract class SearchExtractor extends ListExtractor<InfoItem> { public abstract class SearchExtractor extends ListExtractor<InfoItem> {
@ -17,14 +19,14 @@ public abstract class SearchExtractor extends ListExtractor<InfoItem> {
private final InfoItemsSearchCollector collector; private final InfoItemsSearchCollector collector;
private final String contentCountry; private final String contentCountry;
public SearchExtractor(StreamingService service, SearchQIHFactory urlIdHandler, String contentCountry) { public SearchExtractor(StreamingService service, SearchQIHandler urlIdHandler, String contentCountry) {
super(service, urlIdHandler); super(service, urlIdHandler);
collector = new InfoItemsSearchCollector(service.getServiceId()); collector = new InfoItemsSearchCollector(service.getServiceId());
this.contentCountry = contentCountry; this.contentCountry = contentCountry;
} }
public String getSearchString() { public String getSearchString() {
return getUIHFactory().getSearchString(); return getUIHandler().getSearchString();
} }
public abstract String getSearchSuggestion() throws ParsingException; public abstract String getSearchSuggestion() throws ParsingException;
@ -34,13 +36,13 @@ public abstract class SearchExtractor extends ListExtractor<InfoItem> {
} }
@Override @Override
public SearchQIHFactory getUIHFactory() { public SearchQIHandler getUIHandler() {
return (SearchQIHFactory) super.getUIHFactory(); return (SearchQIHandler) super.getUIHandler();
} }
@Override @Override
public String getName() { public String getName() {
return getUIHFactory().getSearchString(); return getUIHandler().getSearchString();
} }
protected String getContentCountry() { protected String getContentCountry() {

View file

@ -2,9 +2,10 @@ package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListInfo; import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
public class SearchInfo extends ListInfo<InfoItem> { public class SearchInfo extends ListInfo<InfoItem> {
@ -13,7 +14,7 @@ public class SearchInfo extends ListInfo<InfoItem> {
public SearchInfo(int serviceId, public SearchInfo(int serviceId,
ListUIHFactory urlIdHandler, ListUIHandler urlIdHandler,
String searchString) throws ParsingException { String searchString) throws ParsingException {
super(serviceId, urlIdHandler, "Search"); super(serviceId, urlIdHandler, "Search");
this.searchString = searchString; this.searchString = searchString;
@ -23,7 +24,7 @@ public class SearchInfo extends ListInfo<InfoItem> {
public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException { public static SearchInfo getInfo(SearchExtractor extractor) throws ExtractionException {
final SearchInfo info = new SearchInfo( final SearchInfo info = new SearchInfo(
extractor.getServiceId(), extractor.getServiceId(),
extractor.getUIHFactory(), extractor.getUIHandler(),
extractor.getSearchString()); extractor.getSearchString());
try { try {

View file

@ -1,44 +0,0 @@
package org.schabi.newpipe.extractor.search;
import org.schabi.newpipe.extractor.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.List;
public abstract class SearchQIHFactory extends ListUIHFactory {
@Override
public String onGetIdFromUrl(String url) {
return "Search";
}
public String getSearchString() {
return getId();
}
@Override
public SearchQIHFactory setQuery(String querry,
List<String> contentFilter,
String sortFilter) throws ParsingException {
return (SearchQIHFactory) super.setQuery(querry, contentFilter, sortFilter);
}
@Override
public SearchQIHFactory setQuery(String querry) throws ParsingException {
return (SearchQIHFactory) super.setQuery(querry);
}
@Override
public boolean onAcceptUrl(String url) {
return false;
}
public SearchQIHFactory setId(String query) throws ParsingException {
if(query == null) throw new IllegalArgumentException("id can not be null");
this.id = query;
return this;
}
}

View file

@ -5,7 +5,7 @@ import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@ -24,14 +24,14 @@ public class SoundcloudChannelExtractor extends ChannelExtractor {
private StreamInfoItemsCollector streamInfoItemsCollector = null; private StreamInfoItemsCollector streamInfoItemsCollector = null;
private String nextPageUrl = null; private String nextPageUrl = null;
public SoundcloudChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public SoundcloudChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) {
super(service, urlIdHandler); super(service, urlIdHandler);
} }
@Override @Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
userId = getUIHFactory().getId(); userId = getUIHandler().getId();
String apiUrl = "https://api-v2.soundcloud.com/users/" + userId + String apiUrl = "https://api-v2.soundcloud.com/users/" + userId +
"?client_id=" + SoundcloudParsingHelper.clientId(); "?client_id=" + SoundcloudParsingHelper.clientId();

View file

@ -1,10 +1,12 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
import java.util.List;
public class SoundcloudChannelUIHFactory extends ListUIHFactory { public class SoundcloudChannelUIHFactory extends ListUIHFactory {
private static final SoundcloudChannelUIHFactory instance = new SoundcloudChannelUIHFactory(); private static final SoundcloudChannelUIHFactory instance = new SoundcloudChannelUIHFactory();
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
@ -16,7 +18,7 @@ public class SoundcloudChannelUIHFactory extends ListUIHFactory {
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException { public String getId(String url) throws ParsingException {
Utils.checkUrl(URL_PATTERN, url); Utils.checkUrl(URL_PATTERN, url);
try { try {
@ -27,7 +29,7 @@ public class SoundcloudChannelUIHFactory extends ListUIHFactory {
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
try { try {
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id); return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
} catch (Exception e) { } catch (Exception e) {

View file

@ -1,7 +1,7 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
@ -17,7 +17,7 @@ public class SoundcloudChartsExtractor extends KioskExtractor {
private StreamInfoItemsCollector collector = null; private StreamInfoItemsCollector collector = null;
private String nextPageUrl = null; private String nextPageUrl = null;
public SoundcloudChartsExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) { public SoundcloudChartsExtractor(StreamingService service, ListUIHandler urlIdHandler, String kioskId) {
super(service, urlIdHandler, kioskId); super(service, urlIdHandler, kioskId);
} }

View file

@ -1,15 +1,17 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import java.util.List;
public class SoundcloudChartsUIHFactory extends ListUIHFactory { public class SoundcloudChartsUIHFactory extends ListUIHFactory {
private final String TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$"; private final String TOP_URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top)?/?([#?].*)?$";
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$"; private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/charts(/top|/new)?/?([#?].*)?$";
@Override @Override
public String onGetIdFromUrl(String url) { public String getId(String url) {
if (Parser.isMatch(TOP_URL_PATTERN, url.toLowerCase())) { if (Parser.isMatch(TOP_URL_PATTERN, url.toLowerCase())) {
return "Top 50"; return "Top 50";
} else { } else {
@ -17,7 +19,8 @@ public class SoundcloudChartsUIHFactory extends ListUIHFactory {
} }
} }
public String getUrl() { @Override
public String getUrl(String id, List<String> contentFilter, String sortFilter) {
if (id.equals("Top 50")) { if (id.equals("Top 50")) {
return "https://soundcloud.com/charts/top"; return "https://soundcloud.com/charts/top";
} else { } else {

View file

@ -4,7 +4,7 @@ import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser; import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException; import com.grack.nanojson.JsonParserException;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -23,14 +23,14 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
private StreamInfoItemsCollector streamInfoItemsCollector = null; private StreamInfoItemsCollector streamInfoItemsCollector = null;
private String nextPageUrl = null; private String nextPageUrl = null;
public SoundcloudPlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public SoundcloudPlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) {
super(service, urlIdHandler); super(service, urlIdHandler);
} }
@Override @Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
playlistId = getUIHFactory().getId(); playlistId = getUIHandler().getId();
String apiUrl = "https://api.soundcloud.com/playlists/" + playlistId + String apiUrl = "https://api.soundcloud.com/playlists/" + playlistId +
"?client_id=" + SoundcloudParsingHelper.clientId() + "?client_id=" + SoundcloudParsingHelper.clientId() +
"&representation=compact"; "&representation=compact";

View file

@ -1,10 +1,12 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
import java.util.List;
public class SoundcloudPlaylistUIHFactory extends ListUIHFactory { public class SoundcloudPlaylistUIHFactory extends ListUIHFactory {
private static final SoundcloudPlaylistUIHFactory instance = new SoundcloudPlaylistUIHFactory(); private static final SoundcloudPlaylistUIHFactory instance = new SoundcloudPlaylistUIHFactory();
private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" + private final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+" +
@ -15,7 +17,7 @@ public class SoundcloudPlaylistUIHFactory extends ListUIHFactory {
} }
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException { public String getId(String url) throws ParsingException {
Utils.checkUrl(URL_PATTERN, url); Utils.checkUrl(URL_PATTERN, url);
try { try {
@ -26,7 +28,7 @@ public class SoundcloudPlaylistUIHFactory extends ListUIHFactory {
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
try { try {
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id); return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id);
} catch (Exception e) { } catch (Exception e) {

View file

@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
import org.schabi.newpipe.extractor.search.SearchEngine; import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.uih.SearchQIHandler;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -26,7 +26,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
private JsonArray searchCollection; private JsonArray searchCollection;
public SoundcloudSearchExtractor(StreamingService service, public SoundcloudSearchExtractor(StreamingService service,
SearchQIHFactory urlIdHandler, SearchQIHandler urlIdHandler,
String contentCountry) { String contentCountry) {
super(service, urlIdHandler, contentCountry); super(service, urlIdHandler, contentCountry);
} }

View file

@ -2,11 +2,12 @@ package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.uih.SearchQIHFactory;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List;
public class SoundcloudSearchQIHFactory extends SearchQIHFactory { public class SoundcloudSearchQIHFactory extends SearchQIHFactory {
public static final String CHARSET_UTF_8 = "UTF-8"; public static final String CHARSET_UTF_8 = "UTF-8";
@ -19,12 +20,12 @@ public class SoundcloudSearchQIHFactory extends SearchQIHFactory {
public static final int ITEMS_PER_PAGE = 10; public static final int ITEMS_PER_PAGE = 10;
@Override @Override
public String getUrl() throws ParsingException { public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
try { try {
String url = "https://api-v2.soundcloud.com/search"; String url = "https://api-v2.soundcloud.com/search";
if(getContentFilter().size() > 0) { if(contentFilter.size() > 0) {
switch (getContentFilter().get(0)) { switch (contentFilter.get(0)) {
case TRACKS: case TRACKS:
url += "/tracks"; url += "/tracks";
break; break;

View file

@ -1,16 +1,13 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.*;
import org.schabi.newpipe.extractor.UIHFactory;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.SearchQIHFactory;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
@ -24,7 +21,7 @@ public class SoundcloudService extends StreamingService {
} }
@Override @Override
public SearchExtractor getSearchExtractor(SearchQIHFactory queryHandler, String contentCountry) { public SearchExtractor getSearchExtractor(SearchQIHandler queryHandler, String contentCountry) {
return new SoundcloudSearchExtractor(this, queryHandler, contentCountry); return new SoundcloudSearchExtractor(this, queryHandler, contentCountry);
} }
@ -50,17 +47,17 @@ public class SoundcloudService extends StreamingService {
@Override @Override
public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) { public StreamExtractor getStreamExtractor(UIHandler UIHandler) {
return new SoundcloudStreamExtractor(this, UIHFactory); return new SoundcloudStreamExtractor(this, UIHandler);
} }
@Override @Override
public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) { public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) {
return new SoundcloudChannelExtractor(this, urlIdHandler); return new SoundcloudChannelExtractor(this, urlIdHandler);
} }
@Override @Override
public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) { public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) {
return new SoundcloudPlaylistExtractor(this, urlIdHandler); return new SoundcloudPlaylistExtractor(this, urlIdHandler);
} }
@ -78,7 +75,7 @@ public class SoundcloudService extends StreamingService {
String id) String id)
throws ExtractionException { throws ExtractionException {
return new SoundcloudChartsExtractor(SoundcloudService.this, return new SoundcloudChartsExtractor(SoundcloudService.this,
new SoundcloudChartsUIHFactory().setUrl(url), id); new SoundcloudChartsUIHFactory().fromUrl(url), id);
} }
}; };

View file

@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.*; import org.schabi.newpipe.extractor.stream.*;
import org.schabi.newpipe.extractor.uih.UIHandler;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
@ -20,8 +21,8 @@ import java.util.List;
public class SoundcloudStreamExtractor extends StreamExtractor { public class SoundcloudStreamExtractor extends StreamExtractor {
private JsonObject track; private JsonObject track;
public SoundcloudStreamExtractor(StreamingService service, UIHFactory UIHFactory) { public SoundcloudStreamExtractor(StreamingService service, UIHandler uIHandler) {
super(service, UIHFactory); super(service, uIHandler);
} }
@Override @Override

View file

@ -1,6 +1,6 @@
package org.schabi.newpipe.extractor.services.soundcloud; package org.schabi.newpipe.extractor.services.soundcloud;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
@ -18,7 +18,7 @@ public class SoundcloudStreamUIHFactory extends UIHFactory {
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl(String id) throws ParsingException {
try { try {
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + id); return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + id);
} catch (Exception e) { } catch (Exception e) {
@ -27,7 +27,7 @@ public class SoundcloudStreamUIHFactory extends UIHFactory {
} }
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException { public String getId(String url) throws ParsingException {
Utils.checkUrl(URL_PATTERN, url); Utils.checkUrl(URL_PATTERN, url);
try { try {

View file

@ -31,7 +31,7 @@ public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor {
String id; String id;
try { try {
id = service.getChannelUIHFactory().setUrl(getUrlFrom(channelUrl)).getId(); id = service.getChannelUIHFactory().fromUrl(getUrlFrom(channelUrl)).getId();
} catch (ExtractionException e) { } catch (ExtractionException e) {
throw new InvalidSourceException(e); throw new InvalidSourceException(e);
} }

View file

@ -1,16 +1,13 @@
package org.schabi.newpipe.extractor.services.youtube; package org.schabi.newpipe.extractor.services.youtube;
import org.schabi.newpipe.extractor.*; import org.schabi.newpipe.extractor.*;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.*;
import org.schabi.newpipe.extractor.UIHFactory;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor; import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList; import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.SearchQIHFactory;
import org.schabi.newpipe.extractor.services.youtube.extractors.*; import org.schabi.newpipe.extractor.services.youtube.extractors.*;
import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.*; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.*;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
@ -23,7 +20,7 @@ import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCap
/* /*
* Created by Christian Schabesberger on 23.08.15. * Created by Christian Schabesberger on 23.08.15.
* *
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeService.java is part of NewPipe. * YoutubeService.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -47,7 +44,7 @@ public class YoutubeService extends StreamingService {
} }
@Override @Override
public SearchExtractor getSearchExtractor(SearchQIHFactory query, String contentCountry) { public SearchExtractor getSearchExtractor(SearchQIHandler query, String contentCountry) {
return new YoutubeSearchExtractor(this, query, contentCountry); return new YoutubeSearchExtractor(this, query, contentCountry);
} }
@ -72,17 +69,17 @@ public class YoutubeService extends StreamingService {
} }
@Override @Override
public StreamExtractor getStreamExtractor(UIHFactory UIHFactory) throws ExtractionException { public StreamExtractor getStreamExtractor(UIHandler uiHandler) throws ExtractionException {
return new YoutubeStreamExtractor(this, UIHFactory); return new YoutubeStreamExtractor(this, uiHandler);
} }
@Override @Override
public ChannelExtractor getChannelExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { public ChannelExtractor getChannelExtractor(ListUIHandler urlIdHandler) throws ExtractionException {
return new YoutubeChannelExtractor(this, urlIdHandler); return new YoutubeChannelExtractor(this, urlIdHandler);
} }
@Override @Override
public PlaylistExtractor getPlaylistExtractor(ListUIHFactory urlIdHandler) throws ExtractionException { public PlaylistExtractor getPlaylistExtractor(ListUIHandler urlIdHandler) throws ExtractionException {
return new YoutubePlaylistExtractor(this, urlIdHandler); return new YoutubePlaylistExtractor(this, urlIdHandler);
} }
@ -102,7 +99,7 @@ public class YoutubeService extends StreamingService {
public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String id) public KioskExtractor createNewKiosk(StreamingService streamingService, String url, String id)
throws ExtractionException { throws ExtractionException {
return new YoutubeTrendingExtractor(YoutubeService.this, return new YoutubeTrendingExtractor(YoutubeService.this,
new YoutubeTrendingUIHFactory().setUrl(url), id); new YoutubeTrendingUIHFactory().fromUrl(url), id);
} }
}, new YoutubeTrendingUIHFactory(), "Trending"); }, new YoutubeTrendingUIHFactory(), "Trending");
list.setDefaultKiosk("Trending"); list.setDefaultKiosk("Trending");

View file

@ -13,6 +13,8 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.DonationLinkHelper;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
@ -24,7 +26,7 @@ import java.util.ArrayList;
/* /*
* Created by Christian Schabesberger on 25.07.16. * Created by Christian Schabesberger on 25.07.16.
* *
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeChannelExtractor.java is part of NewPipe. * YoutubeChannelExtractor.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -48,7 +50,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
private Document doc; private Document doc;
public YoutubeChannelExtractor(StreamingService service, ListUIHFactory urlIdHandler) { public YoutubeChannelExtractor(StreamingService service, ListUIHandler urlIdHandler) {
super(service, urlIdHandler); super(service, urlIdHandler);
} }

View file

@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeParsin
import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.StreamType; import org.schabi.newpipe.extractor.stream.StreamType;
import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -24,7 +25,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
private Document doc; private Document doc;
public YoutubePlaylistExtractor(StreamingService service, ListUIHFactory urlIdHandler) throws ExtractionException { public YoutubePlaylistExtractor(StreamingService service, ListUIHandler urlIdHandler) throws ExtractionException {
super(service, urlIdHandler); super(service, urlIdHandler);
} }
@ -170,10 +171,10 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
} }
} }
private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) throws ParsingException { private void collectStreamsFrom(StreamInfoItemsCollector collector, Element element) {
collector.reset(); collector.reset();
final UIHFactory streamUIHFactory = getService().getStreamUIHFactory(); final org.schabi.newpipe.extractor.uih.UIHFactory streamUIHFactory = getService().getStreamUIHFactory();
for (final Element li : element.children()) { for (final Element li : element.children()) {
if(isDeletedItem(li)) { if(isDeletedItem(li)) {
continue; continue;
@ -183,14 +184,14 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
public Element uploaderLink; public Element uploaderLink;
@Override @Override
public boolean isAd() throws ParsingException { public boolean isAd() {
return false; return false;
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl() throws ParsingException {
try { try {
return streamUIHFactory.setId(li.attr("data-video-id")).getUrl(); return streamUIHFactory.fromId(li.attr("data-video-id")).getUrl();
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("Could not get web page url for the video", e); throw new ParsingException("Could not get web page url for the video", e);
} }
@ -255,7 +256,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
@Override @Override
public String getThumbnailUrl() throws ParsingException { public String getThumbnailUrl() throws ParsingException {
try { try {
return "https://i.ytimg.com/vi/" + streamUIHFactory.setUrl(getUrl()).getId() + "/hqdefault.jpg"; return "https://i.ytimg.com/vi/" + streamUIHFactory.fromUrl(getUrl()).getId() + "/hqdefault.jpg";
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException("Could not get thumbnail url", e); throw new ParsingException("Could not get thumbnail url", e);
} }

View file

@ -10,7 +10,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector; import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
import org.schabi.newpipe.extractor.search.SearchExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.uih.SearchQIHandler;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -19,12 +19,32 @@ import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
/*
* Created by Christian Schabesberger on 22.07.2018
*
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeSearchExtractor.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 YoutubeSearchExtractor extends SearchExtractor { public class YoutubeSearchExtractor extends SearchExtractor {
private Document doc; private Document doc;
public YoutubeSearchExtractor(StreamingService service, public YoutubeSearchExtractor(StreamingService service,
SearchQIHFactory urlIdHandler, SearchQIHandler urlIdHandler,
String contentCountry) { String contentCountry) {
super(service, urlIdHandler, contentCountry); super(service, urlIdHandler, contentCountry);
} }

View file

@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.services.youtube.ItagItem; import org.schabi.newpipe.extractor.services.youtube.ItagItem;
import org.schabi.newpipe.extractor.stream.*; import org.schabi.newpipe.extractor.stream.*;
import org.schabi.newpipe.extractor.uih.UIHandler;
import org.schabi.newpipe.extractor.utils.DonationLinkHelper; import org.schabi.newpipe.extractor.utils.DonationLinkHelper;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
@ -29,7 +30,7 @@ import java.util.*;
/* /*
* Created by Christian Schabesberger on 06.08.15. * Created by Christian Schabesberger on 06.08.15.
* *
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeStreamExtractor.java is part of NewPipe. * YoutubeStreamExtractor.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -84,8 +85,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
private boolean isAgeRestricted; private boolean isAgeRestricted;
public YoutubeStreamExtractor(StreamingService service, UIHFactory UIHFactory) throws ExtractionException { public YoutubeStreamExtractor(StreamingService service, UIHandler uiHandler) throws ExtractionException {
super(service, UIHFactory); super(service, uiHandler);
} }
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////

View file

@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
/* /*
* Created by Christian Schabesberger on 12.08.17. * Created by Christian Schabesberger on 12.08.17.
* *
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeTrendingExtractor.java is part of NewPipe. * YoutubeTrendingExtractor.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -25,7 +25,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHandler;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -40,8 +40,9 @@ public class YoutubeTrendingExtractor extends KioskExtractor {
private Document doc; private Document doc;
public YoutubeTrendingExtractor(StreamingService service, ListUIHFactory urlIdHandler, String kioskId) public YoutubeTrendingExtractor(StreamingService service,
throws ExtractionException { ListUIHandler urlIdHandler,
String kioskId) {
super(service, urlIdHandler, kioskId); super(service, urlIdHandler, kioskId);
} }

View file

@ -1,13 +1,15 @@
package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import java.util.List;
/* /*
* Created by Christian Schabesberger on 25.07.16. * Created by Christian Schabesberger on 25.07.16.
* *
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chrźis.schabesberger@mailbox.org>
* YoutubeChannelUIHFactory.java is part of NewPipe. * YoutubeChannelUIHFactory.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -34,12 +36,12 @@ public class YoutubeChannelUIHFactory extends ListUIHFactory {
} }
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException { public String getId(String url) throws ParsingException {
return Parser.matchGroup1(ID_PATTERN, url); return Parser.matchGroup1(ID_PATTERN, url);
} }
@Override @Override
public String getUrl() { public String getUrl(String id, List<String> contentFilters, String searchFilter) {
return "https://www.youtube.com/" + id; return "https://www.youtube.com/" + id;
} }

View file

@ -1,10 +1,12 @@
package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers;
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import java.util.List;
public class YoutubePlaylistUIHFactory extends ListUIHFactory { public class YoutubePlaylistUIHFactory extends ListUIHFactory {
private static final YoutubePlaylistUIHFactory instance = new YoutubePlaylistUIHFactory(); private static final YoutubePlaylistUIHFactory instance = new YoutubePlaylistUIHFactory();
@ -15,12 +17,12 @@ public class YoutubePlaylistUIHFactory extends ListUIHFactory {
} }
@Override @Override
public String getUrl() { public String getUrl(String id, List<String> contentFilters, String sortFilter) {
return "https://www.youtube.com/playlist?list=" + id; return "https://www.youtube.com/playlist?list=" + id;
} }
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException { public String getId(String url) throws ParsingException {
try { try {
return Parser.matchGroup1("list=" + ID_PATTERN, url); return Parser.matchGroup1("list=" + ID_PATTERN, url);
} catch (final Exception exception) { } catch (final Exception exception) {

View file

@ -1,10 +1,11 @@
package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers; package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.search.SearchQIHFactory; import org.schabi.newpipe.extractor.uih.SearchQIHFactory;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.List;
public class YoutubeSearchQIHFactory extends SearchQIHFactory { public class YoutubeSearchQIHFactory extends SearchQIHFactory {
@ -20,13 +21,13 @@ public class YoutubeSearchQIHFactory extends SearchQIHFactory {
} }
@Override @Override
public String getUrl() throws ParsingException { public String getUrl(String searchString, List<String> contentFilters, String sortFilter) throws ParsingException {
try { try {
final String url = "https://www.youtube.com/results" final String url = "https://www.youtube.com/results"
+ "?q=" + URLEncoder.encode(id, CHARSET_UTF_8); + "?q=" + URLEncoder.encode(searchString, CHARSET_UTF_8);
if(getContentFilter().size() > 0) { if(contentFilters.size() > 0) {
switch (getContentFilter().get(0)) { switch (contentFilters.get(0)) {
case STREAM: return url + "&sp=EgIQAVAU"; case STREAM: return url + "&sp=EgIQAVAU";
case CHANNEL: return url + "&sp=EgIQAlAU"; case CHANNEL: return url + "&sp=EgIQAlAU";
case PLAYLIST: return url + "&sp=EgIQA1AU"; case PLAYLIST: return url + "&sp=EgIQA1AU";

View file

@ -5,7 +5,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.Downloader; import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.exceptions.FoundAdException; import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
@ -20,7 +20,7 @@ import java.net.URLDecoder;
/* /*
* Created by Christian Schabesberger on 02.02.16. * Created by Christian Schabesberger on 02.02.16.
* *
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeStreamUIHFactory.java is part of NewPipe. * YoutubeStreamUIHFactory.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -50,12 +50,12 @@ public class YoutubeStreamUIHFactory extends UIHFactory {
} }
@Override @Override
public String getUrl() { public String getUrl(String id) {
return "https://www.youtube.com/watch?v=" + id; return "https://www.youtube.com/watch?v=" + id;
} }
@Override @Override
public String onGetIdFromUrl(String url) throws ParsingException, IllegalArgumentException { public String getId(String url) throws ParsingException, IllegalArgumentException {
if (url.isEmpty()) { if (url.isEmpty()) {
throw new IllegalArgumentException("The url parameter should not be empty"); throw new IllegalArgumentException("The url parameter should not be empty");
} }
@ -141,16 +141,13 @@ public class YoutubeStreamUIHFactory extends UIHFactory {
} catch (IOException | ReCaptchaException e) { } catch (IOException | ReCaptchaException e) {
throw new ParsingException("Unable to resolve shared link", e); throw new ParsingException("Unable to resolve shared link", e);
} }
Document document = Jsoup.parse(content); final Document document = Jsoup.parse(content);
String urlWithRealId;
Element element = document.select("link[rel=\"canonical\"]").first(); final Element element = document.select("link[rel=\"canonical\"]").first();
if (element != null) { final String urlWithRealId = (element != null)
urlWithRealId = element.attr("abs:href"); ? element.attr("abs:href")
} else { : document.select("meta[property=\"og:url\"]").first()
urlWithRealId = document.select("meta[property=\"og:url\"]").first()
.attr("abs:content"); .attr("abs:content");
}
String realId = Parser.matchGroup1(ID_PATTERN, urlWithRealId); String realId = Parser.matchGroup1(ID_PATTERN, urlWithRealId);
if (sharedId.equals(realId)) { if (sharedId.equals(realId)) {
@ -167,16 +164,18 @@ public class YoutubeStreamUIHFactory extends UIHFactory {
} }
@Override @Override
public boolean onAcceptUrl(final String url) { public boolean onAcceptUrl(final String url) throws FoundAdException {
final String lowercaseUrl = url.toLowerCase(); final String lowercaseUrl = url.toLowerCase();
if (lowercaseUrl.contains("youtube") if (lowercaseUrl.contains("youtube")
|| lowercaseUrl.contains("youtu.be") || lowercaseUrl.contains("youtu.be")
|| lowercaseUrl.contains("hooktube")) { || lowercaseUrl.contains("hooktube")) {
// bad programming I know // bad programming I know
try { try {
onGetIdFromUrl(url); getId(url);
return true; return true;
} catch (Exception e) { } catch (FoundAdException fe) {
throw fe;
} catch (ParsingException e) {
return false; return false;
} }
} else { } else {

View file

@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers;
/* /*
* Created by Christian Schabesberger on 12.08.17. * Created by Christian Schabesberger on 12.08.17.
* *
* Copyright (C) Christian Schabesberger 2017 <chris.schabesberger@mailbox.org> * Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
* YoutubeTrendingUIHFactory.java is part of NewPipe. * YoutubeTrendingUIHFactory.java is part of NewPipe.
* *
* NewPipe is free software: you can redistribute it and/or modify * NewPipe is free software: you can redistribute it and/or modify
@ -20,17 +20,19 @@ package org.schabi.newpipe.extractor.services.youtube.urlIdHandlers;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>. * along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/ */
import org.schabi.newpipe.extractor.ListUIHFactory; import org.schabi.newpipe.extractor.uih.ListUIHFactory;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import java.util.List;
public class YoutubeTrendingUIHFactory extends ListUIHFactory { public class YoutubeTrendingUIHFactory extends ListUIHFactory {
public String getUrl() { public String getUrl(String id, List<String> contentFilters, String sortFilter) {
return "https://www.youtube.com/feed/trending"; return "https://www.youtube.com/feed/trending";
} }
@Override @Override
public String onGetIdFromUrl(String url) { public String getId(String url) {
return "Trending"; return "Trending";
} }

View file

@ -23,9 +23,10 @@ package org.schabi.newpipe.extractor.stream;
import org.schabi.newpipe.extractor.Extractor; import org.schabi.newpipe.extractor.Extractor;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.Subtitles; import org.schabi.newpipe.extractor.Subtitles;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.UIHandler;
import org.schabi.newpipe.extractor.utils.Parser; import org.schabi.newpipe.extractor.utils.Parser;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -39,8 +40,8 @@ public abstract class StreamExtractor extends Extractor {
public static final int NO_AGE_LIMIT = 0; public static final int NO_AGE_LIMIT = 0;
public StreamExtractor(StreamingService service, UIHFactory UIHFactory) { public StreamExtractor(StreamingService service, UIHandler uiHandler) {
super(service, UIHFactory); super(service, uiHandler);
} }
@Nonnull @Nonnull

View file

@ -0,0 +1,71 @@
package org.schabi.newpipe.extractor.uih;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public abstract class ListUIHFactory extends UIHFactory {
///////////////////////////////////
// To Override
///////////////////////////////////
public List<String> getContentFilter(String url) throws ParsingException { return new ArrayList<>(0);}
public String getSortFilter(String url) throws ParsingException {return ""; }
public abstract String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException;
///////////////////////////////////
// Logic
///////////////////////////////////
@Override
public ListUIHandler fromUrl(String url) throws ParsingException {
if(url == null) throw new IllegalArgumentException("url may not be null");
return new ListUIHandler(super.fromUrl(url), getContentFilter(url), getSortFilter(url));
}
@Override
public ListUIHandler fromId(String id) throws ParsingException {
return new ListUIHandler(super.fromId(id), new ArrayList<String>(0), "");
}
public ListUIHandler fromQuery(String id,
List<String> contentFilters,
String sortFilter) throws ParsingException {
final String url = getUrl(id, contentFilters, sortFilter);
return new ListUIHandler(url, url, id, contentFilters, sortFilter);
}
/**
* For makeing ListUIHFactory compatible with UIHFactory we need to override this,
* however it should not be overridden by the actual implementation.
* @param id
* @return the url coresponding to id without any filters applied
*/
public String getUrl(String id) throws ParsingException {
return getUrl(id, new ArrayList<String>(0), "");
}
/**
* Will returns content filter the corresponding extractor can handle like "channels", "videos", "music", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableContentFilter() {
return new String[0];
}
/**
* Will returns sort filter the corresponding extractor can handle like "A-Z", "oldest first", "size", etc.
*
* @return filter that can be applied when building a query for getting a list
*/
public String[] getAvailableSortFilter() {
return new String[0];
}
}

View file

@ -0,0 +1,45 @@
package org.schabi.newpipe.extractor.uih;
import java.util.Collections;
import java.util.List;
public class ListUIHandler extends UIHandler {
protected final List<String> contentFilters;
protected final String sortFilter;
public ListUIHandler(String originalUrl,
String url,
String id,
List<String> contentFilters,
String sortFilter) {
super(originalUrl, url, id);
this.contentFilters = Collections.unmodifiableList(contentFilters);
this.sortFilter = sortFilter;
}
public ListUIHandler(ListUIHandler handler) {
this(handler.originalUrl,
handler.url,
handler.id,
handler.contentFilters,
handler.sortFilter);
}
public ListUIHandler(UIHandler handler,
List<String> contentFilters,
String sortFilter) {
this(handler.originalUrl,
handler.url,
handler.id,
contentFilters,
sortFilter);
}
public List<String> getContentFilters() {
return contentFilters;
}
public String getSortFilter() {
return sortFilter;
}
}

View file

@ -0,0 +1,43 @@
package org.schabi.newpipe.extractor.uih;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import java.util.ArrayList;
import java.util.List;
public abstract class SearchQIHFactory extends ListUIHFactory {
///////////////////////////////////
// To Override
///////////////////////////////////
@Override
public abstract String getUrl(String querry, List<String> contentFilter, String sortFilter) throws ParsingException;
public String getSearchString(String url) { return "";}
///////////////////////////////////
// Logic
///////////////////////////////////
@Override
public String getId(String url) { return getSearchString(url); }
@Override
public SearchQIHandler fromQuery(String querry,
List<String> contentFilter,
String sortFilter) throws ParsingException {
return new SearchQIHandler(super.fromQuery(querry, contentFilter, sortFilter));
}
public SearchQIHandler fromQuery(String querry) throws ParsingException {
return fromQuery(querry, new ArrayList<String>(0), "");
}
/**
* It's not mandatorry for NewPipe to handle the Url
* @param url
* @return
*/
@Override
public boolean onAcceptUrl(String url) { return false; }
}

View file

@ -0,0 +1,32 @@
package org.schabi.newpipe.extractor.uih;
import java.util.List;
public class SearchQIHandler extends ListUIHandler {
public SearchQIHandler(String originalUrl,
String url,
String searchString,
List<String> contentFilters,
String sortFilter) {
super(originalUrl, url, searchString, contentFilters, sortFilter);
}
public SearchQIHandler(ListUIHandler handler) {
this(handler.originalUrl,
handler.url,
handler.id,
handler.contentFilters,
handler.sortFilter);
}
/**
* Returns the search string. Since ListQIHandler is based on ListUIHandler
* getSearchString() is equivalent to calling getId().
* @return the search string
*/
public String getSearchString() {
return getId();
}
}

View file

@ -1,5 +1,6 @@
package org.schabi.newpipe.extractor; package org.schabi.newpipe.extractor.uih;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
/* /*
@ -24,38 +25,32 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
public abstract class UIHFactory { public abstract class UIHFactory {
protected String id = ""; ///////////////////////////////////
protected String originalUrl = ""; // To Override
///////////////////////////////////
public abstract String onGetIdFromUrl(String url) throws ParsingException; public abstract String getId(String url) throws ParsingException;
public abstract String getUrl() throws ParsingException; public abstract String getUrl(String id) throws ParsingException;
public abstract boolean onAcceptUrl(final String url) throws ParsingException; public abstract boolean onAcceptUrl(final String url) throws ParsingException;
///////////////////////////////////
// Logic
///////////////////////////////////
public UIHFactory setUrl(String url) throws ParsingException { public UIHandler fromUrl(String url) throws ParsingException {
if(url == null) throw new IllegalArgumentException("url can not be null"); if(url == null) throw new IllegalArgumentException("url can not be null");
originalUrl = url; if(!acceptUrl(url)) {
id = onGetIdFromUrl(url); throw new ParsingException("Malformed unacceptable url: " + url);
return this;
} }
public UIHFactory setId(String id) throws ParsingException { final String id = getId(url);
return new UIHandler(url, getUrl(id), id);
}
public UIHandler fromId(String id) throws ParsingException {
if(id == null) throw new IllegalArgumentException("id can not be null"); if(id == null) throw new IllegalArgumentException("id can not be null");
this.id = id; final String url = getUrl(id);
if(!acceptUrl(getUrl())) { return new UIHandler(url, url, id);
throw new ParsingException("Malformed unacceptable url: " + getUrl());
}
return this;
}
public String getId() {
return id;
}
public String getOriginalUrl() throws ParsingException {
return (originalUrl == null || originalUrl.isEmpty())
? getUrl()
: originalUrl;
} }
/** /**
@ -63,11 +58,11 @@ public abstract class UIHFactory {
* Intent was meant to be watched with this Service. * Intent was meant to be watched with this Service.
* Return false if this service shall not allow to be called through ACTIONs. * Return false if this service shall not allow to be called through ACTIONs.
*/ */
public boolean acceptUrl(final String url) { public boolean acceptUrl(final String url) throws ParsingException {
try { try {
return onAcceptUrl(url); return onAcceptUrl(url);
} catch (Exception e) { } catch (FoundAdException fe) {
return false; throw fe;
} }
} }
} }

View file

@ -0,0 +1,31 @@
package org.schabi.newpipe.extractor.uih;
import java.io.Serializable;
public class UIHandler implements Serializable {
protected final String originalUrl;
protected final String url;
protected final String id;
public UIHandler(String originalUrl, String url, String id) {
this.originalUrl = originalUrl;
this.url = url;
this.id = id;
}
public UIHandler(UIHandler handler) {
this(handler.originalUrl, handler.url, handler.id);
}
public String getOriginalUrl() {
return originalUrl;
}
public String getUrl() {
return url;
}
public String getId() {
return id;
}
}

View file

@ -24,14 +24,14 @@ public class SoundcloudChartsUIHFactoryTest {
@Test @Test
public void getUrl() throws Exception { public void getUrl() throws Exception {
assertEquals(urlIdHandler.setId("Top 50").getUrl(), "https://soundcloud.com/charts/top"); assertEquals(urlIdHandler.fromId("Top 50").getUrl(), "https://soundcloud.com/charts/top");
assertEquals(urlIdHandler.setId("New & hot").getUrl(), "https://soundcloud.com/charts/new"); assertEquals(urlIdHandler.fromId("New & hot").getUrl(), "https://soundcloud.com/charts/new");
} }
@Test @Test
public void getId() throws ParsingException { public void getId() throws ParsingException {
assertEquals(urlIdHandler.setUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50"); assertEquals(urlIdHandler.fromUrl("http://soundcloud.com/charts/top?genre=all-music").getId(), "Top 50");
assertEquals(urlIdHandler.setUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot"); assertEquals(urlIdHandler.fromUrl("HTTP://www.soundcloud.com/charts/new/?genre=all-music&country=all-countries").getId(), "New & hot");
} }
@Test @Test

View file

@ -25,7 +25,7 @@ public class SoundcloudStreamUIHFactoryTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void getIdWithNullAsUrl() throws ParsingException { public void getIdWithNullAsUrl() throws ParsingException {
urlIdHandler.setUrl(null).getId(); urlIdHandler.fromUrl(null).getId();
} }
@Test @Test
@ -37,7 +37,7 @@ public class SoundcloudStreamUIHFactoryTest {
for (String invalidUrl : invalidUrls) { for (String invalidUrl : invalidUrls) {
Throwable exception = null; Throwable exception = null;
try { try {
urlIdHandler.setUrl(invalidUrl).getId(); urlIdHandler.fromUrl(invalidUrl).getId();
} catch (ParsingException e) { } catch (ParsingException e) {
exception = e; exception = e;
} }
@ -49,16 +49,16 @@ public class SoundcloudStreamUIHFactoryTest {
@Test @Test
public void getId() throws Exception { public void getId() throws Exception {
assertEquals("309689103", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/15-ysl").getId()); assertEquals("309689103", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/15-ysl").getId());
assertEquals("309689082", urlIdHandler.setUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId()); assertEquals("309689082", urlIdHandler.fromUrl("https://www.soundcloud.com/liluzivert/15-luv-scars-ko").getId());
assertEquals("309689035", urlIdHandler.setUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId()); assertEquals("309689035", urlIdHandler.fromUrl("http://soundcloud.com/liluzivert/15-boring-shit").getId());
assertEquals("294488599", urlIdHandler.setUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId()); assertEquals("294488599", urlIdHandler.fromUrl("http://www.soundcloud.com/liluzivert/secure-the-bag-produced-by-glohan-beats").getId());
assertEquals("294488438", urlIdHandler.setUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId()); assertEquals("294488438", urlIdHandler.fromUrl("HtTpS://sOuNdClOuD.cOm/LiLuZiVeRt/In-O4-pRoDuCeD-bY-dP-bEaTz").getId());
assertEquals("294488147", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId()); assertEquals("294488147", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/fresh-produced-by-zaytoven#t=69").getId());
assertEquals("294487876", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId()); assertEquals("294487876", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/threesome-produced-by-zaytoven#t=1:09").getId());
assertEquals("294487684", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId()); assertEquals("294487684", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/blonde-brigitte-produced-manny-fresh#t=1:9").getId());
assertEquals("294487428", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId()); assertEquals("294487428", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/today-produced-by-c-note#t=1m9s").getId());
assertEquals("294487157", urlIdHandler.setUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId()); assertEquals("294487157", urlIdHandler.fromUrl("https://soundcloud.com/liluzivert/changed-my-phone-produced-by-c-note#t=1m09s").getId());
} }

View file

@ -5,7 +5,7 @@ import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionItem; import org.schabi.newpipe.extractor.subscription.SubscriptionItem;

View file

@ -37,10 +37,15 @@ public abstract class SoundcloudSearchExtractorBaseTest {
protected static ListExtractor.InfoItemsPage<InfoItem> itemsPage; protected static ListExtractor.InfoItemsPage<InfoItem> itemsPage;
protected static String removeClientId(String url) {
String[] splitUrl = url.split("client_id=[a-zA-Z0-9]*&");
return splitUrl[0] + splitUrl[1];
}
@Test @Test
public void testResultListElementsLength() { public void testResultListElementsLength() {
assertTrue(Integer.toString(itemsPage.getItems().size()), assertTrue(Integer.toString(itemsPage.getItems().size()),
itemsPage.getItems().size() >= 10); itemsPage.getItems().size() >= 3);
} }
@Test @Test

View file

@ -30,7 +30,7 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx
asList(new String[]{"users"}), null, "de"); asList(new String[]{"users"}), null, "de");
ListExtractor.InfoItemsPage<InfoItem> secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl()); ListExtractor.InfoItemsPage<InfoItem> secondPage = secondExtractor.getPage(itemsPage.getNextPageUrl());
assertTrue(Integer.toString(secondPage.getItems().size()), assertTrue(Integer.toString(secondPage.getItems().size()),
secondPage.getItems().size() >= 7); secondPage.getItems().size() >= 3);
// check if its the same result // check if its the same result
boolean equals = true; boolean equals = true;
@ -43,14 +43,14 @@ public class SoundcloudSearchExtractorChannelOnlyTest extends SoundcloudSearchEx
} }
assertFalse("First and second page are equal", equals); assertFalse("First and second page are equal", equals);
assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20", assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&limit=10&offset=20",
secondPage.getNextPageUrl()); removeClientId(secondPage.getNextPageUrl()));
} }
@Test @Test
public void testGetSecondPageUrl() throws Exception { public void testGetSecondPageUrl() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10", assertEquals("https://api-v2.soundcloud.com/search/users?q=lill+uzi+vert&limit=10&offset=10",
extractor.getNextPageUrl()); removeClientId(extractor.getNextPageUrl()));
} }
@Test @Test

View file

@ -50,8 +50,8 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac
@Test @Test
public void testGetSecondPageUrl() throws Exception { public void testGetSecondPageUrl() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=10", assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=10",
extractor.getNextPageUrl()); removeClientId(extractor.getNextPageUrl()));
} }
@Test @Test
@ -92,8 +92,8 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac
} }
assertFalse("First and second page are equal", equals); assertFalse("First and second page are equal", equals);
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=20", assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=20",
secondPage.getNextPageUrl()); removeClientId(secondPage.getNextPageUrl()));
} }

View file

@ -16,33 +16,43 @@ public class SoundcloudSearchQUHTest {
NewPipe.init(Downloader.getInstance()); NewPipe.init(Downloader.getInstance());
} }
private static String removeClientId(String url) {
String[] splitUrl = url.split("client_id=[a-zA-Z0-9]*&");
return splitUrl[0] + splitUrl[1];
}
@Test @Test
public void testRegularValues() throws Exception { public void testRegularValues() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("asdf").getUrl()); assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0",
assertEquals("https://api-v2.soundcloud.com/search?q=hans&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0",SoundCloud.getSearchQIHFactory().setQuery("hans").getUrl()); removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("asdf").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("Poifj&jaijf").getUrl()); assertEquals("https://api-v2.soundcloud.com/search?q=hans&limit=10&offset=0",
assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("Gülüm").getUrl()); removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("hans").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory().setQuery("?j$)H§B").getUrl()); assertEquals("https://api-v2.soundcloud.com/search?q=Poifj%26jaijf&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=G%C3%BCl%C3%BCm&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("Gülüm").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=%3Fj%24%29H%C2%A7B&limit=10&offset=0",
removeClientId(SoundCloud.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl()));
} }
@Test @Test
public void testGetContentFilter() throws Exception { public void testGetContentFilter() throws Exception {
assertEquals("tracks", SoundCloud.getSearchQIHFactory() assertEquals("tracks", SoundCloud.getSearchQIHFactory()
.setQuery("", asList(new String[]{"tracks"}), "").getContentFilter().get(0)); .fromQuery("", asList(new String[]{"tracks"}), "").getContentFilters().get(0));
assertEquals("users", SoundCloud.getSearchQIHFactory() assertEquals("users", SoundCloud.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"users"}), "").getContentFilter().get(0)); .fromQuery("asdf", asList(new String[]{"users"}), "").getContentFilters().get(0));
} }
@Test @Test
public void testWithContentfilter() throws Exception { public void testWithContentfilter() throws Exception {
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"tracks"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"tracks"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"users"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"users"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&client_id=rc0HfXXgVnLSGEuQMs1F8xxuAR2AL431&limit=10&offset=0", SoundCloud.getSearchQIHFactory() assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()));
} }
@Test @Test

View file

@ -4,6 +4,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUIHFactory; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeChannelUIHFactory;
@ -24,7 +25,7 @@ public class YoutubeChannelUIHFactoryTest {
} }
@Test @Test
public void acceptrUrlTest() { public void acceptrUrlTest() throws ParsingException {
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Gronkh")); assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Gronkh"));
assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Netzkino/videos")); assertTrue(urlIdHandler.acceptUrl("https://www.youtube.com/user/Netzkino/videos"));
@ -40,17 +41,17 @@ public class YoutubeChannelUIHFactoryTest {
@Test @Test
public void getIdFromUrl() throws ParsingException { public void getIdFromUrl() throws ParsingException {
assertEquals("user/Gronkh", urlIdHandler.setUrl("https://www.youtube.com/user/Gronkh").getId()); assertEquals("user/Gronkh", urlIdHandler.fromUrl("https://www.youtube.com/user/Gronkh").getId());
assertEquals("user/Netzkino", urlIdHandler.setUrl("https://www.youtube.com/user/Netzkino/videos").getId()); assertEquals("user/Netzkino", urlIdHandler.fromUrl("https://www.youtube.com/user/Netzkino/videos").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://www.youtube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId());
assertEquals("user/Gronkh", urlIdHandler.setUrl("https://hooktube.com/user/Gronkh").getId()); assertEquals("user/Gronkh", urlIdHandler.fromUrl("https://hooktube.com/user/Gronkh").getId());
assertEquals("user/Netzkino", urlIdHandler.setUrl("https://hooktube.com/user/Netzkino/videos").getId()); assertEquals("user/Netzkino", urlIdHandler.fromUrl("https://hooktube.com/user/Netzkino/videos").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA").getId()); assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA").getId());
assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.setUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId()); assertEquals("channel/UClq42foiSgl7sSpLupnugGA", urlIdHandler.fromUrl("https://hooktube.com/channel/UClq42foiSgl7sSpLupnugGA/videos?disable_polymer=1").getId());
} }
} }

View file

@ -28,12 +28,12 @@ public class YoutubeStreamUIHFactoryTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void getIdWithNullAsUrl() throws ParsingException { public void getIdWithNullAsUrl() throws ParsingException {
urlIdHandler.setId(null); urlIdHandler.fromId(null);
} }
@Test(expected = FoundAdException.class) @Test(expected = FoundAdException.class)
public void getIdForAd() throws ParsingException { public void getIdForAd() throws ParsingException {
urlIdHandler.setUrl(AD_URL).getId(); urlIdHandler.fromUrl(AD_URL).getId();
} }
@Test @Test
@ -45,7 +45,7 @@ public class YoutubeStreamUIHFactoryTest {
for (String invalidUrl : invalidUrls) { for (String invalidUrl : invalidUrls) {
Throwable exception = null; Throwable exception = null;
try { try {
urlIdHandler.setUrl(invalidUrl).getId(); urlIdHandler.fromUrl(invalidUrl).getId();
} catch (ParsingException e) { } catch (ParsingException e) {
exception = e; exception = e;
} }
@ -57,37 +57,37 @@ public class YoutubeStreamUIHFactoryTest {
@Test @Test
public void getIdfromYt() throws Exception { public void getIdfromYt() throws Exception {
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/watch?v=jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI").getId());
assertEquals("W-fFHeTX70Q", urlIdHandler.setUrl("https://www.youtube.com/watch?v=W-fFHeTX70Q").getId()); assertEquals("W-fFHeTX70Q", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=W-fFHeTX70Q").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://WWW.YouTube.com/watch?v=jZViOEv90dI?t=100").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("HTTPS://www.youtube.com/watch?v=jZViOEv90dI?t=100").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://youtu.be/jZViOEv90dI?t=9s").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://youtu.be/jZViOEv90dI?t=9s").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("HTTPS://Youtu.be/jZViOEv90dI?t=9s").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("HTTPS://Youtu.be/jZViOEv90dI?t=9s").getId());
assertEquals("uEJuoEs1UxY", urlIdHandler.setUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); assertEquals("uEJuoEs1UxY", urlIdHandler.fromUrl("http://www.youtube.com/watch_popup?v=uEJuoEs1UxY").getId());
assertEquals("uEJuoEs1UxY", urlIdHandler.setUrl("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY").getId()); assertEquals("uEJuoEs1UxY", urlIdHandler.fromUrl("http://www.Youtube.com/watch_popup?v=uEJuoEs1UxY").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube.com/embed/jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube.com/embed/jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("https://www.youtube-nocookie.com/embed/jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube.com/watch?v=jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube.com/watch?v=jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://youtube.com/watch?v=jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://youtube.com/watch?v=jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://youtu.be/jZViOEv90dI?t=9s").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://youtu.be/jZViOEv90dI?t=9s").getId());
assertEquals("7_WWz2DSnT8", urlIdHandler.setUrl("https://youtu.be/7_WWz2DSnT8").getId()); assertEquals("7_WWz2DSnT8", urlIdHandler.fromUrl("https://youtu.be/7_WWz2DSnT8").getId());
assertEquals("oy6NvWeVruY", urlIdHandler.setUrl("https://m.youtube.com/watch?v=oy6NvWeVruY").getId()); assertEquals("oy6NvWeVruY", urlIdHandler.fromUrl("https://m.youtube.com/watch?v=oy6NvWeVruY").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube.com/embed/jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube.com/embed/jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId());
assertEquals("EhxJLojIE_o", urlIdHandler.setUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId()); assertEquals("EhxJLojIE_o", urlIdHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId());
assertEquals("jZViOEv90dI", urlIdHandler.setUrl("vnd.youtube:jZViOEv90dI").getId()); assertEquals("jZViOEv90dI", urlIdHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId());
} }
@Test @Test
public void getIdfromSharedLinksYt() throws Exception { public void getIdfromSharedLinksYt() throws Exception {
String sharedId = "7JIArTByb3E"; String sharedId = "7JIArTByb3E";
String realId = "Q7JsK50NGaA"; String realId = "Q7JsK50NGaA";
assertEquals(realId, urlIdHandler.setUrl("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link").getId()); assertEquals(realId, urlIdHandler.fromUrl("vnd.youtube://www.YouTube.com/shared?ci=" + sharedId + "&feature=twitter-deep-link").getId());
assertEquals(realId, urlIdHandler.setUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId).getId()); assertEquals(realId, urlIdHandler.fromUrl("vnd.youtube://www.youtube.com/shared?ci=" + sharedId).getId());
assertEquals(realId, urlIdHandler.setUrl("https://www.youtube.com/shared?ci=" + sharedId).getId()); assertEquals(realId, urlIdHandler.fromUrl("https://www.youtube.com/shared?ci=" + sharedId).getId());
} }
@ -131,11 +131,11 @@ public class YoutubeStreamUIHFactoryTest {
@Test @Test
public void testGetHookIdfromUrl() throws ParsingException { public void testGetHookIdfromUrl() throws ParsingException {
assertEquals("TglNG-yjabU", urlIdHandler.setUrl("https://hooktube.com/watch?v=TglNG-yjabU").getId()); assertEquals("TglNG-yjabU", urlIdHandler.fromUrl("https://hooktube.com/watch?v=TglNG-yjabU").getId());
assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/watch?v=3msbfr6pBNE").getId()); assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/watch?v=3msbfr6pBNE").getId());
assertEquals("ocH3oSnZG3c", urlIdHandler.setUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId()); assertEquals("ocH3oSnZG3c", urlIdHandler.fromUrl("https://hooktube.com/watch?v=ocH3oSnZG3c&list=PLS2VU1j4vzuZwooPjV26XM9UEBY2CPNn2").getId());
assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/watch/3msbfr6pBNE").getId()); assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/watch/3msbfr6pBNE").getId());
assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/v/3msbfr6pBNE").getId()); assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/v/3msbfr6pBNE").getId());
assertEquals("3msbfr6pBNE", urlIdHandler.setUrl("hooktube.com/embed/3msbfr6pBNE").getId()); assertEquals("3msbfr6pBNE", urlIdHandler.fromUrl("hooktube.com/embed/3msbfr6pBNE").getId());
} }
} }

View file

@ -5,7 +5,7 @@ import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList; import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor; import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor; import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionItem; import org.schabi.newpipe.extractor.subscription.SubscriptionItem;

View file

@ -25,7 +25,7 @@ import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.kiosk.KioskInfo; import org.schabi.newpipe.extractor.kiosk.KioskInfo;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -45,7 +45,7 @@ public class YoutubeTrendingKioskInfoTest {
StreamingService service = YouTube; StreamingService service = YouTube;
UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending"); UIHFactory UIHFactory = service.getKioskList().getUrlIdHandlerByType("Trending");
kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.setId("Trending").getUrl(), null); kioskInfo = KioskInfo.getInfo(YouTube, UIHFactory.fromId("Trending").getUrl(), null);
} }
@Test @Test

View file

@ -24,9 +24,13 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.schabi.newpipe.Downloader; import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.UIHFactory; import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.uih.UIHFactory;
import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory; import org.schabi.newpipe.extractor.services.youtube.urlIdHandlers.YoutubeTrendingUIHFactory;
import java.text.ParseException;
import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -47,17 +51,17 @@ public class YoutubeTrendingUIHFactoryTest {
@Test @Test
public void getUrl() public void getUrl()
throws Exception { throws Exception {
assertEquals(UIHFactory.setId("").getUrl(), "https://www.youtube.com/feed/trending"); assertEquals(UIHFactory.fromId("").getUrl(), "https://www.youtube.com/feed/trending");
} }
@Test @Test
public void getId() public void getId()
throws Exception { throws Exception {
assertEquals(UIHFactory.setUrl("").getId(), "Trending"); assertEquals(UIHFactory.fromUrl("https://www.youtube.com/feed/trending").getId(), "Trending");
} }
@Test @Test
public void acceptUrl() { public void acceptUrl() throws ParsingException {
assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending")); assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending"));
assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe")); assertTrue(UIHFactory.acceptUrl("https://www.youtube.com/feed/trending?adsf=fjaj#fhe"));
assertTrue(UIHFactory.acceptUrl("http://www.youtube.com/feed/trending")); assertTrue(UIHFactory.acceptUrl("http://www.youtube.com/feed/trending"));

View file

@ -10,31 +10,31 @@ public class YoutubeSearchQUHTest {
@Test @Test
public void testRegularValues() throws Exception { public void testRegularValues() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory().setQuery("asdf").getUrl()); assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory().fromQuery("asdf").getUrl());
assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQIHFactory().setQuery("hans").getUrl()); assertEquals("https://www.youtube.com/results?q=hans",YouTube.getSearchQIHFactory().fromQuery("hans").getUrl());
assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQIHFactory().setQuery("Poifj&jaijf").getUrl()); assertEquals("https://www.youtube.com/results?q=Poifj%26jaijf", YouTube.getSearchQIHFactory().fromQuery("Poifj&jaijf").getUrl());
assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQIHFactory().setQuery("Gülüm").getUrl()); assertEquals("https://www.youtube.com/results?q=G%C3%BCl%C3%BCm", YouTube.getSearchQIHFactory().fromQuery("Gülüm").getUrl());
assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQIHFactory().setQuery("?j$)H§B").getUrl()); assertEquals("https://www.youtube.com/results?q=%3Fj%24%29H%C2%A7B", YouTube.getSearchQIHFactory().fromQuery("?j$)H§B").getUrl());
} }
@Test @Test
public void testGetContentFilter() throws Exception { public void testGetContentFilter() throws Exception {
assertEquals("stream", YouTube.getSearchQIHFactory() assertEquals("stream", YouTube.getSearchQIHFactory()
.setQuery("", asList(new String[]{"stream"}), "").getContentFilter().get(0)); .fromQuery("", asList(new String[]{"stream"}), "").getContentFilters().get(0));
assertEquals("channel", YouTube.getSearchQIHFactory() assertEquals("channel", YouTube.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"channel"}), "").getContentFilter().get(0)); .fromQuery("asdf", asList(new String[]{"channel"}), "").getContentFilters().get(0));
} }
@Test @Test
public void testWithContentfilter() throws Exception { public void testWithContentfilter() throws Exception {
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQIHFactory() assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAVAU", YouTube.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"stream"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"stream"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQIHFactory() assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQAlAU", YouTube.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"channel"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"channel"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQIHFactory() assertEquals("https://www.youtube.com/results?q=asdf&sp=EgIQA1AU", YouTube.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"playlist"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"playlist"}), "").getUrl());
assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory() assertEquals("https://www.youtube.com/results?q=asdf", YouTube.getSearchQIHFactory()
.setQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()); .fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl());
} }
@Test @Test