Skip to content

Commit a281519

Browse files
committed
added metadata, fix descriptions, fix thumbnail, update tests
thumbnail: quality before: https://peertube.cpy.re/static/thumbnails/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg quality after: https://peertube.cpy.re/static/previews/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg description: we were getting about the first 260 characters, we now get full description (with fallback to first 260 chars if the get request for full description fails) test: updated tests to match description, also changed some test: it was assertEquals(extracted, expected), but the proper way to do it is assertEquals(expected, extracted) metadata: got host, privacy (public, private, unlisted), licence, language, tags
1 parent 2ee558f commit a281519

10 files changed

Lines changed: 295 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ To test changes quickly you can build the library locally. Using the local Maven
2121
2. It's _recommended_ that you change the `version` of this library (e.g. `LOCAL_SNAPSHOT`).
2222
3. Run gradle's `ìnstall` task to deploy this library to your local repository (using the wrapper, present in the root of this project: `./gradlew install`)
2323
4. Change the dependency version used in your project to match the one you chose in step 2 (`implementation 'com.github.TeamNewPipe:NewPipeExtractor:LOCAL_SNAPSHOT'`)
24-
24+
2525
> Tip for Android Studio users: After you make changes and run the `install` task, use the menu option `File → "Sync with File System"` to refresh the library in your project.
2626
2727
## Supported sites

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1313
import org.schabi.newpipe.extractor.localization.DateWrapper;
1414
import org.schabi.newpipe.extractor.stream.*;
15+
import org.schabi.newpipe.extractor.utils.JsonUtils;
1516

1617
import javax.annotation.Nonnull;
1718
import java.io.IOException;
@@ -225,4 +226,35 @@ public String getName() throws ParsingException {
225226
public String getOriginalUrl() throws ParsingException {
226227
return data.getString("frontend_link");
227228
}
229+
230+
@Override
231+
public String getHost() throws ParsingException {
232+
return "";
233+
}
234+
235+
@Override
236+
public String getPrivacy() throws ParsingException {
237+
return "";
238+
}
239+
240+
@Override
241+
public String getCategory() throws ParsingException {
242+
return "";
243+
}
244+
245+
@Override
246+
public String getLicence() throws ParsingException {
247+
return "";
248+
}
249+
250+
@Override
251+
public String getStreamInfoLanguage() throws ParsingException {
252+
return "";
253+
}
254+
255+
@Nonnull
256+
@Override
257+
public List<String> getTags() throws ParsingException {
258+
return new ArrayList<>();
259+
}
228260
}

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import org.jsoup.helper.StringUtil;
1111
import org.schabi.newpipe.extractor.MediaFormat;
12-
import org.schabi.newpipe.extractor.ServiceList;
12+
import org.schabi.newpipe.extractor.NewPipe;
1313
import org.schabi.newpipe.extractor.StreamingService;
1414
import org.schabi.newpipe.extractor.downloader.Downloader;
1515
import org.schabi.newpipe.extractor.downloader.Response;
@@ -29,7 +29,6 @@
2929
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
3030
import org.schabi.newpipe.extractor.stream.VideoStream;
3131
import org.schabi.newpipe.extractor.utils.JsonUtils;
32-
import org.schabi.newpipe.extractor.utils.Utils;
3332

