Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PeerTube] added metadata, fix descriptions, fix thumbnail, fix upload date, fix age limit, update tests. #239

Merged
merged 21 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a281519
added metadata, fix descriptions, fix thumbnail, update tests
B0pol Jan 19, 2020
b382416
changed the way to extract peertube description
B0pol Jan 20, 2020
ad7f97a
fix PeerTube description and add more description tests
B0pol Jan 20, 2020
f403490
Refactoring
B0pol Jan 20, 2020
bcfe7be
Merge branch 'dev' into peertube
B0pol Jan 22, 2020
1a15c0e
agelimit now returns 18 if the video is marked as nsfw, 0 otherwise
B0pol Jan 23, 2020
74439f6
add extraction for support info and rename getLanguageInfo function
B0pol Jan 23, 2020
20da475
empty support returns "", same for empty description
B0pol Jan 23, 2020
a691d6d
fix upload date: there was a one hour delay
B0pol Jan 23, 2020
c790261
update test
B0pol Jan 23, 2020
812c8e0
authorName in comments now follow PeerTube website
B0pol Jan 23, 2020
b816e48
Merge branch 'dev' into peertube
B0pol Jan 24, 2020
341372c
reindenting (ctrl alt l) on JsonUtils and PeertubeStreamExtractor
B0pol Jan 24, 2020
e392b6c
getLanguageInfo returns Locale instead of String
B0pol Jan 25, 2020
b671a4b
Merge branch 'dev' into peertube
B0pol Feb 1, 2020
5756df8
Use GMT as base time (actually fix upload date)
B0pol Feb 6, 2020
26c65b2
Create class Description
B0pol Feb 6, 2020
70a40e7
Description: rm constructor by serviceId
B0pol Feb 7, 2020
0f8a7f9
fix testGetUploadDate for PeerTubeStreamExtractor
B0pol Feb 7, 2020
11bcc78
Description implements Serializable. fix NotSerializableException
B0pol Feb 7, 2020
0e33249
Fix SoundCloud description test
TobiGr Feb 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ To test changes quickly you can build the library locally. Using the local Maven
2. It's _recommended_ that you change the `version` of this library (e.g. `LOCAL_SNAPSHOT`).
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`)
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'`)

> 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.

## Supported sites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.*;
import org.schabi.newpipe.extractor.utils.JsonUtils;

