3434
3535public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor {
3636 private final JsonObject channelInfoItem ;
37+ /**
38+ * New layout:
39+ * "subscriberCountText": Channel handle
40+ * "videoCountText": Subscriber count
41+ */
42+ private final boolean withHandle ;
3743
3844 public YoutubeChannelInfoItemExtractor (final JsonObject channelInfoItem ) {
3945 this .channelInfoItem = channelInfoItem ;
46+
47+ boolean wHandle = false ;
48+ try {
49+ final String subscriberCountText = getTextFromObject (
50+ channelInfoItem .getObject ("subscriberCountText" ));
51+ if (subscriberCountText != null ) {
52+ wHandle = subscriberCountText .startsWith ("@" );
53+ }
54+ } catch (final ParsingException ignored ) {
55+ }
56+ this .withHandle = wHandle ;
4057 }
4158
4259 @ Override
@@ -78,6 +95,11 @@ public long getSubscriberCount() throws ParsingException {
7895 return -1 ;
7996 }
8097
98+ if (withHandle ) {
99+ return Utils .mixedNumberWordToLong (getTextFromObject (
100+ channelInfoItem .getObject ("videoCountText" )));
101+ }
102+
81103 return Utils .mixedNumberWordToLong (getTextFromObject (
82104 channelInfoItem .getObject ("subscriberCountText" )));
83105 } catch (final Exception e ) {
@@ -88,8 +110,9 @@ public long getSubscriberCount() throws ParsingException {
88110 @ Override
89111 public long getStreamCount () throws ParsingException {
90112 try {
91- if (!channelInfoItem .has ("videoCountText" )) {
92- // Video count is not available, channel probably has no public uploads.
113+ if (withHandle || !channelInfoItem .has ("videoCountText" )) {
114+ // Video count is not available, either the channel has no public uploads
115+ // or YouTube displays the channel handle instead.
93116 return ListExtractor .ITEM_COUNT_UNKNOWN ;
94117 }
95118
0 commit comments