Merge pull request #857 from FireMasterK/video-title

Get original untranslated title for YouTube
This commit is contained in:
Stypox 2022-07-06 10:26:45 +02:00 committed by GitHub
commit 5ab74b3631
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -162,17 +162,18 @@ public class YoutubeStreamExtractor extends StreamExtractor {
@Override @Override
public String getName() throws ParsingException { public String getName() throws ParsingException {
assertPageFetched(); assertPageFetched();
String title = null; String title;
// Try to get the video's original title, which is untranslated
title = playerResponse.getObject("videoDetails").getString("title");
if (isNullOrEmpty(title)) {
try { try {
title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title")); title = getTextFromObject(getVideoPrimaryInfoRenderer().getObject("title"));
} catch (final ParsingException ignored) { } catch (final ParsingException ignored) {
// Age-restricted videos cause a ParsingException here // Age-restricted videos cause a ParsingException here
} }
if (isNullOrEmpty(title)) {
title = playerResponse.getObject("videoDetails").getString("title");
if (isNullOrEmpty(title)) { if (isNullOrEmpty(title)) {
throw new ParsingException("Could not get name"); throw new ParsingException("Could not get name");
} }