File tree Expand file tree Collapse file tree
src/main/java/org/schabi/newpipe/extractor/services/youtube Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package org .schabi .newpipe .extractor .services .youtube ;
22
3+ import org .jsoup .Jsoup ;
4+ import org .jsoup .nodes .Document ;
5+ import org .jsoup .nodes .Element ;
36import org .schabi .newpipe .extractor .Downloader ;
47import org .schabi .newpipe .extractor .NewPipe ;
58import 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 }
You can’t perform that action at this time.
0 commit comments