コード例 #1
0
def redis_public(o_redis, msg):
    #写入redis并发出消息
    o_redis.public(msg)


print(sys.getdefaultencoding())

print('--------------------------------------read config')
#print(config_configparser.config_write())
config = config_configparser.config_read()
print(config)
log_file = (config['DEFAULT']['server action'])

b_loop = True
log = LogHelper(log_file)

# 实例化RedisHelper类对象
str_r_ip = config['redis']['ip2']
str_r_port = config['redis']['port2']
str_r_pwd = config['redis']['pwd2']
str_r_chan = config['redis']['chan1']
str_r_db = config['redis']['db']
str_r_chan2 = config['redis']['chan2']

#打印配置文件
lists_header = config.sections()
str_config = ""
for secs in lists_header:
    for key in config[secs]:
        str_config = str_config + " " + key + ":" + config[secs][key]
コード例 #2
0
    configInfo.barkurl = cf.get("BarkConfig", "barkurl")
    configInfo.barkapikey = cf.get("BarkConfig", "barkapikey")
    configInfo.notifyurl = cf.get("BarkConfig", "notifyurl")
    configInfo.repeatTimes = int(cf.get("DownloadConfig", "repeatTimes"))
    configInfo.delay = int(cf.get("DownloadConfig", "delay"))

    return configInfo


if __name__ == '__main__':
    # --------------------------------------------------------------
    # 读取外部配置
    configInfo = ReadConfigIni()

    while configInfo.repeatTimes > 0 or configInfo.repeatTimes == -1:
        logger = LogHelper('Bili', cmdLevel='INFO', fileLevel="DEBUG").logger

        try:
            logger.info('repeatTimes = ' + str(configInfo.repeatTimes))
            # --------------------------------------------------------------
            # 设置需要下载的信息
            # 每个 UP 主视频
            downloadlistfile = 'DownloadList.txt'
            if os.path.exists(downloadlistfile) == True:
                filmList = ReadDownloadList(downloadlistfile)
            else:
                logger.error("DownloadList.txt not found")
                raise Exception("DownloadList.txt not found")

            uperList = ReadDownloadList(downloadlistfile)
