NewPipeExtractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelInfo.java

146 lines
4.4 KiB
Java
Raw Normal View History

2017-08-11 03:23:09 +02:00
package org.schabi.newpipe.extractor.channel;
2017-03-01 18:47:52 +01:00
2018-02-24 22:20:50 +01:00
import org.schabi.newpipe.extractor.ListExtractor.InfoItemPage;
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2017-03-01 18:47:52 +01:00
import org.schabi.newpipe.extractor.exceptions.ParsingException;
2017-11-11 02:55:56 +01:00
import org.schabi.newpipe.extractor.utils.ExtractorHelper;
2017-03-01 18:47:52 +01:00
2017-08-06 22:20:15 +02:00
import java.io.IOException;
2017-03-01 18:47:52 +01:00
/*
2017-03-01 18:47:52 +01:00
* Created by Christian Schabesberger on 31.07.16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
2017-08-11 03:23:09 +02:00
* ChannelInfo.java is part of NewPipe.
2017-03-01 18:47:52 +01:00
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
2017-08-11 03:23:09 +02:00
public class ChannelInfo extends ListInfo {
2017-08-06 22:20:15 +02:00
2017-11-11 02:55:56 +01:00
public ChannelInfo(int serviceId, String url, String id, String name) {
super(serviceId, id, url, name);
}
2018-02-24 22:20:50 +01:00
public static InfoItemPage getMoreItems(StreamingService service, String url, String nextPageUrl)
throws IOException, ExtractionException {
return service.getChannelExtractor(url, nextPageUrl).getInfoItemPage();
2017-08-06 22:20:15 +02:00
}
2017-08-11 03:23:09 +02:00
public static ChannelInfo getInfo(String url) throws IOException, ExtractionException {
2017-08-06 22:20:15 +02:00
return getInfo(NewPipe.getServiceByUrl(url), url);
}
2017-08-11 03:23:09 +02:00
public static ChannelInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
2017-12-29 14:40:42 +01:00
ChannelExtractor extractor = service.getChannelExtractor(url);
extractor.fetchPage();
2017-12-30 01:13:24 +01:00
return getInfo(extractor);
2017-08-06 22:20:15 +02:00
}
2017-03-01 18:47:52 +01:00
2017-08-11 03:23:09 +02:00
public static ChannelInfo getInfo(ChannelExtractor extractor) throws ParsingException {
2017-03-01 18:47:52 +01:00
2017-06-29 19:34:21 +02:00
// important data
2017-11-11 02:55:56 +01:00
int serviceId = extractor.getServiceId();
String url = extractor.getCleanUrl();
String id = extractor.getId();
String name = extractor.getName();
ChannelInfo info = new ChannelInfo(serviceId, url, id, name);
2017-03-01 18:47:52 +01:00
try {
2017-11-11 02:55:56 +01:00
info.setAvatarUrl(extractor.getAvatarUrl());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
2017-11-11 02:55:56 +01:00
info.addError(e);
2017-03-01 18:47:52 +01:00
}
try {
2017-11-11 02:55:56 +01:00
info.setBannerUrl(extractor.getBannerUrl());
} catch (Exception e) {
2017-11-11 02:55:56 +01:00
info.addError(e);
2017-03-01 18:47:52 +01:00
}
try {
2017-11-11 02:55:56 +01:00
info.setFeedUrl(extractor.getFeedUrl());
} catch (Exception e) {
2017-11-11 02:55:56 +01:00
info.addError(e);
2017-03-01 18:47:52 +01:00
}
2017-11-11 02:55:56 +01:00
2018-02-24 22:20:50 +01:00
info.setRelatedStreams(ExtractorHelper.getInfoItemsOrLogError(info, extractor));
2017-11-11 02:55:56 +01:00
2017-03-01 18:47:52 +01:00
try {
2017-11-11 02:55:56 +01:00
info.setSubscriberCount(extractor.getSubscriberCount());
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
2017-11-11 02:55:56 +01:00
info.addError(e);
2017-03-01 18:47:52 +01:00
}
try {
2017-11-11 02:55:56 +01:00
info.setDescription(extractor.getDescription());
} catch (Exception e) {
2017-11-11 02:55:56 +01:00
info.addError(e);
}
2017-03-01 18:47:52 +01:00
2018-02-24 22:20:50 +01:00
info.setHasMoreStreams(extractor.hasNextPage());
info.setNextStreamsUrl(extractor.getNextPageUrl());
2017-03-01 18:47:52 +01:00
return info;
}
public String avatar_url;
public String banner_url;
public String feed_url;
public long subscriber_count = -1;
2017-08-11 20:21:49 +02:00
public String description;
2017-11-11 02:55:56 +01:00
public String getAvatarUrl() {
return avatar_url;
}
public void setAvatarUrl(String avatarUrl) {
this.avatar_url = avatarUrl;
}
public String getBannerUrl() {
return banner_url;
}
public void setBannerUrl(String bannerUrl) {
this.banner_url = bannerUrl;
}
public String getFeedUrl() {
return feed_url;
}
public void setFeedUrl(String feedUrl) {
this.feed_url = feedUrl;
}
public long getSubscriberCount() {
return subscriber_count;
}
public void setSubscriberCount(long subscriberCount) {
this.subscriber_count = subscriberCount;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
2017-03-01 18:47:52 +01:00
}