Parse browseEndpoint and watchEndpoint in descriptions

This commit is contained in:
wb9688 2020-02-26 19:37:58 +01:00
parent 8dc39d517a
commit 8d503407ef
2 changed files with 25 additions and 10 deletions

View File

@ -229,7 +229,25 @@ public class YoutubeStreamExtractor extends StreamExtractor {
descriptionBuilder.append("<a href=\"").append(internUrl).append("\">").append(text).append("</a>");
htmlConversionRequired = true;
}
continue;
} else if (textHolder.getObject("navigationEndpoint").getObject("browseEndpoint") != null) {
descriptionBuilder.append("<a href=\"https://www.youtube.com").append(
textHolder.getObject("navigationEndpoint").getObject("browseEndpoint")
.getString("canonicalBaseUrl")).append("\">").append(text).append("</a>");
htmlConversionRequired = true;
} else if (textHolder.getObject("navigationEndpoint").getObject("watchEndpoint") != null) {
if (textHolder.getObject("navigationEndpoint").getObject("watchEndpoint").getString("playlistId") != null) {
descriptionBuilder.append("<a href=\"https://www.youtube.com/watch?v=").append(
textHolder.getObject("navigationEndpoint").getObject("watchEndpoint")
.getString("videoId")).append("&amp;list=")
.append(textHolder.getObject("navigationEndpoint")
.getObject("watchEndpoint").getString("playlistId"))
.append("\">").append(text).append("</a>");
} else {
descriptionBuilder.append("<a href=\"https://www.youtube.com/watch?v=").append(
textHolder.getObject("navigationEndpoint").getObject("watchEndpoint")
.getString("videoId")).append("\">").append(text).append("</a>");
}
htmlConversionRequired = true;
}
continue;
}

View File

@ -245,21 +245,18 @@ public class YoutubeStreamExtractorDefaultTest {
@Test
public void testGetDescription() throws ParsingException {
System.out.println(extractor.getDescription().getContent());
assertNotNull(extractor.getDescription());
assertFalse(extractor.getDescription().getContent().isEmpty());
}
@Test
public void testGetFullLinksInDescription() throws ParsingException {
assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(extractor.getDescription().getContent().contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertFalse(extractor.getDescription().getContent().contains("https://youtu.be/X7FLCHVXpsA?list=PL7..."));
assertFalse(extractor.getDescription().getContent().contains("https://youtu.be/Lqv6G0pDNnw?list=PL7..."));
assertFalse(extractor.getDescription().getContent().contains("https://youtu.be/XxaRBPyrnBU?list=PL7..."));
assertFalse(extractor.getDescription().getContent().contains("https://youtu.be/U-9tUEOFKNU?list=PL7..."));
final String description = extractor.getDescription().getContent();
assertTrue(description.contains("https://www.youtube.com/watch?v=X7FLCHVXpsA&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(description.contains("https://www.youtube.com/watch?v=Lqv6G0pDNnw&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(description.contains("https://www.youtube.com/watch?v=XxaRBPyrnBU&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
assertTrue(description.contains("https://www.youtube.com/watch?v=U-9tUEOFKNU&amp;list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34"));
}
}