CrawlStrategy.java 2.39 KB
package cn.fw.freya.service.crawl;

import cn.fw.freya.enums.AccountTypeEnum;
import cn.fw.freya.model.data.pool.LivePool;
import cn.fw.freya.model.data.pool.VideoPool;
import cn.fw.freya.model.dto.rpc.ReportAccountDto;
import cn.fw.freya.utils.http.InitUserAgent;

import java.io.IOException;
import java.util.List;

/**
 * @author null
 * @date 2021-11-12 11:28
 * @description
 */
public interface CrawlStrategy {
    /**
     * 账户类型(1:快手, 2:抖音, 3:懂车帝, 4:Bilibili)
     *
     * @return
     */
    AccountTypeEnum getType();

    /**
     * 登陆准备
     *
     * @param accountNo 账户号
     * @return
     */
    String preLogin(String accountNo);

    /**
     * 登陆
     *
     * @param accountNo 账户号
     * @return
     */
    boolean doLogin(String accountNo);

    /**
     * 获取 UserAgent
     *
     * @param accountNo 账户号
     * @return
     */
    default String getUserAgent(String accountNo) {
        return InitUserAgent.getOne();
    }

    /**
     * 随机等待时长
     *
     * @param seconds
     */
    default void waitFor(int seconds) {
        try {
            Thread.sleep(seconds * 1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 随机等待时长
     *
     * @param seconds
     */
    default void waitFor(double seconds) {
        try {
            Thread.sleep((long) (seconds * 1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    /**
     * 退出浏览器
     *
     * @param accountNo 账户号
     * @return
     */
    default boolean exitBrowser(String accountNo) {
        return true;
    }

    /**
     * 获取所有视频信息
     *
     * @param accountNo 账户号
     * @return
     * @throws IOException
     */
    List<VideoPool> getAllVideoMsg(String accountNo) throws IOException;

    /**
     * 获取昨日所有直播信息
     *
     * @param accountNo 账户号
     * @return
     * @throws IOException
     */
    List<LivePool> getYesterdayLiveMsg(String accountNo) throws IOException;

    /**
     * 更新账户信息
     *
     * @param accountNo 账户号
     * @return
     * @throws IOException
     */
    ReportAccountDto updateAccountMsg(String accountNo) throws IOException;
}