-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #946 from chowder/dev
Add ability to identify short-form `StreamInfoItem`s
- Loading branch information
Showing
11 changed files
with
1,591 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
package org.schabi.newpipe.extractor.services.youtube.extractors; | ||
|
||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailUrlFromInfoItem; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint; | ||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||
|
||
import com.grack.nanojson.JsonArray; | ||
import com.grack.nanojson.JsonObject; | ||
|
||
import org.schabi.newpipe.extractor.exceptions.ParsingException; | ||
import org.schabi.newpipe.extractor.localization.DateWrapper; | ||
import org.schabi.newpipe.extractor.localization.TimeAgoParser; | ||
|
@@ -18,12 +12,16 @@ | |
import org.schabi.newpipe.extractor.utils.JsonUtils; | ||
import org.schabi.newpipe.extractor.utils.Utils; | ||
|
||
import javax.annotation.Nullable; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import javax.annotation.Nullable; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailUrlFromInfoItem; | ||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint; | ||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; | ||
|
||
/* | ||
* Copyright (C) Christian Schabesberger 2016 <[email protected]> | ||
|
@@ -324,4 +322,46 @@ public String getShortDescription() throws ParsingException { | |
|
||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isShortFormContent() throws ParsingException { | ||
try { | ||
final String webPageType = videoInfo.getObject("navigationEndpoint") | ||
.getObject("commandMetadata").getObject("webCommandMetadata") | ||
.getString("webPageType"); | ||
|
||
boolean isShort = !isNullOrEmpty(webPageType) | ||
&& webPageType.equals("WEB_PAGE_TYPE_SHORTS"); | ||
|
||
if (!isShort) { | ||
isShort = videoInfo.getObject("navigationEndpoint").has("reelWatchEndpoint"); | ||
} | ||
|
||
if (!isShort) { | ||
final JsonObject thumbnailTimeOverlay = videoInfo.getArray("thumbnailOverlays") | ||
.stream() | ||
.filter(JsonObject.class::isInstance) | ||
.map(JsonObject.class::cast) | ||
.filter(thumbnailOverlay -> thumbnailOverlay.has( | ||
"thumbnailOverlayTimeStatusRenderer")) | ||
.map(thumbnailOverlay -> thumbnailOverlay.getObject( | ||
"thumbnailOverlayTimeStatusRenderer")) | ||
.findFirst() | ||
.orElse(null); | ||
|
||
if (!isNullOrEmpty(thumbnailTimeOverlay)) { | ||
isShort = thumbnailTimeOverlay.getString("style", "") | ||
.equalsIgnoreCase("SHORTS") | ||
|| thumbnailTimeOverlay.getObject("icon") | ||
.getString("iconType", "") | ||
.toLowerCase() | ||
.contains("shorts"); | ||
} | ||
} | ||
|
||
return isShort; | ||
} catch (final Exception e) { | ||
throw new ParsingException("Could not determine if this is short-form content", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...g/schabi/newpipe/extractor/services/youtube/extractor/search/shorts/generated_mock_0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"request": { | ||
"httpMethod": "GET", | ||
"url": "https://www.youtube.com/sw.js", | ||
"headers": { | ||
"Origin": [ | ||
"https://www.youtube.com" | ||
], | ||
"Referer": [ | ||
"https://www.youtube.com" | ||
], | ||
"Accept-Language": [ | ||
"en-GB, en;q\u003d0.9" | ||
] | ||
}, | ||
"localization": { | ||
"languageCode": "en", | ||
"countryCode": "GB" | ||
} | ||
}, | ||
"response": { | ||
"responseCode": 200, | ||
"responseMessage": "", | ||
"responseHeaders": { | ||
"access-control-allow-credentials": [ | ||
"true" | ||
], | ||
"access-control-allow-origin": [ | ||
"https://www.youtube.com" | ||
], | ||
"alt-svc": [ | ||
"h3\u003d\":443\"; ma\u003d2592000,h3-29\u003d\":443\"; ma\u003d2592000,h3-Q050\u003d\":443\"; ma\u003d2592000,h3-Q046\u003d\":443\"; ma\u003d2592000,h3-Q043\u003d\":443\"; ma\u003d2592000,quic\u003d\":443\"; ma\u003d2592000; v\u003d\"46,43\"" | ||
], | ||
"cache-control": [ | ||
"private, max-age\u003d0" | ||
], | ||
"content-type": [ | ||
"text/javascript; charset\u003dutf-8" | ||
], | ||
"cross-origin-opener-policy-report-only": [ | ||
"same-origin; report-to\u003d\"youtube_main\"" | ||
], | ||
"date": [ | ||
"Tue, 18 Oct 2022 22:13:02 GMT" | ||
], | ||
"expires": [ | ||
"Tue, 18 Oct 2022 22:13:02 GMT" | ||
], | ||
"p3p": [ | ||
"CP\u003d\"This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl\u003den-GB for more info.\"" | ||
], | ||
"permissions-policy": [ | ||
"ch-ua-arch\u003d*, ch-ua-bitness\u003d*, ch-ua-full-version\u003d*, ch-ua-full-version-list\u003d*, ch-ua-model\u003d*, ch-ua-wow64\u003d*, ch-ua-platform\u003d*, ch-ua-platform-version\u003d*" | ||
], | ||
"report-to": [ | ||
"{\"group\":\"youtube_main\",\"max_age\":2592000,\"endpoints\":[{\"url\":\"https://csp.withgoogle.com/csp/report-to/youtube_main\"}]}" | ||
], | ||
"server": [ | ||
"ESF" | ||
], | ||
"set-cookie": [ | ||
"YSC\u003dtvxMn34iTRM; Domain\u003d.youtube.com; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone", | ||
"VISITOR_INFO1_LIVE\u003d; Domain\u003d.youtube.com; Expires\u003dWed, 22-Jan-2020 22:13:02 GMT; Path\u003d/; Secure; HttpOnly; SameSite\u003dnone", | ||
"CONSENT\u003dPENDING+265; expires\u003dThu, 17-Oct-2024 22:13:02 GMT; path\u003d/; domain\u003d.youtube.com; Secure" | ||
], | ||
"strict-transport-security": [ | ||
"max-age\u003d31536000" | ||
], | ||
"x-content-type-options": [ | ||
"nosniff" | ||
], | ||
"x-frame-options": [ | ||
"SAMEORIGIN" | ||
], | ||
"x-xss-protection": [ | ||
"0" | ||
] | ||
}, | ||
"responseBody": "\n self.addEventListener(\u0027install\u0027, event \u003d\u003e {\n event.waitUntil(self.skipWaiting());\n });\n self.addEventListener(\u0027activate\u0027, event \u003d\u003e {\n event.waitUntil(\n self.clients.claim().then(() \u003d\u003e self.registration.unregister()));\n });\n ", | ||
"latestUrl": "https://www.youtube.com/sw.js" | ||
} | ||
} |
Oops, something went wrong.