import javax.annotation.Nonnull;
import java.io.IOException;
Expand Down Expand Up @@ -225,4 +226,35 @@ public String getName() throws ParsingException {
public String getOriginalUrl() throws ParsingException {
return data.getString("frontend_link");
}

@Override
public String getHost() throws ParsingException {
return "";
}

@Override
public String getPrivacy() throws ParsingException {
return "";
}

@Override
public String getCategory() throws ParsingException {
return "";
}

@Override
public String getLicence() throws ParsingException {
return "";
}

@Override
public String getStreamInfoLanguage() throws ParsingException {
return "";
}

@Nonnull
@Override
public List<String> getTags() throws ParsingException {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.jsoup.helper.StringUtil;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Response;
Expand All @@ -29,7 +29,6 @@
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils;

import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
Expand Down Expand Up @@ -66,21 +65,39 @@ public DateWrapper getUploadDate() throws ParsingException {

@Override
public String getThumbnailUrl() throws ParsingException {
return baseUrl + JsonUtils.getString(json, "thumbnailPath");
return baseUrl + JsonUtils.getString(json, "previewPath");
}

@Override
public String getDescription() throws ParsingException {
String desc;
try {
return JsonUtils.getString(json, "description");
}catch(ParsingException e) {
desc = JsonUtils.getString(json, "description");
} catch (ParsingException e) {
return "No description";
}
if (desc.length() == 250 && desc.substring(247).equals("...")) {
//if description is shortened, get full description
Downloader dl = NewPipe.getDownloader();
try {
Response response = dl.get(getUrl() + "/description");
JsonObject jsonObject = JsonParser.object().from(response.responseBody());
desc = JsonUtils.getString(jsonObject, "description");
} catch (ReCaptchaException | IOException | JsonParserException e) {
e.printStackTrace();
}
}
return desc;
}

@Override
public int getAgeLimit() throws ParsingException {
return NO_AGE_LIMIT;
boolean isNSFW = JsonUtils.getBoolean(json, "nsfw");
if (isNSFW) {
return 18;
} else {
return NO_AGE_LIMIT;
}
}

@Override
Expand Down Expand Up @@ -224,8 +241,9 @@ public StreamInfoItemsCollector getRelatedStreams() throws IOException, Extracti
if(!StringUtil.isBlank(apiUrl)) getStreamsFromApi(collector, apiUrl);
return collector;
}

private List<String> getTags(){

@Override
public List<String> getTags(){
B0pol marked this conversation as resolved.
Show resolved Hide resolved
try {
return (List) JsonUtils.getArray(json, "tags");
} catch (Exception e) {
Expand Down Expand Up @@ -339,4 +357,28 @@ public String getOriginalUrl() throws ParsingException {
return baseUrl + "/videos/watch/" + getId();
}

@Override
public String getHost() throws ParsingException {
return JsonUtils.getString(json, "account.host");
}

@Override
public String getPrivacy() throws ParsingException {
return JsonUtils.getString(json, "privacy.label");
}

@Override
public String getCategory() throws ParsingException {
return JsonUtils.getString(json, "category.label");
}

@Override
public String getLicence() throws ParsingException {
return JsonUtils.getString(json, "licence.label");
}

@Override
public String getStreamInfoLanguage() throws ParsingException {
return JsonUtils.getString(json, "language.label");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,35 @@ public StreamInfoItemsCollector getRelatedStreams() throws IOException, Extracti
public String getErrorMessage() {
return null;
}

@Override
public String getHost() throws ParsingException {
return "";
}

@Override
public String getPrivacy() throws ParsingException {
return "";
}

@Override
public String getCategory() throws ParsingException {
return "";
}

@Override
public String getLicence() throws ParsingException {
return "";
}

@Override
public String getStreamInfoLanguage() throws ParsingException {
return "";
}

@Nonnull
@Override
public List<String> getTags() throws ParsingException {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,35 @@ public List<Frameset> getFrames() throws ExtractionException {
throw new ExtractionException(e);
}
}

@Override
public String getHost() throws ParsingException {
return "";
}

@Override
public String getPrivacy() throws ParsingException {
return "";
}

@Override
public String getCategory() throws ParsingException {
return "";
}

@Override
public String getLicence() throws ParsingException {
return "";
}

@Override
public String getStreamInfoLanguage() throws ParsingException {
return "";
}

@Nonnull
@Override
public List<String> getTags() throws ParsingException {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Parser;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -349,4 +350,60 @@ protected long getTimestampSeconds(String regexPattern) throws ParsingException
return 0;
}
}

/**
* The host of the stream (Eg. peertube.cpy.re).
* If the host is not available, or if the service doesn't use
* a federated system, but a centralised system,
* you can simply return an empty string.
* @return the host of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getHost() throws ParsingException;

/**
* The privacy of the stream (Eg. Public, Private, Unlisted…).
* If the privacy is not available you can simply return an empty string.
* @return the privacy of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getPrivacy() throws ParsingException;
TobiGr marked this conversation as resolved.
Show resolved Hide resolved

/**
* The name of the category of the stream.
* If the category is not available you can simply return an empty string.
* @return the category of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getCategory() throws ParsingException;

/**
* The name of the licence of the stream.
* If the licence is not available you can simply return an empty string.
* @return the licence of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getLicence() throws ParsingException;

/**
* The language of the stream.
* If the language is not available you can simply return an empty string.
* @return the licence of the stream or an empty String.
* @throws ParsingException
*/
@Nonnull
public abstract String getStreamInfoLanguage() throws ParsingException;

/**
* The list of tags of the stream.
* If the tag list is not available you can simply return an empty list.
* @return the list of tags of the stream or an empty list.
* @throws ParsingException
*/
@Nonnull
public abstract List<String> getTags() throws ParsingException;
}
Loading