Skip to content

Commit 71b3351

Browse files
authored
Merge pull request #1308 from watermelon42/3783_Import_Soundcloud_likes
[SoundCloud] Add support for likes channel tab
2 parents c0ff21a + 5e1a1d5 commit 71b3351

8 files changed

Lines changed: 92 additions & 8 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/channel/tabs/ChannelTabs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public final class ChannelTabs {
1111
public static final String CHANNELS = "channels";
1212
public static final String PLAYLISTS = "playlists";
1313
public static final String ALBUMS = "albums";
14+
public static final String LIKES = "likes";
1415

1516
private ChannelTabs() {
1617
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
2626
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor;
2727
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudPlaylistInfoItemExtractor;
28+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudLikesInfoItemExtractor;
2829
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor;
2930
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
3031
import org.schabi.newpipe.extractor.utils.ImageSuffix;
@@ -396,6 +397,17 @@ public static String getInfoItemsFromApi(final MultiInfoItemsCollector collector
396397
case "playlist":
397398
collector.commit(new SoundcloudPlaylistInfoItemExtractor(searchResult));
398399
break;
400+
case "like":
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+
);
410+
break;
399411
}
400412
});
401413

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public List<ListLinkHandler> getTabs() throws ParsingException {
123123
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.PLAYLISTS);
124124
final String urlAlbums = url
125125
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.ALBUMS);
126+
final String urlLikes = url
127+
+ SoundcloudChannelTabLinkHandlerFactory.getUrlSuffix(ChannelTabs.LIKES);
126128
final String id = getId();
127129

128130
return List.of(
@@ -131,6 +133,8 @@ public List<ListLinkHandler> getTabs() throws ParsingException {
131133
new ListLinkHandler(urlPlaylists, urlPlaylists, id,
132134
List.of(ChannelTabs.PLAYLISTS), ""),
133135
new ListLinkHandler(urlAlbums, urlAlbums, id,
134-
List.of(ChannelTabs.ALBUMS), ""));
136+
List.of(ChannelTabs.ALBUMS), ""),
137+
new ListLinkHandler(urlLikes, urlLikes, id,
138+
List.of(ChannelTabs.LIKES), ""));
135139
}
136140
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelTabExtractor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ private String getEndpoint() throws ParsingException {
3939
return "/playlists_without_albums";
4040
case ChannelTabs.ALBUMS:
4141
return "/albums";
42+
case ChannelTabs.LIKES:
43+
return "/likes";
4244
}
4345
throw new ParsingException("Unsupported tab: " + getName());
4446
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
2+
3+
import com.grack.nanojson.JsonObject;
4+
5+
public class SoundcloudLikesInfoItemExtractor extends SoundcloudStreamInfoItemExtractor {
6+
7+
public SoundcloudLikesInfoItemExtractor(final JsonObject itemObject) {
8+
super(itemObject.getObject("track"));
9+
}
10+
11+
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudChannelTabLinkHandlerFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public static String getUrlSuffix(final String tab) throws UnsupportedOperationE
2828
return "/sets";
2929
case ChannelTabs.ALBUMS:
3030
return "/albums";
31+
case ChannelTabs.LIKES:
32+
return "/likes";
3133
}
3234
throw new UnsupportedTabException(tab);
3335
}
@@ -56,6 +58,7 @@ public String[] getAvailableContentFilter() {
5658
ChannelTabs.TRACKS,
5759
ChannelTabs.PLAYLISTS,
5860
ChannelTabs.ALBUMS,
61+
ChannelTabs.LIKES,
5962
};
6063
}
6164
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testVerified() throws Exception {
9999
@Override
100100
public void testTabs() throws Exception {
101101
assertTabsContain(extractor.getTabs(), ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS,
102-
ChannelTabs.ALBUMS);
102+
ChannelTabs.ALBUMS, ChannelTabs.LIKES);
103103
}
104104

105105
@Test
@@ -187,7 +187,7 @@ public void testVerified() throws Exception {
187187
@Override
188188
public void testTabs() throws Exception {
189189
assertTabsContain(extractor.getTabs(), ChannelTabs.TRACKS, ChannelTabs.PLAYLISTS,
190-
ChannelTabs.ALBUMS);
190+
ChannelTabs.ALBUMS, ChannelTabs.LIKES);
191191
}
192192

193193
@Test

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

Lines changed: 56 additions & 5 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

@@ -94,4 +89,60 @@ static void setUp() throws IOException, ExtractionException {
9489
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.PLAYLIST; }
9590
@Override public boolean expectedHasMoreItems() { return true; }
9691
}
92+
93+
static class LikesOnlyTracks extends DefaultListExtractorTest<ChannelTabExtractor> {
94+
private static SoundcloudChannelTabExtractor extractor;
95+
96+
@BeforeAll
97+
static void setUp() throws IOException, ExtractionException {
98+
NewPipe.init(DownloaderTestImpl.getInstance());
99+
extractor = (SoundcloudChannelTabExtractor) SoundCloud
100+
.getChannelTabExtractorFromId("30854092", ChannelTabs.LIKES);
101+
extractor.fetchPage();
102+
}
103+
104+
@Override public ChannelTabExtractor extractor() throws Exception { return extractor; }
105+
@Override public StreamingService expectedService() throws Exception { return SoundCloud; }
106+
@Override public String expectedName() throws Exception { return ChannelTabs.LIKES; }
107+
@Override public String expectedId() throws Exception { return "30854092"; }
108+
@Override public String expectedUrlContains() throws Exception { return "https://soundcloud.com/lubenitza/likes"; }
109+
@Override public String expectedOriginalUrlContains() throws Exception { return "https://soundcloud.com/lubenitza/likes"; }
110+
@Override public InfoItem.InfoType expectedInfoItemType() { return InfoItem.InfoType.STREAM; }
111+
@Override public boolean expectedHasMoreItems() { return true; }
112+
113+
@Test
114+
void testGetPageInNewExtractor() throws Exception {
115+
final ChannelTabExtractor newTabExtractor =
116+
SoundCloud.getChannelTabExtractorFromId("30854092", ChannelTabs.LIKES);
117+
defaultTestGetPageInNewExtractor(extractor, newTabExtractor);
118+
}
119+
}
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+
}
97148
}

0 commit comments

Comments
 (0)