3433
import com.grack.nanojson.JsonArray;
3534
import com.grack.nanojson.JsonObject;
@@ -66,16 +65,25 @@ public DateWrapper getUploadDate() throws ParsingException {
6665

6766
@Override
6867
public String getThumbnailUrl() throws ParsingException {
69-
return baseUrl + JsonUtils.getString(json, "thumbnailPath");
68+
return baseUrl + JsonUtils.getString(json, "previewPath");
7069
}
7170

7271
@Override
7372
public String getDescription() throws ParsingException {
73+
String description = "";
74+
Downloader dl = NewPipe.getDownloader();
7475
try {
75-
return JsonUtils.getString(json, "description");
76-
}catch(ParsingException e) {
77-
return "No description";
76+
Response response = dl.get(getUrl() + "/description");
77+
JsonObject jsonObject = JsonParser.object().from(response.responseBody());
78+
description = JsonUtils.getString(jsonObject, "description");
79+
} catch (ReCaptchaException | IOException | JsonParserException e) {
80+
e.printStackTrace();
7881
}
82+
if (description.equals("")) {
83+
//if the request above failed
84+
description = JsonUtils.getString(json, "description");
85+
}
86+
return description;
7987
}
8088

8189
@Override
@@ -224,8 +232,9 @@ public StreamInfoItemsCollector getRelatedStreams() throws IOException, Extracti
224232
if(!StringUtil.isBlank(apiUrl)) getStreamsFromApi(collector, apiUrl);
225233
return collector;
226234
}
227-
228-
private List<String> getTags(){
235+
236+
@Override
237+
public List<String> getTags(){
229238
try {
230239
return (List) JsonUtils.getArray(json, "tags");
231240
} catch (Exception e) {
@@ -339,4 +348,29 @@ public String getOriginalUrl() throws ParsingException {
339348
return baseUrl + "/videos/watch/" + getId();
340349
}
341350

351+
//TODO: change privacy, category, licence by getting ID, therefore we will be able to translate it
352+
@Override
353+
public String getHost() throws ParsingException {
354+
return JsonUtils.getString(json, "account.host");
355+
}
356+
357+
@Override
358+
public String getPrivacy() throws ParsingException {
359+
return JsonUtils.getString(json, "privacy.label");
360+
}
361+
362+
@Override
363+
public String getCategory() throws ParsingException {
364+
return JsonUtils.getString(json, "category.label");
365+
}
366+
367+
@Override
368+
public String getLicence() throws ParsingException {
369+
return JsonUtils.getString(json, "licence.label");
370+
}
371+
372+
@Override
373+
public String getStreamInfoLanguage() throws ParsingException {
374+
return JsonUtils.getString(json, "language.label");
375+
}
342376
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,35 @@ public StreamInfoItemsCollector getRelatedStreams() throws IOException, Extracti
254254
public String getErrorMessage() {
255255
return null;
256256
}
257+
258+
@Override
259+
public String getHost() throws ParsingException {
260+
return "";
261+
}
262+
263+
@Override
264+
public String getPrivacy() throws ParsingException {
265+
return "";
266+
}
267+
268+
@Override
269+
public String getCategory() throws ParsingException {
270+
return "";
271+
}
272+
273+
@Override
274+
public String getLicence() throws ParsingException {
275+
return "";
276+
}
277+
278+
@Override
279+
public String getStreamInfoLanguage() throws ParsingException {
280+
return "";
281+
}
282+
283+
@Nonnull
284+
@Override
285+
public List<String> getTags() throws ParsingException {
286+
return new ArrayList<>();
287+
}
257288
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,4 +1113,35 @@ public List<Frameset> getFrames() throws ExtractionException {
11131113
throw new ExtractionException(e);
11141114
}
11151115
}
1116+
1117+
@Override
1118+
public String getHost() throws ParsingException {
1119+
return "";
1120+
}
1121+
1122+
@Override
1123+
public String getPrivacy() throws ParsingException {
1124+
return "";
1125+
}
1126+
1127+
@Override
1128+
public String getCategory() throws ParsingException {
1129+
return "";
1130+
}
1131+
1132+
@Override
1133+
public String getLicence() throws ParsingException {
1134+
return "";
1135+
}
1136+
1137+
@Override
1138+
public String getStreamInfoLanguage() throws ParsingException {
1139+
return "";
1140+
}
1141+
1142+
@Nonnull
1143+
@Override
1144+
public List<String> getTags() throws ParsingException {
1145+
return new ArrayList<>();
1146+
}
11161147
}

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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2828
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
2929
import org.schabi.newpipe.extractor.localization.DateWrapper;
30+
import org.schabi.newpipe.extractor.utils.JsonUtils;
3031
import org.schabi.newpipe.extractor.utils.Parser;
3132

3233
import javax.annotation.Nonnull;
@@ -349,4 +350,60 @@ protected long getTimestampSeconds(String regexPattern) throws ParsingException
349350
return 0;
350351
}
351352
}
353+
354+
/**
355+
* The host of the stream (Eg. peertube.cpy.re).
356+
* If the privacy is not available, or if the service doesn't use
357+
* a federated system, but a centralised system,
358+
* you can simply return an empty string.
359+
* @return the host of the stream or an empty String.
360+
* @throws ParsingException
361+
*/
362+
@Nonnull
363+
public abstract String getHost() throws ParsingException;
364+
365+
/**
366+
* The privacy of the stream (Eg. Public, Private, Unlisted…).
367+
* If the privacy is not available you can simply return an empty string.
368+
* @return the privacy of the stream or an empty String.
369+
* @throws ParsingException
370+
*/
371+
@Nonnull
372+
public abstract String getPrivacy() throws ParsingException;
373+
374+
/**
375+
* The name of the category of the stream.
376+
* If the category is not available you can simply return an empty string.
377+
* @return the category of the stream or an empty String.
378+
* @throws ParsingException
379+
*/
380+
@Nonnull
381+
public abstract String getCategory() throws ParsingException;
382+
383+
/**
384+
* The name of the licence of the stream.
385+
* If the licence is not available you can simply return an empty string.
386+
* @return the licence of the stream or an empty String.
387+
* @throws ParsingException
388+
*/
389+
@Nonnull
390+
public abstract String getLicence() throws ParsingException;
391+
392+
/**
393+
* The language of the stream.
394+
* If the language is not available you can simply return an empty string.
395+
* @return the licence of the stream or an empty String.
396+
* @throws ParsingException
397+
*/
398+
@Nonnull
399+
public abstract String getStreamInfoLanguage() throws ParsingException;
400+
401+
/**
402+
* The list of tags of the stream.
403+
* If the tag list is not available you can simply return an empty list.
404+
* @return the list of tags of the stream or an empty list.
405+
* @throws ParsingException
406+
*/
407+
@Nonnull
408+
public abstract List<String> getTags() throws ParsingException;
352409
}

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,38 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
270270
streamInfo.addError(e);
271271
}
272272

