Skip to content

Commit 504d099

Browse files
authored
Merge pull request #1460 from G-flat/fix_error_for_yt_videos_with_no_title
[YouTube] Fix retrieving the title for videos with no title
2 parents 4701a17 + 97083db commit 504d099

3 files changed

Lines changed: 602 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ public String getUrl() throws ParsingException {
130130

131131
@Override
132132
public String getName() throws ParsingException {
133-
final String name = getTextFromObject(videoInfo.getObject("title"));
133+
final JsonObject title = videoInfo.getObject("title");
134+
final String name = getTextFromObject(title);
134135
if (!isNullOrEmpty(name)) {
135136
return name;
136137
}
138+
// Videos can have no title, e.g. https://www.youtube.com/watch?v=nc1kN8ZSfGQ
139+
if (!isNullOrEmpty(title) && !title.has("runs")) {
140+
return "";
141+
}
137142
throw new ParsingException("Could not get name");
138143
}
139144

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamInfoItemTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,29 @@ void lockupViewModelPremiere()
8585
() -> assertFalse(extractor.isShortFormContent())
8686
);
8787
}
88+
89+
@Test
90+
void emptyTitle() throws FileNotFoundException, JsonParserException {
91+
final var json = JsonParser.object().from(new FileInputStream(getMockPath(
92+
YoutubeStreamInfoItemTest.class, "emptyTitle") + ".json"));
93+
final var timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.DEFAULT);
94+
final var extractor = new YoutubeStreamInfoItemExtractor(json, timeAgoParser);
95+
assertAll(
96+
() -> assertEquals(StreamType.VIDEO_STREAM, extractor.getStreamType()),
97+
() -> assertFalse(extractor.isAd()),
98+
() -> assertEquals("https://www.youtube.com/watch?v=nc1kN8ZSfGQ", extractor.getUrl()),
99+
() -> assertEquals("", extractor.getName()),
100+
() -> assertEquals(39, extractor.getDuration()),
101+
() -> assertEquals("hyper", extractor.getUploaderName()),
102+
() -> assertEquals("https://www.youtube.com/channel/UCSezUnbvCLYBXuUlPcXU_QQ", extractor.getUploaderUrl()),
103+
() -> assertFalse(extractor.getUploaderAvatars().isEmpty()),
104+
() -> assertTrue(extractor.isUploaderVerified()),
105+
() -> assertEquals("8 years ago", extractor.getTextualUploadDate()),
106+
() -> assertNotNull(extractor.getUploadDate()),
107+
() -> assertTrue(extractor.getViewCount() >= 1318193),
108+
() -> assertFalse(extractor.getThumbnails().isEmpty()),
109+
() -> assertNull(extractor.getShortDescription()),
110+
() -> assertFalse(extractor.isShortFormContent())
111+
);
112+
}
88113
}

0 commit comments

Comments
 (0)