导航菜单

页面标题

页面副标题

Kreate v1.5.0 - PeertubeInstance.java 源代码

正在查看: Kreate v1.5.0 应用的 PeertubeInstance.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package org.schabi.newpipe.extractor.services.peertube;

import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;
import java.io.IOException;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils;

public class PeertubeInstance {
    public static final PeertubeInstance DEFAULT_INSTANCE = new PeertubeInstance("https://framatube.org", "FramaTube");
    private String name;
    private final String url;

    public PeertubeInstance(String str) {
        this.url = str;
        this.name = "PeerTube";
    }

    public PeertubeInstance(String str, String str2) {
        this.url = str;
        this.name = str2;
    }

    public String getUrl() {
        return this.url;
    }

    public void fetchInstanceMetaData() throws Exception {
        try {
            Response response = NewPipe.getDownloader().get(this.url + "/api/v1/config");
            if (response == null || Utils.isBlank(response.responseBody())) {
                throw new Exception("unable to configure instance " + this.url);
            }
            try {
                this.name = JsonUtils.getString((JsonObject) JsonParser.object().from(response.responseBody()), "instance.name");
            } catch (ParsingException | JsonParserException e) {
                throw new Exception("unable to parse instance config", e);
            }
        } catch (IOException | ReCaptchaException e2) {
            throw new Exception("unable to configure instance " + this.url, e2);
        }
    }

    public String getName() {
        return this.name;
    }
}