Skip to content

Commit 867695e

Browse files
committed
refactor: cleanup
1 parent 7884e32 commit 867695e

13 files changed

Lines changed: 81 additions & 73 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/InfoItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public enum InfoType {
7777
PLAYLIST,
7878
CHANNEL,
7979
COMMENT,
80-
RENDERERLIST
80+
RENDERER_LIST
8181
}
8282
}

extractor/src/main/java/org/schabi/newpipe/extractor/StreamingService.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,6 @@ public ChannelTabExtractor getChannelTabExtractorFromIdAndBaseUrl(final String i
307307
id, Collections.singletonList(tab), "", baseUrl));
308308
}
309309

310-
public ChannelListExtractor getChannelListExtractor(final String url)
311-
throws ExtractionException {
312-
return getChannelListExtractor(getChannelTabLHFactory().fromUrl(url));
313-
}
314-
315310
public ChannelListExtractor getChannelListExtractor(final String id,
316311
final List<String> contentFilter,
317312
final String baseUrl)

extractor/src/main/java/org/schabi/newpipe/extractor/channel/list/ChannelListInfo.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.schabi.newpipe.extractor.ListExtractor;
44
import org.schabi.newpipe.extractor.ListInfo;
5-
import org.schabi.newpipe.extractor.NewPipe;
65
import org.schabi.newpipe.extractor.Page;
76
import org.schabi.newpipe.extractor.StreamingService;
87
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
@@ -22,18 +21,6 @@ public ChannelListInfo(final int serviceId,
2221
super(serviceId, linkHandler, name);
2322
}
2423

25-
public static ChannelListInfo getInfo(final String url)
26-
throws IOException, ExtractionException {
27-
return getInfo(NewPipe.getServiceByUrl(url), url);
28-
}
29-
30-
public static ChannelListInfo getInfo(final StreamingService service, final String url)
31-
throws IOException, ExtractionException {
32-
final ChannelListExtractor extractor = service.getChannelListExtractor(url);
33-
extractor.fetchPage();
34-
return getInfo(extractor);
35-
}
36-
3724
/**
3825
* Get a {@link ChannelListInfo} instance from the given service and link handler.
3926
*
@@ -45,7 +32,8 @@ public static ChannelListInfo getInfo(final StreamingService service, final Stri
4532
public static ChannelListInfo getInfo(@Nonnull final StreamingService service,
4633
@Nonnull final ListLinkHandler linkHandler)
4734
throws ExtractionException, IOException {
48-
final ChannelListExtractor extractor = service.getChannelListExtractor(linkHandler);
35+
final ChannelListExtractor extractor = service
36+
.getChannelListExtractor(linkHandler);
4937
extractor.fetchPage();
5038

5139
return getInfo(extractor);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public final class ChannelTabs {
77

8-
public static final String FEATURED = "featured"; // Home Tab
8+
public static final String FEATURED = "featured";
99
public static final String VIDEOS = "videos";
1010
public static final String TRACKS = "tracks";
1111
public static final String SHORTS = "shorts";

extractor/src/main/java/org/schabi/newpipe/extractor/channel/tabs/rendererlist/RendererListInfoItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class RendererListInfoItem extends InfoItem {
1010
private String rendererListItemType;
1111

1212
public RendererListInfoItem(final int serviceId, final String url, final String name) {
13-
super(InfoType.RENDERERLIST, serviceId, url, name);
13+
super(InfoType.RENDERER_LIST, serviceId, url, name);
1414
}
1515

1616
public String getTitle() {

extractor/src/main/java/org/schabi/newpipe/extractor/channel/tabs/rendererlist/RendererListInfoItemExtractor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
public interface RendererListInfoItemExtractor extends InfoItemExtractor {
88

99
/**
10-
* Get the list link handler of the rendererlist
10+
* Get the list link handler of the renderer list item for extraction
1111
* @return the ListLinkHandler of the list
1212
*/
1313
ListLinkHandler getListLinkHandler() throws ParsingException;
1414

1515
/**
16-
* Get the item type that exist in the renderer list
17-
* @return the item type of the render list
16+
* Gets the item type as a string for this render list item
17+
* @return the item type of the render list string
1818
*/
1919
String getRendererListItemType() throws ParsingException;
2020

