Skip to content

Commit ad7f97a

Browse files
committed
fix PeerTube description and add more description tests
actually, the max description length is 250 after request with our extractor. during my tests, I made API requests with Firefox, copy/pasted into echo "insert description" | wc, and it was giving a wrong length, maybe due to the escapers, I have no idea anyway, it's now fixed
1 parent b382416 commit ad7f97a

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public String getDescription() throws ParsingException {
7676
} catch (ParsingException e) {
7777
return "No description";
7878
}
79-
if (desc.length() >= 255 && desc.substring(desc.length() - 3).equals("...")) {
79+
if (desc.length() == 250 && desc.substring(desc.length() - 3).equals("...")) {
80+
//if description is shortened, get full description
8081
Downloader dl = NewPipe.getDownloader();
8182
try {
8283
Response response = dl.get(getUrl() + "/description");

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamExtractorDefaultTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
*/
3030
public class PeertubeStreamExtractorDefaultTest {
3131
private static PeertubeStreamExtractor extractor;
32-
private static final String expectedDescription = "**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n\r\n**Take back the control of your videos! [#JoinPeertube](https://joinpeertube.org)**\r\n*A decentralized video hosting network, based on free/libre software!*\r\n\r\n**Animation Produced by:** [LILA](https://libreart.info) - [ZeMarmot Team](https://film.zemarmot.net)\r\n*Directed by* Aryeom\r\n*Assistant* Jehan\r\n**Licence**: [CC-By-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\r\n\r\n**Sponsored by** [Framasoft](https://framasoft.org)\r\n\r\n**Music**: [Red Step Forward](http://play.dogmazic.net/song.php?song_id=52491) - CC-By Ken Bushima\r\n\r\n**Movie Clip**: [Caminades 3: Llamigos](http://www.caminandes.com/) CC-By Blender Institute\r\n\r\n**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/";
32+
private static final String expectedLargeDescription = "**[Want to help to translate this video?](https://weblate.framasoft.org/projects/what-is-peertube-video/)**\r\n\r\n**Take back the control of your videos! [#JoinPeertube](https://joinpeertube.org)**\r\n*A decentralized video hosting network, based on free/libre software!*\r\n\r\n**Animation Produced by:** [LILA](https://libreart.info) - [ZeMarmot Team](https://film.zemarmot.net)\r\n*Directed by* Aryeom\r\n*Assistant* Jehan\r\n**Licence**: [CC-By-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)\r\n\r\n**Sponsored by** [Framasoft](https://framasoft.org)\r\n\r\n**Music**: [Red Step Forward](http://play.dogmazic.net/song.php?song_id=52491) - CC-By Ken Bushima\r\n\r\n**Movie Clip**: [Caminades 3: Llamigos](http://www.caminandes.com/) CC-By Blender Institute\r\n\r\n**Video sources**: https://gitlab.gnome.org/Jehan/what-is-peertube/";
33+
private static final String expectedSmallDescription = "https://www.kickstarter.com/projects/1587081065/nothing-to-hide-the-documentary";
3334

3435
@BeforeClass
3536
public static void setUp() throws Exception {
@@ -52,8 +53,23 @@ public void testGetTitle() throws ParsingException {
5253
}
5354

5455
@Test
55-
public void testGetDescription() throws ParsingException {
56-
assertEquals(expectedDescription, extractor.getDescription());
56+
public void testGetLargeDescription() throws ParsingException {
57+
assertEquals(expectedLargeDescription, extractor.getDescription());
58+
}
59+
60+
@Test
61+
public void testGetEmptyDescription() throws Exception {
62+
PeertubeStreamExtractor extractorEmpty = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://framatube.org/api/v1/videos/d5907aad-2252-4207-89ec-a4b687b9337d");
63+
extractorEmpty.fetchPage();
64+
assertEquals("No description", extractorEmpty.getDescription());
65+
}
66+
67+
@Test
68+
public void testGetSmallDescription() throws Exception {
69+
PeerTube.setInstance(new PeertubeInstance("https://peertube.cpy.re", "PeerTube test server"));
70+
PeertubeStreamExtractor extractorSmall = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.cpy.re/videos/watch/d2a5ec78-5f85-4090-8ec5-dc1102e022ea");
71+
extractorSmall.fetchPage();
72+
assertEquals(expectedSmallDescription, extractorSmall.getDescription());
5773
}
5874

5975
@Test

0 commit comments

Comments
 (0)