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

Release 0.21.12 #758

Merged
merged 35 commits into from
Dec 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
94efe86
Extract Video Short Description in YouTube.
FireMasterK Sep 22, 2021
d1add05
Add requested changes.
FireMasterK Oct 4, 2021
6231396
Add default implementation for getShortDescription.
FireMasterK Oct 4, 2021
1867a38
Bump spotbugs-annotations from 4.4.1 to 4.4.2
dependabot[bot] Oct 12, 2021
4e9d9bf
Merge pull request #738 from TeamNewPipe/dependabot/gradle/com.github…
TobiGr Oct 12, 2021
b425394
Merge pull request #731 from FireMasterK/short-description
TobiGr Oct 15, 2021
3e8e2a1
Add support for y2u.be links
triallax Oct 22, 2021
4f60225
Merge pull request #741 from mhmdanas/add-y2ube-link-support
litetex Oct 26, 2021
198d370
Bump gson from 2.8.8 to 2.8.9
dependabot[bot] Nov 1, 2021
599a91c
[PeerTube] Support /w/ short video links
B0pol Nov 3, 2021
e0b8e14
[PeerTube] Support /a/ and /c/ short links
B0pol Nov 3, 2021
0267516
[PeerTube] Support /w/p/ short playlist links
B0pol Nov 3, 2021
38ad1ea
[PeerTube] Support /w/ short video links part 2
B0pol Nov 3, 2021
396aece
Make sure playlists aren't accepted by PeertubeStreamLinkHandlerFactory
B0pol Nov 3, 2021
7e7b78f
Merge pull request #743 from B0pol/peertube-shortlinks
litetex Nov 4, 2021
cb80a64
Update hardcoded SoundCloud client_id
opusforlife2 Nov 4, 2021
8e4f999
Merge pull request #745 from TeamNewPipe/update_SC_hardcoded_client_id
B0pol Nov 4, 2021
68d7e4e
Merge pull request #742 from TeamNewPipe/dependabot/gradle/com.google…
TobiGr Nov 8, 2021
1e0c802
Bump spotbugs-annotations from 4.4.2 to 4.5.0
dependabot[bot] Nov 12, 2021
5028396
Improve names and formatting
TobiGr Nov 8, 2021
c4eca91
Fix YouTube likes + dislikes
B0pol Nov 19, 2021
56c8af7
Code refactoring
B0pol Nov 21, 2021
f6f2724
Merge pull request #753 from B0pol/dis-likes
litetex Nov 29, 2021
f735788
Fixed Soundcloud hardcoded client id
litetex Dec 8, 2021
3c669d3
Fixed YoutubeStreamExtractorAgeRestrictedTest
litetex Dec 8, 2021
652fdf2
Updated mock-data for YoutubeStreamExtractorAgeRestrictedTest
litetex Dec 8, 2021
7f99c1c
Fixed YoutubeStreamExtractorLivestreamTest
litetex Dec 8, 2021
f276bac
Fixed SoundcloudStreamExtractorTest
litetex Dec 8, 2021
75bb83a
Fixed YoutubeChannelExtractorTest
litetex Dec 8, 2021
5c288eb
Updated mock data for YoutubeChannelExtractorTest
litetex Dec 8, 2021
a3a0c1e
Fixed YoutubeCommentsExtractorTest
litetex Dec 8, 2021
d9b2a20
Updated mock data for YoutubeCommentsExtractorTest
litetex Dec 8, 2021
1e0c409
Merge pull request #760 from litetex/fix-test
TobiGr Dec 11, 2021
4dd737c
Updated version to v0.21.12
litetex Nov 30, 2021
795e6df
Update README.md
litetex Dec 11, 2021
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 @@ -11,7 +11,7 @@ NewPipe Extractor is available at JitPack's Maven repo.
If you're using Gradle, you could add NewPipe Extractor as a dependency with the following steps:

1. Add `maven { url 'https://jitpack.io' }` to the `repositories` in your `build.gradle`.
2. Add `implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.21.11'`the `dependencies` in your `build.gradle`. Replace `v0.21.11` with the latest release.
2. Add `implementation 'com.github.TeamNewPipe:NewPipeExtractor:INSERT_VERSION_HERE'` to the `dependencies` in your `build.gradle`. Replace `INSERT_VERSION_HERE` with the [latest release](https://github.com/TeamNewPipe/NewPipeExtractor/releases/latest).

**Note:** To use NewPipe Extractor in projects with a `minSdkVersion` below 26, [API desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) is required.

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8

version 'v0.21.11'
version 'v0.21.12'
group 'com.github.TeamNewPipe'

repositories {
Expand All @@ -28,7 +28,7 @@ allprojects {

ext {
nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751"
spotbugsVersion = "4.4.1"
spotbugsVersion = "4.5.0"
junitVersion = "4.13.2"
}
}
Expand Down
2 changes: 1 addition & 1 deletion extractor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies {

testImplementation "junit:junit:$junitVersion"
testImplementation "com.squareup.okhttp3:okhttp:3.12.13"
testImplementation 'com.google.code.gson:gson:2.8.8'
testImplementation 'com.google.code.gson:gson:2.8.9'
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public static CommentsInfo getInfo(final String url) throws IOException, Extract
return getInfo(NewPipe.getServiceByUrl(url), url);
}

public static CommentsInfo getInfo(final StreamingService serviceByUrl, final String url)
public static CommentsInfo getInfo(final StreamingService service, final String url)
throws ExtractionException, IOException {
return getInfo(serviceByUrl.getCommentsExtractor(url));
return getInfo(service.getCommentsExtractor(url));
}

public static CommentsInfo getInfo(final CommentsExtractor commentsExtractor)
Expand Down Expand Up @@ -63,7 +63,7 @@ public static InfoItemsPage<CommentsInfoItem> getMoreItems(
final StreamingService service,
final CommentsInfo commentsInfo,
final Page page) throws IOException, ExtractionException {
if (null == commentsInfo.getCommentsExtractor()) {
if (commentsInfo.getCommentsExtractor() == null) {
commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl()));
commentsInfo.getCommentsExtractor().fetchPage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory {

private static final PeertubeChannelLinkHandlerFactory instance = new PeertubeChannelLinkHandlerFactory();
private static final String ID_PATTERN = "(accounts|video-channels)/([^/?&#]*)";
private static final String ID_PATTERN = "((accounts|a)|(video-channels|c))/([^/?&#]*)";
public static final String API_ENDPOINT = "/api/v1/";

public static PeertubeChannelLinkHandlerFactory getInstance() {
Expand All @@ -19,7 +19,7 @@ public static PeertubeChannelLinkHandlerFactory getInstance() {

@Override
public String getId(String url) throws ParsingException {
return Parser.matchGroup(ID_PATTERN, url, 0);
return fixId(Parser.matchGroup(ID_PATTERN, url, 0));
}

@Override
Expand All @@ -31,7 +31,7 @@ public String getUrl(String id, List<String> contentFilters, String searchFilter
public String getUrl(String id, List<String> contentFilter, String sortFilter, String baseUrl)
throws ParsingException {
if (id.matches(ID_PATTERN)) {
return baseUrl + "/" + id;
return baseUrl + "/" + fixId(id);
} else {
// This is needed for compatibility with older versions were we didn't support video channels yet
return baseUrl + "/accounts/" + id;
Expand All @@ -40,6 +40,28 @@ public String getUrl(String id, List<String> contentFilter, String sortFilter, S

@Override
public boolean onAcceptUrl(String url) {
return url.contains("/accounts/") || url.contains("/video-channels/");
return url.contains("/accounts/") || url.contains("/a/")
|| url.contains("/video-channels/") || url.contains("/c/");
}

/**
* Fix id
*
* <p>
* a/:accountName and c/:channelName ids are supported
* by the PeerTube web client (>= v3.3.0)
* but not by the API.
* </p>
*
* @param id the id to fix
* @return the fixed id
*/
private String fixId(String id) {
if (id.startsWith("a/")) {
id = "accounts" + id.substring(1);
} else if (id.startsWith("c/")) {
id = "video-channels" + id.substring(1);
}
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory {

private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory();
private static final String ID_PATTERN = "/videos/(watch/)?([^/?&#]*)";
private static final String COMMENTS_ENDPOINT = "/api/v1/videos/%s/comment-threads";

public static PeertubeCommentsLinkHandlerFactory getInstance() {
Expand All @@ -20,12 +19,12 @@ public static PeertubeCommentsLinkHandlerFactory getInstance() {

@Override
public String getId(String url) throws ParsingException, IllegalArgumentException {
return Parser.matchGroup(ID_PATTERN, url, 2);
return PeertubeStreamLinkHandlerFactory.getInstance().getId(url); // the same id is needed
}

@Override
public boolean onAcceptUrl(final String url) throws FoundAdException {
return url.contains("/videos/");
return url.contains("/videos/") || url.contains("/w/");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory {

private static final PeertubePlaylistLinkHandlerFactory instance = new PeertubePlaylistLinkHandlerFactory();
private static final String ID_PATTERN = "/videos/watch/playlist/([^/?&#]*)";
private static final String ID_PATTERN = "(/videos/watch/playlist/|/w/p/)([^/?&#]*)";

public static PeertubePlaylistLinkHandlerFactory getInstance() {
return instance;
Expand All @@ -30,7 +30,7 @@ public String getUrl(String id, List<String> contentFilters, String sortFilter,

@Override
public String getId(String url) throws ParsingException {
return Parser.matchGroup1(ID_PATTERN, url);
return Parser.matchGroup(ID_PATTERN, url, 2);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {

private static final PeertubeStreamLinkHandlerFactory instance = new PeertubeStreamLinkHandlerFactory();
private static final String ID_PATTERN = "/videos/(watch/|embed/)?([^/?&#]*)";
private static final String ID_PATTERN = "(/w/|(/videos/(watch/|embed/)?))(?!p/)([^/?&#]*)";
// we exclude p/ because /w/p/ is playlist, not video
public static final String VIDEO_API_ENDPOINT = "/api/v1/videos/";

// From PeerTube 3.3.0, the default path is /w/.
// We still use /videos/watch/ for compatibility reasons:
// /videos/watch/ is still accepted by >=3.3.0 but /w/ isn't by <3.3.0
private static final String VIDEO_PATH = "/videos/watch/";

private PeertubeStreamLinkHandlerFactory() {
Expand All @@ -32,7 +37,7 @@ public String getUrl(String id, String baseUrl) {

@Override
public String getId(String url) throws ParsingException, IllegalArgumentException {
return Parser.matchGroup(ID_PATTERN, url, 2);
return Parser.matchGroup(ID_PATTERN, url, 4);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import static org.schabi.newpipe.extractor.utils.Utils.*;

public class SoundcloudParsingHelper {
private static final String HARDCODED_CLIENT_ID =
"yoxLvaFlJ3V5LbNCt53Cwvw5KXKKxWfn"; // Updated on 01/10/21
static final String HARDCODED_CLIENT_ID =
"1NKODbzHzEpoowFHxTAmS7oB08DObPuK"; // Updated on 08/12/21
private static String clientId;
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public static boolean isInvidioURL(@Nonnull final URL url) {
|| host.equalsIgnoreCase("y.com.cm");
}

public static boolean isY2ubeURL(@Nonnull final URL url) {
return url.getHost().equalsIgnoreCase("y2u.be");
}

/**
* Parses the duration string of the video expecting ":" or "." as separators
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,33 @@ public long getViewCount() throws ParsingException {
@Override
public long getLikeCount() throws ParsingException {
assertPageFetched();
String likesString = "";
String likesString = null;
try {
try {
likesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
.getObject("sentimentBarRenderer").getString("tooltip").split("/")[0];
} catch (final NullPointerException e) {
likesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
.getObject("sentimentBarRenderer").getString("tooltip");
if (likesString != null && likesString.contains("/")) {
likesString = likesString.split("/")[0];
} else {
likesString = getVideoPrimaryInfoRenderer()
.getObject("videoActions")
.getObject("menuRenderer")
.getArray("topLevelButtons")
.getObject(0)
.getObject("toggleButtonRenderer")
.getObject("defaultText")
.getObject("accessibility")
.getObject("accessibilityData")
.getString("label");
}

if (likesString == null) {
// If this kicks in our button has no content and therefore ratings must be disabled
if (playerResponse.getObject("videoDetails").getBoolean("allowRatings")) {
throw new ParsingException(
"Ratings are enabled even though the like button is missing", e);
throw new ParsingException("Ratings are enabled even though the like button is missing");
}
return -1;
}

return Integer.parseInt(Utils.removeNonDigitCharacters(likesString));
} catch (final NumberFormatException nfe) {
throw new ParsingException("Could not parse \"" + likesString + "\" as an Integer",
Expand All @@ -366,29 +380,28 @@ public long getLikeCount() throws ParsingException {
public long getDislikeCount() throws ParsingException {
assertPageFetched();

String dislikesString = "";
try {
try {
dislikesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
.getObject("sentimentBarRenderer").getString("tooltip").split("/")[1];
} catch (final NullPointerException e) {
// If this kicks in our button has no content and therefore ratings must be disabled
if (playerResponse.getObject("videoDetails").getBoolean("allowRatings")) {
throw new ParsingException(
"Ratings are enabled even though the dislike button is missing", e);
String dislikesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar")
.getObject("sentimentBarRenderer").getString("tooltip");
if (dislikesString != null && dislikesString.contains("/")) {
dislikesString = dislikesString.split("/")[1];
return Integer.parseInt(Utils.removeNonDigitCharacters(dislikesString));
} else {
// Calculate dislike with average rating and like count
long likes = getLikeCount();
double averageRating = playerResponse.getObject("videoDetails").getDouble("averageRating");

if (likes != -1 && averageRating > 1) {
// If averageRating can't be gathered, it will be 0,
// but we also can't divide by 0 so we need > 1
return Math.round(likes * ((5 - averageRating) / (averageRating - 1)));
}
return -1;
}
return Integer.parseInt(Utils.removeNonDigitCharacters(dislikesString));
} catch (final NumberFormatException nfe) {
throw new ParsingException("Could not parse \"" + dislikesString + "\" as an Integer",
nfe);
} catch (final Exception e) {
if (getAgeLimit() == NO_AGE_LIMIT) {
throw new ParsingException("Could not get dislike count", e);
}
return -1;
}
// Silently fail as YouTube is "gradually rolling out" removing dislike count
// https://blog.youtube/news-and-events/update-to-youtube/
return -1;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,19 @@ private OffsetDateTime getDateFromPremiere() throws ParsingException {
throw new ParsingException("Could not parse date from premiere: \"" + startTime + "\"");
}
}

@Nullable
@Override
public String getShortDescription() throws ParsingException {

if (videoInfo.has("detailedMetadataSnippets")) {
return getTextFromObject(videoInfo.getArray("detailedMetadataSnippets").getObject(0).getObject("snippetText"));
}

if (videoInfo.has("descriptionSnippet")) {
return getTextFromObject(videoInfo.getObject("descriptionSnippet"));
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx

if (!Utils.isHTTP(url) || !(YoutubeParsingHelper.isYoutubeURL(url) ||
YoutubeParsingHelper.isYoutubeServiceURL(url) || YoutubeParsingHelper.isHooktubeURL(url) ||
YoutubeParsingHelper.isInvidioURL(url))) {
YoutubeParsingHelper.isInvidioURL(url) || YoutubeParsingHelper.isY2ubeURL(url))) {
if (host.equalsIgnoreCase("googleads.g.doubleclick.net")) {
throw new FoundAdException("Error found ad: " + urlString);
}
Expand Down Expand Up @@ -160,6 +160,7 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx
return assertIsId(viewQueryValue);
}

case "Y2U.BE":
case "YOUTU.BE": {
String viewQueryValue = Utils.getQueryValue(url, "v");
if (viewQueryValue != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class StreamInfoItem extends InfoItem {
private final StreamType streamType;

private String uploaderName;
private String shortDescription;
private String textualUploadDate;
@Nullable
private DateWrapper uploadDate;
Expand Down Expand Up @@ -92,6 +93,14 @@ public void setUploaderAvatarUrl(final String uploaderAvatarUrl) {
this.uploaderAvatarUrl = uploaderAvatarUrl;
}

public String getShortDescription() {
return shortDescription;
}

public void setShortDescription(final String shortDescription) {
this.shortDescription = shortDescription;
}

@Nullable
public String getTextualUploadDate() {
return textualUploadDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ public interface StreamInfoItemExtractor extends InfoItemExtractor {
@Nullable
DateWrapper getUploadDate() throws ParsingException;


/**
* Get the video's short description.
*
* @return The video's short description or {@code null} if not provided by the service.
* @throws ParsingException if there is an error in the extraction
*/
@Nullable
default String getShortDescription() throws ParsingException { return null; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public StreamInfoItem extract(StreamInfoItemExtractor extractor) throws ParsingE
} catch (Exception e) {
addError(e);
}
try {
resultItem.setShortDescription(extractor.getShortDescription());
} catch (Exception e) {
addError(e);
}

return resultItem;
}
Expand Down
Loading