273+
//additional info
274+
try {
275+
streamInfo.setHost(extractor.getHost());
276+
} catch (Exception e) {
277+
streamInfo.addError(e);
278+
}
279+
try {
280+
streamInfo.setPrivacy(extractor.getPrivacy());
281+
} catch (Exception e) {
282+
streamInfo.addError(e);
283+
}
284+
try {
285+
streamInfo.setCategory(extractor.getCategory());
286+
} catch (Exception e) {
287+
streamInfo.addError(e);
288+
}
289+
try {
290+
streamInfo.setLicence(extractor.getLicence());
291+
} catch (Exception e) {
292+
streamInfo.addError(e);
293+
}
294+
try {
295+
streamInfo.setLanguage(extractor.getStreamInfoLanguage());
296+
} catch (Exception e) {
297+
streamInfo.addError(e);
298+
}
299+
try {
300+
streamInfo.setTags(extractor.getTags());
301+
} catch (Exception e) {
302+
streamInfo.addError(e);
303+
}
304+
273305
streamInfo.setRelatedStreams(ExtractorHelper.getRelatedVideosOrLogError(streamInfo, extractor));
274306

275307
return streamInfo;
@@ -308,6 +340,13 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
308340
private long startPosition = 0;
309341
private List<SubtitlesStream> subtitles = new ArrayList<>();
310342

343+
private String host = "";
344+
private String privacy = "";
345+
private String category = "";
346+
private String licence = "";
347+
private String language = "";
348+
private List<String> tags = new ArrayList<>();
349+
311350
/**
312351
* Get the stream type
313352
*
@@ -533,4 +572,53 @@ public void setSubtitles(List<SubtitlesStream> subtitles) {
533572
this.subtitles = subtitles;
534573
}
535574

575+
public String getHost() {
576+
return this.host;
577+
}
578+
579+
public void setHost(String str) {
580+
this.host = str;
581+
}
582+
583+
public String getPrivacy() {
584+
return this.privacy;
585+
}
586+
587+
public void setPrivacy(String str) {
588+
this.privacy = str;
589+
}
590+
591+
public String getCategory() {
592+
return this.category;
593+
}
594+
595+
public void setCategory(String cat) {
596+
this.category = cat;
597+
}
598+
599+
public String getLicence() {
600+
return this.licence;
601+
}
602+
603+
public void setLicence(String str) {
604+
this.licence = str;
605+
}
606+
607+
public String getLanguage() {
608+
return this.language;
609+
}
610+
611+
public void setLanguage(String lang) {
612+
this.language = lang;
613+
}
614+
615+
public List<String> getTags() {
616+
return this.tags;
617+
}
618+
619+
public void setTags(List<String> tags) {
620+
this.tags = tags;
621+
}
622+
623+
536624
}

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,4 @@ public static String getBaseUrl(String url) throws ParsingException {
185185
}
186186
return uri.getProtocol() + "://" + uri.getAuthority();
187187
}
188-
189188
}

0 commit comments

Comments
 (0)