コード例 #3
0
def main():
    logger = LogHelper('ZiMuZuHelper', cmdLevel='INFO',
                       fileLevel="DEBUG").logger
    onething = WanKeYunApi.WanKeYunApi(logger)
    bok = onething.LoginEx(user="******", passwd="1234567890")
    if bok is False:
        return
    bok = onething.GetUSBInfo()
    if bok is False:
        return
    bok = onething.RemoteDlLogin()
    if bok is False:
        return
    bok = onething.GetRemoteDlInfo()
    if bok is False:
        return
    # --------------------------------------------------------------------------------
    # bok, mediaInfo = onething.UrlResolve('ed2k://|file|%E9%BB%84%E7%9F%B3.Yellowstone.2018.S01E07.%E4%B8%AD%E8%8B%B1%E5%AD%97%E5%B9%95.WEB.720P-%E4%BA%BA%E4%BA%BA%E5%BD%B1%E8%A7%86.mp4|559753916|bdb7746c12f23558420a1bfd610e8bb5|h=xavxscmhtkwu4bl52jiqnmow6pa6ntdf|/')
    # --------------------------------------------------------------------------------
    JobList = []
    OneJob = {
        "filesize":
        0,
        "name":
        '黄石.Yellowstone.2018.S01E07.中英字幕.WEB.720P-人人影视.mp4',
        "url":
        'ed2k://|file|%E9%BB%84%E7%9F%B3.Yellowstone.2018.S01E07.%E4%B8%AD%E8%8B%B1%E5%AD%97%E5%B9%95.WEB.720P-%E4%BA%BA%E4%BA%BA%E5%BD%B1%E8%A7%86.mp4|559753916|bdb7746c12f23558420a1bfd610e8bb5|h=xavxscmhtkwu4bl52jiqnmow6pa6ntdf|/',
    }
    OneJob2 = {
        "filesize":
        0,
        "name":
        '黄石.Yellowstone.2018.S01E08.中英字幕.WEB.720P-人人影视.mp4',
        "url":
        'ed2k://|file|%E9%BB%84%E7%9F%B3.Yellowstone.2018.S01E08.%E4%B8%AD%E8%8B%B1%E5%AD%97%E5%B9%95.WEB.720P-%E4%BA%BA%E4%BA%BA%E5%BD%B1%E8%A7%86.mp4|472873520|c273bf00703b45225f2056393d6de87f|h=yq4vc2vndh2fnqdiwnhnqapwh7xcvlrw|/',
    }
    OneJob3 = {
        "filesize":
        0,
        # "name": '【幻櫻字幕組】【一拳超人 第二季 ONE PUNCH MAN S2】【OVA】【02】【BIG5_MP4】【1280X720】.mp4',
        "name":
        '123.mp4',
        "url":
        "magnet:?xt=urn:btih:UK32AE3T2R3UOBAPDVZJ6W35T7DRSFGJ&dn=&tr=http%3A%2F%2F104.238.198.186%3A8000%2Fannounce&tr=udp%3A%2F%2F104.238.198.186%3A8000%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker3.itzmx.com%3A6961%2Fannounce&tr=http%3A%2F%2Ftracker4.itzmx.com%3A2710%2Fannounce&tr=http%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=http%3A%2F%2Ftracker.prq.to%2Fannounce&tr=http%3A%2F%2Fopen.acgtracker.com%3A1096%2Fannounce&tr=https%3A%2F%2Ft-115.rhcloud.com%2Fonly_for_ylbud&tr=http%3A%2F%2Ftracker1.itzmx.com%3A8080%2Fannounce&tr=http%3A%2F%2Ftracker2.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker1.itzmx.com%3A8080%2Fannounce&tr=udp%3A%2F%2Ftracker2.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker3.itzmx.com%3A6961%2Fannounce&tr=udp%3A%2F%2Ftracker4.itzmx.com%3A2710%2Fannounce&tr=http%3A%2F%2Fnyaa.tracker.wf%3A7777%2Fannounce"
    }
    JobList.append(OneJob)
    JobList.append(OneJob2)
    JobList.append(OneJob3)
    # --------------------------------------------------------------------------------
    # 创建批量下载任务示例,原生,需要自己填入,需要下载到那个磁盘
    # 一般就是磁盘 0
    # partitionID = 0
    # rootPath = onething.user_info["usb_info"][1]['partitions'][partitionID]['path']
    # remoteLocation = rootPath + self.defaultPath
    # remoteLocation = remoteLocation.lower()
    # onething.CreateTasks(JobList, remoteLocation)
    # --------------------------------------------------------------------------------
    # 当玩客云关机再开机的时候,需要恢复为下载完成的任务,也可以操作暂停正在下载的任务
    # 查询下载的任务列表,下载完毕的也在内,需要过滤
    # nowDownloadingList = onething.user_info["remote_download_list"]["tasks"]
    # for oneTask in nowDownloadingList:
    #     iprogress = int(oneTask["progress"])
    #     if iprogress == 10000:
    #         pass
    #     else:
    #         # onething.StartRemoteDl(oneTask["id"])
    #         onething.PauseRemoteDl(oneTask["id"])
    # --------------------------------------------------------------------------------
    # 创建批量下载任务,扩展,会判断
    onething.AddDownloadTasks(JobList)
    # --------------------------------------------------------------------------------
    print("Done.")
