NewPipeExtractor/src/main/java/org/schabi/newpipe/extractor/user/UserInfo.java

107 lines
3.9 KiB
Java
Raw Normal View History

2017-08-07 18:12:51 +02:00
package org.schabi.newpipe.extractor.user;
2017-03-01 18:47:52 +01:00
2017-08-06 22:20:15 +02:00
import org.schabi.newpipe.extractor.ListExtractor.NextItemsResult;
import org.schabi.newpipe.extractor.ListInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.ServiceList;
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;
import org.schabi.newpipe.extractor.stream.StreamInfoItemCollector;
2017-03-01 18:47:52 +01:00
2017-08-06 22:20:15 +02:00
import java.io.IOException;
import java.util.ArrayList;
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-07 18:12:51 +02:00
* UserInfo.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-07 18:12:51 +02:00
public class UserInfo extends ListInfo {
2017-08-06 22:20:15 +02:00
public static NextItemsResult getMoreItems(ServiceList serviceItem, String nextStreamsUrl) throws IOException, ExtractionException {
return getMoreItems(serviceItem.getService(), nextStreamsUrl);
}
public static NextItemsResult getMoreItems(StreamingService service, String nextStreamsUrl) throws IOException, ExtractionException {
2017-08-07 18:12:51 +02:00
return service.getUserExtractor(null, nextStreamsUrl).getNextStreams();
2017-08-06 22:20:15 +02:00
}
2017-08-07 18:12:51 +02:00
public static UserInfo getInfo(String url) throws IOException, ExtractionException {
2017-08-06 22:20:15 +02:00
return getInfo(NewPipe.getServiceByUrl(url), url);
}
2017-08-07 18:12:51 +02:00
public static UserInfo getInfo(ServiceList serviceItem, String url) throws IOException, ExtractionException {
2017-08-06 22:20:15 +02:00
return getInfo(serviceItem.getService(), url);
}
2017-08-07 18:12:51 +02:00
public static UserInfo getInfo(StreamingService service, String url) throws IOException, ExtractionException {
return getInfo(service.getUserExtractor(url));
2017-08-06 22:20:15 +02:00
}
2017-03-01 18:47:52 +01:00
2017-08-07 18:12:51 +02:00
public static UserInfo getInfo(UserExtractor extractor) throws ParsingException {
UserInfo info = new UserInfo();
2017-03-01 18:47:52 +01:00
2017-06-29 19:34:21 +02:00
// important data
2017-03-01 18:47:52 +01:00
info.service_id = extractor.getServiceId();
2017-08-06 22:20:15 +02:00
info.url = extractor.getCleanUrl();
2017-08-07 18:12:51 +02:00
info.id = extractor.getUserId();
info.name = extractor.getUserName();
2017-03-01 18:47:52 +01:00
try {
info.avatar_url = extractor.getAvatarUrl();
} catch (Exception e) {
info.errors.add(e);
}
try {
info.banner_url = extractor.getBannerUrl();
} catch (Exception e) {
info.errors.add(e);
}
try {
info.feed_url = extractor.getFeedUrl();
} catch (Exception e) {
2017-03-01 18:47:52 +01:00
info.errors.add(e);
}
try {
StreamInfoItemCollector c = extractor.getStreams();
info.related_streams = c.getItemList();
info.errors.addAll(c.getErrors());
} catch (Exception e) {
2017-03-01 18:47:52 +01:00
info.errors.add(e);
}
try {
info.subscriber_count = extractor.getSubscriberCount();
2017-03-01 18:47:52 +01:00
} catch (Exception e) {
info.errors.add(e);
}
2017-08-06 22:20:15 +02:00
// Lists can be null if a exception was thrown during extraction
if (info.related_streams == null) info.related_streams = new ArrayList<>();
info.has_more_streams = extractor.hasMoreStreams();
info.next_streams_url = extractor.getNextStreamsUrl();
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-03-01 18:47:52 +01:00
}