You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.7 KiB
47 lines
1.7 KiB
6 months ago
|
import time
|
||
|
from LoggerUtils import Logger, initLogger
|
||
|
from bs4 import BeautifulSoup as bs
|
||
|
from urllib.request import urlopen, Request
|
||
|
import json
|
||
|
import Contant
|
||
|
from sqlalchemy import create_engine
|
||
|
from entity.DownloadInfoEntity import DownloadInfo
|
||
|
from service.DownloadInfoService import DownloadInfoService
|
||
|
from common.YoutubeUtils import YouTubeUtil
|
||
|
import operator
|
||
|
import argparse
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
# 读取配置文件
|
||
|
with open('download_video_config.json', 'r', encoding='utf-8') as f:
|
||
|
# 使用json.load()方法读取文件内容
|
||
|
data = json.load(f)
|
||
|
|
||
|
# 初始化日志
|
||
|
Contant.logDir = data['log']['dir']
|
||
|
Contant.logFileName = data['log']['fileName']
|
||
|
initLogger(Contant.logDir, Contant.logFileName)
|
||
|
|
||
|
# 连接mysql
|
||
|
dbHost = data['mysql']['host']
|
||
|
dbPort = data['mysql']['port']
|
||
|
dbUserName = data['mysql']['username']
|
||
|
dbPassword = data['mysql']['password']
|
||
|
dbDatabase = data['mysql']['database']
|
||
|
Logger.info("尝试连接mysql host:'{}' port:'{}' username:'{}' password:'{}' database:'{}'",
|
||
|
dbHost, dbPort, dbUserName, dbPassword, dbDatabase)
|
||
|
Contant.engin = create_engine(
|
||
|
f'mysql+mysqlconnector://{dbUserName}:{dbPassword}@{dbHost}:{dbPort}/{dbDatabase}')
|
||
|
Logger.info("连接mysql成功")
|
||
|
|
||
|
# 获取一个未下载的video
|
||
|
downloadInfo: DownloadInfo = DownloadInfoService.getOneNoFinish()
|
||
|
if downloadInfo != None:
|
||
|
Logger.info("开始下载videoId:{}".format(downloadInfo.videoId))
|
||
|
# TODO 下载字幕文件或音频文件
|
||
|
# 重新获取下一个下载任务
|
||
|
downloadInfo: DownloadInfo = DownloadInfoService.getOneNoFinish()
|
||
|
else:
|
||
|
Logger.info("完成下载")
|