Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public final class ChannelTabs {
public static final String CHANNELS = "channels";
public static final String PLAYLISTS = "playlists";
public static final String ALBUMS = "albums";
public static final String LIKES = "likes";

private ChannelTabs() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudPlaylistInfoItemExtractor;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudLikesInfoItemExtractor;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.utils.ImageSuffix;
Expand Down Expand Up @@ -396,6 +397,17 @@ public static String getInfoItemsFromApi(final MultiInfoItemsCollector collector
case "playlist":
collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult));
break;
case "like":
// Soundcloud users can like tracks or playlists and all end up in the
// `Likes` feed, so they should be handled by the correct extractor.
final JsonObject likedPlaylist =
searchResult.getObject("playlist", null);
collector.commit(
null == likedPlaylist
? new SoundcloudLikesInfoItemExtractor(searchResult)
: new SoundcloudPlaylistInfoItemExtractor(likedPlaylist)
);
break;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public List<ListLinkHandler> getTabs() throws ParsingException {
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.PLAYLISTS);
final String urlAlbums = url
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.ALBUMS);
final String urlLikes = url
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.LIKES);
final String id = getId();

return List.of(
Expand All @@ -131,6 +133,8 @@ public List<ListLinkHandler> getTabs() throws ParsingException {
new ListLinkHandler(urlPlaylists, urlPlaylists, id,
List.of(ChannelTabs.PLAYLISTS), ""),
new ListLinkHandler(urlAlbums, urlAlbums, id,
List.of(ChannelTabs.ALBUMS), ""));
List.of(ChannelTabs.ALBUMS), ""),
new ListLinkHandler(urlLikes, urlLikes, id,
List.of(ChannelTabs.LIKES), ""));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private String getEndpoint() throws ParsingException {
return "/playlists_without_albums";
case ChannelTabs.ALBUMS:
return "/albums";
case ChannelTabs.LIKES:
return "/likes";
}
throw new ParsingException("Unsupported tab: " + getName());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.schabi.newpipe.extractor.services.soundcloud.extractors;

import com.grack.nanojson.JsonObject;

public class SoundcloudLikesInfoItemExtractor extends SoundcloudStreamInfoItemExtractor {

public SoundcloudLikesInfoItemExtractor(final JsonObject itemObject) {
super(itemObject.getObject("track"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static String getUrlSuffix(final String tab) throws UnsupportedOperationE
return "/sets";
case ChannelTabs.ALBUMS:
return "/albums";
case ChannelTabs.LIKES:
return "/likes";
}
throw new UnsupportedTabException(tab);
}
Expand Down Expand Up @@ -56,6 +58,7 @@ public String[] getAvailableContentFilter() {
ChannelTabs.TRACKS,
ChannelTabs.PLAYLISTS,
ChannelTabs.ALBUMS,
ChannelTabs.LIKES,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void testVerified() throws Exception {
@Override
public void testTabs() throws Exception {
assertTabsContain(extractor.getTabs(), ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS,
ChannelTabs.ALBUMS);
ChannelTabs.ALBUMS, ChannelTabs.LIKES);
}

@Test
Expand Down Expand Up @@ -187,7 +187,7 @@ public void testVerified() throws Exception {
@Override
public void testTabs() throws Exception {
assertTabsContain(extractor.getTabs(), ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS,
ChannelTabs.ALBUMS);
ChannelTabs.ALBUMS, ChannelTabs.LIKES);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
import org.schabi.newpipe.extractor.services.DefaultListExtractorTest;
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelTabExtractor;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;

class SoundcloudChannelTabExtractorTest {

Expand Down Expand Up @@ -94,4 +89,60 @@ static void setUp() throws IOException, ExtractionException {
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.PLAYLIST; }
@Override public boolean expectedHasMoreItems() { return true; }
}

static class LikesOnlyTracks extends DefaultListExtractorTest<ChannelTabExtractor> {
private static SoundcloudChannelTabExtractor extractor;

@BeforeAll
static void setUp() throws IOException, ExtractionException {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (SoundcloudChannelTabExtractor) SoundCloud
.getChannelTabExtractorFromId("30854092", ChannelTabs.LIKES);
extractor.fetchPage();
}

@Override public ChannelTabExtractor extractor() throws Exception { return extractor; }
@Override public StreamingService expectedService() throws Exception { return SoundCloud; }
@Override public String expectedName() throws Exception { return ChannelTabs.LIKES; }
@Override public String expectedId() throws Exception { return "30854092"; }
@Override public String expectedUrlContains() throws Exception { return "https://soundcloud.com/lubenitza/likes"; }
@Override public String expectedOriginalUrlContains() throws Exception { return "https://soundcloud.com/lubenitza/likes"; }
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; }
@Override public boolean expectedHasMoreItems() { return true; }

@Test
void testGetPageInNewExtractor() throws Exception {
final ChannelTabExtractor newTabExtractor =
SoundCloud.getChannelTabExtractorFromId("30854092", ChannelTabs.LIKES);
defaultTestGetPageInNewExtractor(extractor, newTabExtractor);
}
}

static class LikesOnlyPlaylists extends DefaultListExtractorTest<ChannelTabExtractor> {
private static SoundcloudChannelTabExtractor extractor;

@BeforeAll
static void setUp() throws IOException, ExtractionException {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (SoundcloudChannelTabExtractor) SoundCloud
.getChannelTabExtractorFromId("1280839267", ChannelTabs.LIKES);
extractor.fetchPage();
}

@Override public ChannelTabExtractor extractor() throws Exception { return extractor; }
@Override public StreamingService expectedService() throws Exception { return SoundCloud; }
@Override public String expectedName() throws Exception { return ChannelTabs.LIKES; }
@Override public String expectedId() throws Exception { return "1280839267"; }
@Override public String expectedUrlContains() throws Exception { return "https://soundcloud.com/soreen-735855039/likes"; }
@Override public String expectedOriginalUrlContains() throws Exception { return "https://soundcloud.com/soreen-735855039/likes"; }
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.PLAYLIST; }
@Override public boolean expectedHasMoreItems() { return true; }

@Test
void testGetPageInNewExtractor() throws Exception {
final ChannelTabExtractor newTabExtractor =
SoundCloud.getChannelTabExtractorFromId("1280839267", ChannelTabs.LIKES);
defaultTestGetPageInNewExtractor(extractor, newTabExtractor);
}
}
}
Loading