导航菜单

页面标题

页面副标题

Kreate v1.5.0 - SoundcloudSubscriptionExtractor.java 源代码

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

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


package org.schabi.newpipe.extractor.services.soundcloud.extractors;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudService;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionItem;
import org.schabi.newpipe.extractor.utils.Utils;

public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor {
    public SoundcloudSubscriptionExtractor(SoundcloudService soundcloudService) {
        super(soundcloudService, Collections.singletonList(SubscriptionExtractor.ContentSource.CHANNEL_URL));
    }

    @Override
    public String getRelatedUrl() {
        return "https://soundcloud.com/you";
    }

    @Override
    public List<SubscriptionItem> fromChannelUrl(String str) throws IOException, ExtractionException {
        if (str == null) {
            throw new SubscriptionExtractor.InvalidSourceException("Channel url is null");
        }
        try {
            String id = this.service.getChannelLHFactory().fromUrl(getUrlFrom(str)).getId();
            String str2 = "https://api-v2.soundcloud.com/users/" + id + "/followings?client_id=" + SoundcloudParsingHelper.clientId() + "&limit=200";
            ChannelInfoItemsCollector channelInfoItemsCollector = new ChannelInfoItemsCollector(this.service.getServiceId());
            SoundcloudParsingHelper.getUsersFromApiMinItems(2500, channelInfoItemsCollector, str2);
            return toSubscriptionItems(channelInfoItemsCollector.getItems());
        } catch (ExtractionException e) {
            throw new SubscriptionExtractor.InvalidSourceException(e);
        }
    }

    private String getUrlFrom(String str) {
        String replaceHttpWithHttps = Utils.replaceHttpWithHttps(str);
        if (replaceHttpWithHttps.startsWith(Utils.HTTPS)) {
            return str;
        }
        if (!replaceHttpWithHttps.contains("soundcloud.com/")) {
            return "https://soundcloud.com/" + replaceHttpWithHttps;
        }
        return Utils.HTTPS + replaceHttpWithHttps;
    }

    private List<SubscriptionItem> toSubscriptionItems(List<ChannelInfoItem> list) {
        ArrayList arrayList = new ArrayList(list.size());
        for (ChannelInfoItem channelInfoItem : list) {
            arrayList.add(new SubscriptionItem(channelInfoItem.getServiceId(), channelInfoItem.getUrl(), channelInfoItem.getName()));
        }
        return arrayList;
    }
}