コード例 #4
0
ファイル: Main.py プロジェクト: clown643/BiliBiliDownloader
def MainProcess(uperList, saveRootPath, concurrency = 3):
    logger = LogHelper('Bili', cmdLevel='INFO', fileLevel="DEBUG").logger
    pp = None
    try:
        # --------------------------------------------------------------
        # 进行每个 UP 主视频页数的获取
        pp = PreProcess(logger = logger, uperList=uperList)
        pp.ScanLoclInfo(saveRootPath)
        pp.Process()
        # --------------------------------------------------------------
        # 爬取要下载视频的 url
        for uper in pp.uperList:
            logger.info(uper.UserName + " Spider Start···")
            OneSpiderRetryTimes = 0
            # 打算下载的数量,要去网络动态获取的数量进行对比
            while ((uper.NeedDownloadFilmCount > len(uper.VideoInfoDic_NetFileName) or len(uper.ErrorUrl_Dic) > 0) and OneSpiderRetryTimes <= 10):
                # dd = BiliSpider()
                # GithubDeveloperSpider
                BiliSpider.start(logger = logger,
                                uper = uper,
                                saveRootPath = saveRootPath,
                                concurrency = concurrency,
                                middleware=middleware)
                                
                OneSpiderRetryTimes = OneSpiderRetryTimes + 1
                logger.info("Try Spider " + uper.UserName + " " + str(OneSpiderRetryTimes) + " times.")
                RandomSleep()
                
            logger.info(uper.UserName + " Spider Done.")

            if OneSpiderRetryTimes > 10:
                logger.error(uper.UserName + " Spider Retry " + str(OneSpiderRetryTimes) + "times.")
                logger.error("Error Url:")
                for eUrl in uper.ErrorUrl_Dic:
                    logger.error(eUrl)
            else:
                # 本地应该原有+准备要下载的 != 网络总数,需要提示
                if len(uper.VideoInfoDic_NetFileName) != len(uper.VideoInfoDic_loaclFileName):
                    logger.warn("VideoInfoDic_NetFileName Count: " + str(len(uper.VideoInfoDic_NetFileName)) 
                        + " != VideoInfoDic_loaclFileName Count: " + str(len(uper.VideoInfoDic_loaclFileName))
                    )
            uper.ErrorUrl_Dic.clear()

        logger.info("Spider All Done.")
        # --------------------------------------------------------------
        logger.info("Start Download"+ "----" * 20)
        # 开始下载
        # 先对 local 与 net 的字典进行同步
        logger.info("Start Sync Dic")
        for uper in pp.uperList:
            iNeedDl = 0
            for fileName, oneVideo in zip(uper.VideoInfoDic_loaclFileName.keys(), uper.VideoInfoDic_loaclFileName.values()):
                if fileName in uper.VideoInfoDic_NetFileName:
                    uper.VideoInfoDic_NetFileName[fileName].isDownloaded = oneVideo.isDownloaded
                    if oneVideo.isDownloaded == False:
                        iNeedDl = iNeedDl + 1
            logger.info(uper.UserName + "NetFile / LocalFile -- NeedDl: " + str(len(uper.VideoInfoDic_NetFileName)) + " / " + str(len(uper.VideoInfoDic_loaclFileName)) + " -- " + str(iNeedDl))
        logger.info("End Sync Dic")
        for uper in pp.uperList:
            directory = os.path.join(saveRootPath, uper.UserName)
            for fileName, oneVideo in zip(uper.VideoInfoDic_NetFileName.keys(), uper.VideoInfoDic_NetFileName.values()):
                if oneVideo.isDownloaded == True:
                    continue
                DownloadRetryTimes = 0
                oneRe = False
                while oneRe is False and DownloadRetryTimes <= 10:
                    oneRe = Downloader(logger, directory, oneVideo.time, oneVideo.title, oneVideo.url).ProcessOne()
                    DownloadRetryTimes = DownloadRetryTimes + 1
                    logger.info("Try Download " + str(DownloadRetryTimes) + " times.")
                    RandomSleep()

                if OneSpiderRetryTimes > 10:
                    logger.error("Retry Download " + str(DownloadRetryTimes) + " times.")
                    logger.error("Error Url: " + oneVideo.url)
                # 标记下载完成
                if oneRe:
                    oneVideo.isDownloaded = True
                    uper.ThisTimeDownloadCount = uper.ThisTimeDownloadCount + 1
                    

    except Exception as ex:
        errInfo = "Catch Exception: " + str(ex)
        logger.error(errInfo)
    finally:
        logger.info("finally"+ "----" * 20)
        for uper in pp.uperList:
            logger.info("This Time Download: " + uper.UserName + " -- " + str(uper.ThisTimeDownloadCount))
        for uper in pp.uperList:
            for fileName, oneVideo in zip(uper.VideoInfoDic_NetFileName.keys(), uper.VideoInfoDic_NetFileName.values()):
                if oneVideo.isDownloaded == False:
                    logger.error('Download Fail:' + uper.UserName)
                    logger.error(oneVideo.url)
        logger.info("All Done.")