@@ -42,8 +42,11 @@ public interface RendererListInfoItemExtractor extends InfoItemExtractor {
4242
*/
4343
boolean isUploaderVerified() throws ParsingException;
4444

45-
46-
static String getRendererListIndexContentFilter(final int index) {
45+
/**
46+
* Creates a render list index that can be used in the content filter
47+
* @return render list index string as a content filter
48+
*/
49+
static String createIndexContentFilter(final int index) {
4750
return "rendererlist_index=" + index;
4851
}
4952
}

extractor/src/main/java/org/schabi/newpipe/extractor/channel/tabs/rendererlist/RendererListInfoItemsCollector.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ public RendererListInfoItem extract(final RendererListInfoItemExtractor extracto
1717
final RendererListInfoItem resultItem = new RendererListInfoItem(
1818
getServiceId(), extractor.getUrl(), extractor.getName());
1919

20-
try {
21-
resultItem.setTitle(extractor.getName());
22-
} catch (final Exception e) {
23-
addError(e);
24-
}
25-
try {
26-
resultItem.setListLinkHandler(extractor.getListLinkHandler());
27-
} catch (final Exception e) {
28-
addError(e);
29-
}
20+
try {
21+
resultItem.setTitle(extractor.getName());
22+
} catch (final Exception e) {
23+
addError(e);
24+
}
25+
try {
26+
resultItem.setListLinkHandler(extractor.getListLinkHandler());
27+
} catch (final Exception e) {
28+
addError(e);
29+
}
3030
try {
3131
resultItem.setRendererListItemType(extractor.getRendererListItemType());
3232
} catch (final Exception e) {
3333
addError(e);
3434
}
3535

36-
37-
return resultItem;
36+
return resultItem;
3837
}
3938
}
4039

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ public static int parseDurationString(@Nonnull final String input)
256256
}
257257

258258
/**
259-
* Parses a param string expecting the string to match exactly rendererlist_index={index}
259+
* Parses a param format string expecting the string to match exactly rendererlist_index={index}
260260
*
261-
* @return the index of the rendererlist
262-
* @throws ParsingException when the url does not match the expected format
261+
* @return the index of the renderer list
262+
* @throws ParsingException when the string does not match the expected format
263263
*/
264-
public static int parseRendererListIndexParam(@Nonnull final String input)
264+
public static int parseParamFormatRendererListIndex(@Nonnull final String input)
265265
throws ParsingException, NumberFormatException {
266266
final Pattern pattern = Pattern.compile("^rendererlist_index=(\\d+)$");
267267
final Matcher matcher = pattern.matcher(input);
@@ -313,12 +313,12 @@ public static Optional<JsonObject> getTabData(@Nonnull final JsonObject jsonResp
313313
}
314314

315315
/**
316-
* Parses a json response of the channel tab featured gets the renderlist data
316+
* Parses a json response of the channel tab featured gets the render list data
317317
*
318318
* @return the data of the renderer list
319319
*/
320-
public static JsonObject getRendererListData(@Nonnull final JsonObject jsonResponse,
321-
final int rendererListIndex) {
320+
public static JsonObject getFeaturedTabRendererListData(@Nonnull final JsonObject jsonResponse,
321+
final int rendererListIndex) {
322322
final Optional<JsonObject> tab = getTabData(jsonResponse, ChannelTabs.FEATURED);
323323

324324
return tab.map(jsonObject -> jsonObject.getObject("content")

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelTabExtractor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ private void commitRendererList(@Nonnull final MultiInfoItemsCollector collector
517517
if (jsonObject.getObject("content")
518518
.getObject("horizontalListRenderer").getArray("items").getObject(0)
519519
.has("gridChannelRenderer")) {
520-
listItemsType = YoutubeShelfRendererListInfoItemExtractor.FEATURED_CHANNEL_LIST;
520+
listItemsType = YoutubeShelfRendererListInfoItemExtractor
521+
.retrieveRendererListTypeString(
522+
YoutubeShelfRendererListInfoItemExtractor
523+
.RendererListTypes.FEATURED_CHANNEL_LIST);
521524
}
522525

523526
if (listItemsType != null) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeaturedChannelListExtractor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public YoutubeFeaturedChannelListExtractor(final StreamingService service,
5656
.findFirst();
5757

5858
if (rendererlist.isEmpty()) {
59-
throw new ExtractionException("content filter for featured channels "
60-
+ "must contain rendererlist_index={index}"
59+
throw new ExtractionException("content filter for featured channels"
60+
+ " must contain rendererlist_index={index}"
6161
+ " to extract featured channels from featured tab");
6262
}
6363

6464
this.rendererListIndex = YoutubeParsingHelper
65-
.parseRendererListIndexParam(rendererlist.get());
65+
.parseParamFormatRendererListIndex(rendererlist.get());
6666
}
6767

6868
@Nonnull
@@ -97,7 +97,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
9797
channelHeader = YoutubeChannelHelper.getChannelHeader(jsonResponse);
9898
channelId = data.channelId;
9999
jsonRendererListData = YoutubeParsingHelper
100-
.getRendererListData(this.jsonResponse, this.rendererListIndex);
100+
.getFeaturedTabRendererListData(this.jsonResponse, this.rendererListIndex);
101101

102102
if (!this.jsonRendererListData.getObject("shelfRenderer")
103103
.getObject("content")

0 commit comments

Comments
 (0)