import argparse import random import time import Contant from LoggerUtils import Logger, initLogger import Orm from Orm import Video,DownloadInfo from VideoService import VideoService from ChannelService import ChannelService from DownloadInfoService import DownloadService from DownloadUtil import DownLoadUtil from func_timeout import func_set_timeout import func_timeout import requests # python3 ./main_download.py --db="../db/youtube_prod.db" --logDir="./logs" if __name__ == "__main__": parser = argparse.ArgumentParser(description='') parser.add_argument('--db', type=str, default='') parser.add_argument('--logDir', type=str, default='') args = parser.parse_args() Contant.db = args.db Contant.logDir = args.logDir initLogger() Orm.ormInit() # channelIds = ["UCUopc5tlSTMgBsZaP4PItRA", # "UC25CsqDNQv6CdzDq_hsazIw", # "UC4douYiP0O4ABtxoMuo9yNA", # "UCaT01FqK7SuPyqR8d2gvuiQ", # "UCA_hK5eRICBdSOLlXKESvEg", # "UCrZzlE9f9aR6yjvIy6-hggg", # "UCrm095p7ZHRS1njmQ1wkgCg", # "UCDDneQi63kJAdr3i5VCPzHg", # "UCwWXGnvVmi-6Sfx2wf8S8tQ", # "UCuzqko_GKcj9922M1gUo__w", # "UCwIdAI4fCV4lisP3TZzOGuw", # "UCYDaGPmMfSXViITpPYDKIcw", # "UCqULpqYsoBDTc_QswJOwMdQ", # "UC3GeULpLgXi1TNDAv0nyN5Q", # "UCYIVkruUoN04UjV9pkBTswg", # "UCya5E2GyEep6HuEsmLUcyWA", # "UC26mgnC13yyRANhG8bEf26g", # "UCJcPWs0gpYMx_CghPdELUhw", # "UCyF2mDq-XtPbhgTXwz1p93A"] # channelIds_hk = ["UC7v5yfvZhs-d5opF575AEhA", # "UCCHUPcdmSP-jqAkh4eh96yg", # "UC4G8Si5IBGy9k_1Oo04DMVg", # "UCAwfc603xR0xXQN58x4uWeA", # "UCHOLdIRhuGvY6EcpmDno3Iw", # "UChQ2W327SnjTlYZwCijCFYw", # "UCOjQAwkxNOY76-_zPqOWziA", # "UCkx8tfePUl__VGvNDNOKqRw", # "UCGAbl3E1aqqgrjwIaiDDdqQ", # "UC15Qrw0HKAMf2RG9PMNRPLg", # "UCilwQlk62k1z7aUEZPOB6yw", # "UCNRdj1WX-bxm5GPJtR2cM5Q", # "UCdWNwPuaS1o2dIzugNMXWtw"] # query = (Video.select().where(Video.channelId.in_(channelIds_hk))) # videos = query.execute() # Logger.info(len(videos)) # count = 0 # for video in videos: # videoId = video.videoId # downLoadInfo = DownloadInfo.get(DownloadInfo.videoId == videoId) # if downLoadInfo.isFinished == 1: # Logger.info(videoId) # count = count + 1 # DownLoadUtil.downloadOne(videoId) # time.sleep(2) # Logger.info("间隔两秒") # Logger.info(count) for line in open("2.txt"): line = line.strip('\n') Logger.info(line) DownLoadUtil.downloadOne(line) # testVideoId = "5RbZgn3Ql5c" # DownLoadUtil.downloadOne(testVideoId) # list = DownloadService.findNotFinishList() # Logger.info("list size:{}".format(len(list))) # while (len(list) > 0): # for info in list: # try: # DownLoadUtil.downloadOne(info.videoId) # restTime = random.randint(1, 3) # Logger.info("间隔{}秒后继续...".format(restTime)) # time.sleep(restTime) # except func_timeout.exceptions.FunctionTimedOut as e: # Logger.error("执行下载方法超时错误:{}".format(e)) # loopRestTime = random.randint(1, 3) # Logger.info("循环间隔{}秒后继续...".format(loopRestTime)) # time.sleep(loopRestTime) # list = DownloadService.findNotFinishList() # # 发送钉钉消息 # webhook = "https://oapi.dingtalk.com/robot/send?access_token=c8c8d7d42c4eecd449dd303025ef968f647d1d8e8694e3fabc0ab5770d646dcb" # jsonData = { # "msgtype": "text", # "text": { # "content": "[Youtube]download finished" # } # } # requests.post(webhook, json=jsonData) # Logger.info("download发送钉钉消息成功...")