Skip to content

Commit 5e1a1d5

Browse files
committed
Handle liked playlists using the SoundcloudPlaylistInfoItemExtractor
1 parent 9645127 commit 5e1a1d5

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,15 @@ public static String getInfoItemsFromApi(final MultiInfoItemsCollector collector
398398
collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult));
399399
break;
400400
case "like":
401-
collector.commit(new SoundcloudLikesInfoItemExtractor(searchResult));
401+
// Soundcloud users can like tracks or playlists and all end up in the
402+
// `Likes` feed, so they should be handled by the correct extractor.
403+
final JsonObject likedPlaylist =
404+
searchResult.getObject("playlist", null);
405+
collector.commit(
406+
null == likedPlaylist
407+
? new SoundcloudLikesInfoItemExtractor(searchResult)
408+
: new SoundcloudPlaylistInfoItemExtractor(likedPlaylist)
409+
);
402410
break;
403411
}
404412
});

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudChannelTabExtractorTest.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@
99
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor;
1010
import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs;
1111
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
12-
import org.schabi.newpipe.extractor.exceptions.ParsingException;
13-
import org.schabi.newpipe.extractor.services.BaseListExtractorTest;
1412
import org.schabi.newpipe.extractor.services.DefaultListExtractorTest;
1513
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelTabExtractor;
1614

1715
import java.io.IOException;
1816

1917
import static org.junit.jupiter.api.Assertions.assertEquals;
20-
import static org.schabi.newpipe.extractor.ServiceList.PeerTube;
2118
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
2219
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor;
23-
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems;
24-
import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems;
2520

2621
class SoundcloudChannelTabExtractorTest {
2722

@@ -95,7 +90,7 @@ static void setUp() throws IOException, ExtractionException {
9590
@Override public boolean expectedHasMoreItems() { return true; }
9691
}
9792

98-
static class Likes extends DefaultListExtractorTest<ChannelTabExtractor> {
93+
static class LikesOnlyTracks extends DefaultListExtractorTest<ChannelTabExtractor> {
9994
private static SoundcloudChannelTabExtractor extractor;
10095

10196
@BeforeAll
@@ -122,4 +117,32 @@ void testGetPageInNewExtractor() throws Exception {
122117
defaultTestGetPageInNewExtractor(extractor, newTabExtractor);
123118
}
124119
}
120+
121+
static class LikesOnlyPlaylists extends DefaultListExtractorTest<ChannelTabExtractor> {
122+
private static SoundcloudChannelTabExtractor extractor;
123+
124+
@BeforeAll
125+
static void setUp() throws IOException, ExtractionException {
126+
NewPipe.init(DownloaderTestImpl.getInstance());
127+
extractor = (SoundcloudChannelTabExtractor) SoundCloud
128+
.getChannelTabExtractorFromId("1280839267", ChannelTabs.LIKES);
129+
extractor.fetchPage();
130+
}
131+
132+
@Override public ChannelTabExtractor extractor() throws Exception { return extractor; }
133+
@Override public StreamingService expectedService() throws Exception { return SoundCloud; }
134+
@Override public String expectedName() throws Exception { return ChannelTabs.LIKES; }
135+
@Override public String expectedId() throws Exception { return "1280839267"; }
136+
@Override public String expectedUrlContains() throws Exception { return "https://soundcloud.com/soreen-735855039/likes"; }
137+
@Override public String expectedOriginalUrlContains() throws Exception { return "https://soundcloud.com/soreen-735855039/likes"; }
138+
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.PLAYLIST; }
139+
@Override public boolean expectedHasMoreItems() { return true; }
140+
141+
@Test
142+
void testGetPageInNewExtractor() throws Exception {
143+
final ChannelTabExtractor newTabExtractor =
144+
SoundCloud.getChannelTabExtractorFromId("1280839267", ChannelTabs.LIKES);
145+
defaultTestGetPageInNewExtractor(extractor, newTabExtractor);
146+
}
147+
}
125148
}

0 commit comments

Comments
 (0)