File tree Expand file tree Collapse file tree
extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4747
4848@ SuppressWarnings ("WeakerAccess" )
4949public class YoutubeChannelExtractor extends ChannelExtractor {
50+ /*package-private*/ static final String CHANNEL_URL_BASE = "https://www.youtube.com/channel/" ;
5051 private static final String CHANNEL_FEED_BASE = "https://www.youtube.com/feeds/videos.xml?channel_id=" ;
5152 private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000" ;
5253
@@ -72,7 +73,7 @@ public String getNextPageUrl() throws ExtractionException {
7273 @ Override
7374 public String getUrl () throws ParsingException {
7475 try {
75- return "https://www.youtube.com/channel/" + getId ();
76+ return CHANNEL_URL_BASE + getId ();
7677 } catch (ParsingException e ) {
7778 return super .getUrl ();
7879 }
Original file line number Diff line number Diff line change 55import org .schabi .newpipe .extractor .exceptions .ParsingException ;
66import org .schabi .newpipe .extractor .utils .Utils ;
77
8+ import java .util .regex .Matcher ;
9+ import java .util .regex .Pattern ;
10+
811/*
912 * Created by Christian Schabesberger on 12.02.17.
1013 *
@@ -53,8 +56,20 @@ public String getName() throws ParsingException {
5356
5457 @ Override
5558 public String getUrl () throws ParsingException {
56- return el .select ("a[class*=\" yt-uix-tile-link\" ]" ).first ()
57- .attr ("abs:href" );
59+ String buttonTrackingUrl = el .select ("button[class*=\" yt-uix-button\" ]" ).first ()
60+ .attr ("abs:data-href" );
61+
62+ Pattern channelIdPattern = Pattern .compile ("(?:.*?)\\ %252Fchannel\\ %252F(.+?)\\ %26(?:.*)" );
63+ Matcher match = channelIdPattern .matcher (buttonTrackingUrl );
64+
65+ if (match .matches ()) {
66+ return YoutubeChannelExtractor .CHANNEL_URL_BASE + match .group (1 );
67+ } else {
68+ // fallback method just in case youtube changes things; it should never run and tests will fail
69+ // provides an url with "/user/NAME", that is inconsistent with stream and channel extractor
70+ return el .select ("a[class*=\" yt-uix-tile-link\" ]" ).first ()
71+ .attr ("abs:href" );
72+ }
5873 }
5974
6075 @ Override
You can’t perform that action at this time.
0 commit comments