Skip to content

Commit 8d88093

Browse files
committed
Fix getRealIdFromShared occasionally failing
1 parent c4f521f commit 8d88093

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamUrlIdHandler.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

3+
import org.jsoup.Jsoup;
4+
import org.jsoup.nodes.Document;
5+
import org.jsoup.nodes.Element;
36
import org.schabi.newpipe.extractor.Downloader;
47
import org.schabi.newpipe.extractor.NewPipe;
58
import org.schabi.newpipe.extractor.UrlIdHandler;
@@ -125,8 +128,18 @@ private String getRealIdFromSharedLink(String url) throws ParsingException {
125128
} catch (IOException | ReCaptchaException e) {
126129
throw new ParsingException("Unable to resolve shared link", e);
127130
}
128-
// is this bad? is this fragile?:
129-
String realId = Parser.matchGroup1("rel=\"shortlink\" href=\"https://youtu.be/" + ID_PATTERN, content);
131+
Document document = Jsoup.parse(content);
132+
String urlWithRealId;
133+
134+
Element element = document.select("link[rel=\"canonical\"]").first();
135+
if (element != null) {
136+
urlWithRealId = element.attr("abs:href");
137+
} else {
138+
urlWithRealId = document.select("meta[property=\"og:url\"]").first()
139+
.attr("abs:content");
140+
}
141+
142+
String realId = Parser.matchGroup1(ID_PATTERN, urlWithRealId);
130143
if (sharedId.equals(realId)) {
131144
throw new ParsingException("Got same id for as shared info_id: " + sharedId);
132145
}

0 commit comments

Comments
 (0)