Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename some stuff #20

Merged
merged 1 commit into from Aug 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/schabi/newpipe/extractor/Extractor.java
Expand Up @@ -37,7 +37,7 @@ public Extractor(StreamingService service, String url) throws ExtractionExceptio
}

/**
* @return a {@link UrlIdHandler} of the current extractor type (e.g. a ChannelExtractor should return a channel url handler).
* @return a {@link UrlIdHandler} of the current extractor type (e.g. a UserExtractor should return a user url handler).
*/
protected abstract UrlIdHandler getUrlIdHandler() throws ParsingException;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/schabi/newpipe/extractor/InfoItem.java
Expand Up @@ -26,7 +26,7 @@ public abstract class InfoItem implements Serializable {
public enum InfoType {
STREAM,
PLAYLIST,
CHANNEL
USER
}

public InfoItem(InfoType infoType) {
Expand Down
Expand Up @@ -7,7 +7,7 @@
import java.util.List;

/**
* Base class to extractors that have a list (e.g. playlists, channels).
* Base class to extractors that have a list (e.g. playlists, users).
*/
public abstract class ListExtractor extends Extractor {
protected String nextStreamsUrl;
Expand Down
Expand Up @@ -7,7 +7,7 @@
* A list of supported services.
*/
public enum ServiceList {
Youtube(new YoutubeService(0, "Youtube")),
YouTube(new YoutubeService(0, "YouTube")),
SoundCloud(new SoundcloudService(1, "SoundCloud"));
// DailyMotion(new DailyMotionService(2, "DailyMotion"));

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/schabi/newpipe/extractor/StreamingService.java
@@ -1,10 +1,10 @@
package org.schabi.newpipe.extractor;

import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.user.UserExtractor;

import java.io.IOException;

Expand All @@ -20,7 +20,7 @@ public ServiceInfo(String name) {
public enum LinkType {
NONE,
STREAM,
CHANNEL,
USER,
PLAYLIST
}

Expand All @@ -41,34 +41,34 @@ public ServiceInfo getServiceInfo() {
}

public abstract UrlIdHandler getStreamUrlIdHandler();
public abstract UrlIdHandler getChannelUrlIdHandler();
public abstract UrlIdHandler getUserUrlIdHandler();
public abstract UrlIdHandler getPlaylistUrlIdHandler();
public abstract SearchEngine getSearchEngine();
public abstract SuggestionExtractor getSuggestionExtractor();
public abstract StreamExtractor getStreamExtractor(String url) throws IOException, ExtractionException;
public abstract ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
public abstract UserExtractor getUserExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;
public abstract PlaylistExtractor getPlaylistExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException;

public ChannelExtractor getChannelExtractor(String url) throws IOException, ExtractionException {
return getChannelExtractor(url, null);
public UserExtractor getUserExtractor(String url) throws IOException, ExtractionException {
return getUserExtractor(url, null);
}

public PlaylistExtractor getPlaylistExtractor(String url) throws IOException, ExtractionException {
return getPlaylistExtractor(url, null);
}

/**
* figure out where the link is pointing to (a channel, video, playlist, etc.)
* figure out where the link is pointing to (a user, video, playlist, etc.)
*/
public final LinkType getLinkTypeByUrl(String url) {
UrlIdHandler sH = getStreamUrlIdHandler();
UrlIdHandler cH = getChannelUrlIdHandler();
UrlIdHandler cH = getUserUrlIdHandler();
UrlIdHandler pH = getPlaylistUrlIdHandler();

if (sH.acceptUrl(url)) {
return LinkType.STREAM;
} else if (cH.acceptUrl(url)) {
return LinkType.CHANNEL;
return LinkType.USER;
} else if (pH.acceptUrl(url)) {
return LinkType.PLAYLIST;
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/schabi/newpipe/extractor/UrlIdHandler.java
Expand Up @@ -24,14 +24,14 @@

public interface UrlIdHandler {

String getUrl(String videoId) throws ParsingException;
String getId(String siteUrl) throws ParsingException;
String cleanUrl(String siteUrl) throws ParsingException;
String getUrl(String id) throws ParsingException;
String getId(String url) throws ParsingException;
String cleanUrl(String complexUrl) throws ParsingException;

/**
* When a VIEW_ACTION is caught this function will test if the url delivered within the calling
* Intent was meant to be watched with this Service.
* Return false if this service shall not allow to be called through ACTIONs.
*/
boolean acceptUrl(String videoUrl);
boolean acceptUrl(String url);
}
@@ -1,12 +1,12 @@
package org.schabi.newpipe.extractor.search;

import org.schabi.newpipe.extractor.InfoItemCollector;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemCollector;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
import org.schabi.newpipe.extractor.user.UserInfoItemCollector;
import org.schabi.newpipe.extractor.user.UserInfoItemExtractor;

/*
* Created by Christian Schabesberger on 12.02.17.
Expand All @@ -31,14 +31,14 @@
public class InfoItemSearchCollector extends InfoItemCollector {
private String suggestion;
private StreamInfoItemCollector streamCollector;
private ChannelInfoItemCollector channelCollector;
private UserInfoItemCollector userCollector;

private SearchResult result = new SearchResult();

InfoItemSearchCollector(int serviceId) {
super(serviceId);
streamCollector = new StreamInfoItemCollector(serviceId);
channelCollector = new ChannelInfoItemCollector(serviceId);
userCollector = new UserInfoItemCollector(serviceId);
}

public void setSuggestion(String suggestion) {
Expand All @@ -47,7 +47,7 @@ public void setSuggestion(String suggestion) {

public SearchResult getSearchResult() throws ExtractionException {

addFromCollector(channelCollector);
addFromCollector(userCollector);
addFromCollector(streamCollector);

result.suggestion = suggestion;
Expand All @@ -65,9 +65,9 @@ public void commit(StreamInfoItemExtractor extractor) {
}
}

public void commit(ChannelInfoItemExtractor extractor) {
public void commit(UserInfoItemExtractor extractor) {
try {
result.resultList.add(channelCollector.extract(extractor));
result.resultList.add(userCollector.extract(extractor));
} catch (FoundAdException ae) {
System.err.println("Found ad");
} catch (Exception e) {
Expand Down
Expand Up @@ -27,7 +27,7 @@

public abstract class SearchEngine {
public enum Filter {
STREAM, CHANNEL, PLAYLIST
STREAM, USER, PLAYLIST
}

public static class NothingFoundException extends ExtractionException {
Expand Down
Expand Up @@ -16,9 +16,9 @@ public static SoundcloudPlaylistUrlIdHandler getInstance() {
}

@Override
public String getUrl(String listId) throws ParsingException {
public String getUrl(String id) throws ParsingException {
try {
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + listId);
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/playlists/" + id);
} catch (Exception e) {
throw new ParsingException(e.getMessage(), e);
}
Expand Down Expand Up @@ -46,8 +46,8 @@ public String cleanUrl(String complexUrl) throws ParsingException {
}

@Override
public boolean acceptUrl(String videoUrl) {
public boolean acceptUrl(String url) {
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+/sets/[0-9a-z_-]+/?([#?].*)?$";
return Parser.isMatch(regex, videoUrl.toLowerCase());
return Parser.isMatch(regex, url.toLowerCase());
}
}
Expand Up @@ -27,9 +27,9 @@ public InfoItemSearchCollector search(String query, int page, String languageCod

String url = "https://api-v2.soundcloud.com/search";

if (filter.contains(Filter.STREAM) && !filter.contains(Filter.CHANNEL)) {
if (filter.contains(Filter.STREAM) && !filter.contains(Filter.USER)) {
url += "/tracks";
} else if (!filter.contains(Filter.STREAM) && filter.contains(Filter.CHANNEL)) {
} else if (!filter.contains(Filter.STREAM) && filter.contains(Filter.USER)) {
url += "/users";
}

Expand All @@ -50,7 +50,7 @@ public InfoItemSearchCollector search(String query, int page, String languageCod
JSONObject searchResult = searchCollection.getJSONObject(i);
String kind = searchResult.getString("kind");
if (kind.equals("user")) {
collector.commit(new SoundcloudChannelInfoItemExtractor(searchResult));
collector.commit(new SoundcloudUserInfoItemExtractor(searchResult));
} else if (kind.equals("track")) {
collector.commit(new SoundcloudStreamInfoItemExtractor(searchResult));
}
Expand Down
Expand Up @@ -3,11 +3,11 @@
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.SuggestionExtractor;
import org.schabi.newpipe.extractor.UrlIdHandler;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchEngine;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.user.UserExtractor;

import java.io.IOException;

Expand All @@ -28,8 +28,8 @@ public UrlIdHandler getStreamUrlIdHandler() {
}

@Override
public UrlIdHandler getChannelUrlIdHandler() {
return SoundcloudChannelUrlIdHandler.getInstance();
public UrlIdHandler getUserUrlIdHandler() {
return SoundcloudUserUrlIdHandler.getInstance();
}

@Override
Expand All @@ -44,8 +44,8 @@ public StreamExtractor getStreamExtractor(String url) throws IOException, Extrac
}

@Override
public ChannelExtractor getChannelExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
return new SoundcloudChannelExtractor(this, url, nextStreamsUrl);
public UserExtractor getUserExtractor(String url, String nextStreamsUrl) throws IOException, ExtractionException {
return new SoundcloudUserExtractor(this, url, nextStreamsUrl);
}

@Override
Expand Down
Expand Up @@ -215,7 +215,7 @@ public StreamInfoItemCollector getRelatedVideos() throws IOException, Extraction
}

@Override
public String getChannelUrl() {
public String getUserUrl() {
return track.getJSONObject("user").getString("permalink_url");
}

Expand Down
Expand Up @@ -19,9 +19,9 @@ public static SoundcloudStreamUrlIdHandler getInstance() {
}

@Override
public String getUrl(String videoId) throws ParsingException {
public String getUrl(String id) throws ParsingException {
try {
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + videoId);
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/tracks/" + id);
} catch (Exception e) {
throw new ParsingException(e.getMessage(), e);
}
Expand Down Expand Up @@ -49,8 +49,8 @@ public String cleanUrl(String complexUrl) throws ParsingException {
}

@Override
public boolean acceptUrl(String videoUrl) {
public boolean acceptUrl(String url) {
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+/(?!(tracks|albums|sets|reposts|followers|following)/?$)[0-9a-z_-]+/?([#?].*)?$";
return Parser.isMatch(regex, videoUrl.toLowerCase());
return Parser.isMatch(regex, url.toLowerCase());
}
}
Expand Up @@ -4,70 +4,70 @@
import org.schabi.newpipe.extractor.Downloader;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
import org.schabi.newpipe.extractor.user.UserExtractor;

import java.io.IOException;

@SuppressWarnings("WeakerAccess")
public class SoundcloudChannelExtractor extends ChannelExtractor {
private String channelId;
private JSONObject channel;
public class SoundcloudUserExtractor extends UserExtractor {
private String userId;
private JSONObject user;

public SoundcloudChannelExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
public SoundcloudUserExtractor(StreamingService service, String url, String nextStreamsUrl) throws IOException, ExtractionException {
super(service, url, nextStreamsUrl);
}

@Override
public void fetchPage() throws IOException, ExtractionException {
Downloader dl = NewPipe.getDownloader();

channelId = getUrlIdHandler().getId(getOriginalUrl());
String apiUrl = "https://api.soundcloud.com/users/" + channelId +
userId = getUrlIdHandler().getId(getOriginalUrl());
String apiUrl = "https://api.soundcloud.com/users/" + userId +
"?client_id=" + SoundcloudParsingHelper.clientId();

String response = dl.download(apiUrl);
channel = new JSONObject(response);
user = new JSONObject(response);
}

@Override
public String getCleanUrl() {
try {
return channel.getString("permalink_url");
return user.getString("permalink_url");
} catch (Exception e) {
return getOriginalUrl();
}
}

@Override
public String getChannelId() {
return channelId;
public String getUserId() {
return userId;
}

@Override
public String getChannelName() {
return channel.getString("username");
public String getUserName() {
return user.getString("username");
}

@Override
public String getAvatarUrl() {
return channel.getString("avatar_url");
return user.getString("avatar_url");
}

@Override
public String getBannerUrl() throws ParsingException {
try {
return channel.getJSONObject("visuals").getJSONArray("visuals").getJSONObject(0).getString("visual_url");
return user.getJSONObject("visuals").getJSONArray("visuals").getJSONObject(0).getString("visual_url");
} catch (Exception e) {
throw new ParsingException("Could not get Banner", e);
}
}

@Override
public long getSubscriberCount() {
return channel.getLong("followers_count");
return user.getLong("followers_count");
}

@Override
Expand All @@ -79,7 +79,7 @@ public String getFeedUrl() throws ParsingException {
public StreamInfoItemCollector getStreams() throws IOException, ExtractionException {
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());

String apiUrl = "https://api-v2.soundcloud.com/users/" + getChannelId() + "/tracks"
String apiUrl = "https://api-v2.soundcloud.com/users/" + getUserId() + "/tracks"
+ "?client_id=" + SoundcloudParsingHelper.clientId()
+ "&limit=20"
+ "&linked_partitioning=1";
Expand All @@ -91,7 +91,7 @@ public StreamInfoItemCollector getStreams() throws IOException, ExtractionExcept
@Override
public NextItemsResult getNextStreams() throws IOException, ExtractionException {
if (!hasMoreStreams()) {
throw new ExtractionException("Channel doesn't have more streams");
throw new ExtractionException("User doesn't have more streams");
}

StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
Expand Down