Skip to content

Commit a902378

Browse files
committed
[YouTube] Cleanup description helper
Remove unneeded isClose field, and make constants private
1 parent b80c3f5 commit a902378

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public final class YoutubeDescriptionHelper {
2424
private YoutubeDescriptionHelper() {
2525
}
2626

27-
public static final String LINK_CLOSE = "</a>";
28-
public static final String STRIKETHROUGH_OPEN = "<s>";
29-
public static final String STRIKETHROUGH_CLOSE = "</s>";
30-
public static final String BOLD_OPEN = "<b>";
31-
public static final String BOLD_CLOSE = "</b>";
32-
public static final String ITALIC_OPEN = "<i>";
33-
public static final String ITALIC_CLOSE = "</i>";
27+
private static final String LINK_CLOSE = "</a>";
28+
private static final String STRIKETHROUGH_OPEN = "<s>";
29+
private static final String STRIKETHROUGH_CLOSE = "</s>";
30+
private static final String BOLD_OPEN = "<b>";
31+
private static final String BOLD_CLOSE = "</b>";
32+
private static final String ITALIC_OPEN = "<i>";
33+
private static final String ITALIC_CLOSE = "</i>";
3434

3535
// special link chips (e.g. for YT videos, YT channels or social media accounts):
3636
// (u00a0) u00a0 u00a0 [/•] u00a0 <link content> u00a0 u00a0
@@ -44,30 +44,26 @@ static final class Run {
4444
@Nonnull final String open;
4545
@Nonnull final String close;
4646
final int pos;
47-
final boolean isClose;
4847
@Nullable final Function<String, String> transformContent;
4948
int openPosInOutput = -1;
5049

5150
Run(
5251
@Nonnull final String open,
5352
@Nonnull final String close,
54-
final int pos,
55-
final boolean isClose
53+
final int pos
5654
) {
57-
this(open, close, pos, isClose, null);
55+
this(open, close, pos, null);
5856
}
5957

6058
Run(
6159
@Nonnull final String open,
6260
@Nonnull final String close,
6361
final int pos,
64-
final boolean isClose,
6562
@Nullable final Function<String, String> transformContent
6663
) {
6764
this.open = open;
6865
this.close = close;
6966
this.pos = pos;
70-
this.isClose = isClose;
7167
this.transformContent = transformContent;
7268
}
7369

@@ -87,6 +83,7 @@ public boolean sameOpen(@Nonnull final Run other) {
8783
* @param attributedDescription the JSON object of the attributed description
8884
* @return the parsed description, in HTML format, as a string
8985
*/
86+
@Nullable
9087
public static String attributedDescriptionToHtml(
9188
@Nullable final JsonObject attributedDescription
9289
) {
@@ -243,10 +240,8 @@ private static void addAllCommandRuns(
243240
final String open = "<a href=\"" + Entities.escape(url) + "\">";
244241
final Function<String, String> transformContent = getTransformContentFun(run);
245242

246-
openers.add(new Run(open, LINK_CLOSE, startIndex, false,
247-
transformContent));
248-
closers.add(new Run(open, LINK_CLOSE, startIndex + length, true,
249-
transformContent));
243+
openers.add(new Run(open, LINK_CLOSE, startIndex, transformContent));
244+
closers.add(new Run(open, LINK_CLOSE, startIndex + length, transformContent));
250245
});
251246
}
252247

@@ -297,19 +292,19 @@ private static void addAllStyleRuns(
297292
final int end = start + length;
298293

299294
if (run.has("strikethrough")) {
300-
openers.add(new Run(STRIKETHROUGH_OPEN, STRIKETHROUGH_CLOSE, start, false));
301-
closers.add(new Run(STRIKETHROUGH_OPEN, STRIKETHROUGH_CLOSE, end, true));
295+
openers.add(new Run(STRIKETHROUGH_OPEN, STRIKETHROUGH_CLOSE, start));
296+
closers.add(new Run(STRIKETHROUGH_OPEN, STRIKETHROUGH_CLOSE, end));
302297
}
303298

304299
if (run.getBoolean("italic", false)) {
305-
openers.add(new Run(ITALIC_OPEN, ITALIC_CLOSE, start, false));
306-
closers.add(new Run(ITALIC_OPEN, ITALIC_CLOSE, end, true));
300+
openers.add(new Run(ITALIC_OPEN, ITALIC_CLOSE, start));
301+
closers.add(new Run(ITALIC_OPEN, ITALIC_CLOSE, end));
307302
}
308303

309304
if (run.has("weightLabel")
310305
&& !"FONT_WEIGHT_NORMAL".equals(run.getString("weightLabel"))) {
311-
openers.add(new Run(BOLD_OPEN, BOLD_CLOSE, start, false));
312-
closers.add(new Run(BOLD_OPEN, BOLD_CLOSE, end, true));
306+
openers.add(new Run(BOLD_OPEN, BOLD_CLOSE, start));
307+
closers.add(new Run(BOLD_OPEN, BOLD_CLOSE, end));
313308
}
314309
});
315310
}

extractor/src/main/java/org/schabi/newpipe/extractor/stream/Description.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.io.Serializable;
44
import java.util.Objects;
55

6+
import javax.annotation.Nullable;
7+
68
public class Description implements Serializable {
79

810
public static final int HTML = 1;
@@ -13,7 +15,7 @@ public class Description implements Serializable {
1315
private final String content;
1416
private final int type;
1517

16-
public Description(final String content, final int type) {
18+
public Description(@Nullable final String content, final int type) {
1719
this.type = type;
1820
if (content == null) {
1921
this.content = "";

0 commit comments

Comments
 (0)