Browse Source

新增download_video

master
zhangshu 5 months ago
parent
commit
a1276e0c1b
  1. 9
      common/DownloadUtils.py
  2. 7
      download_video.py
  3. 3
      download_video_config.json
  4. 45
      sftp.py
  5. 20
      sftp_config.json

9
common/DownloadUtils.py

@ -52,17 +52,14 @@ class DownloadUtil:
ys.download(output_path=mp3OutPutPath, filename=fileName, mp3=True)
@func_set_timeout(60)
def downloadOne(videoId):
def downloadOne(videoId, rootPath):
video: Video = VideoService.queryOneByVideoId(videoId=videoId)
channel: Channel = ChannelService.queryOneByChannelId(video.channelId)
# 开始下载
Logger.info("开始下载...{}".format(videoId))
# 配置下载地址 /mnt/youtube_mysql
mainPath = "/mnt/youtube_mysql/srt/main"
tmpPath = "/mnt/youtube_mysql/srt/tmp"
# TODO 删除测试代码
mainPath = "E:/code/tmp/main"
tmpPath = "E:/code/tmp/tmp"
mainPath = "{}/main".format(rootPath)
tmpPath = "{}/tmp".format(rootPath)
storePath = "{}/{}/{}-{}".format(
mainPath, channel.region, channel.channelId, channel.channelTitle)

7
download_video.py

@ -8,6 +8,7 @@ from sqlalchemy import create_engine
from entity.DownloadInfoEntity import DownloadInfo
from service.DownloadInfoService import DownloadInfoService
from common.YoutubeUtils import YouTubeUtil
from common.DownloadUtils import DownloadUtil
import operator
import argparse
@ -36,10 +37,16 @@ if __name__ == "__main__":
Logger.info("连接mysql成功")
# 获取一个未下载的video
downloadRootPath = data['download_root_path']
if downloadRootPath == "" or downloadRootPath == None:
Logger.error("downloadRootPath配置错误...")
exit
Logger.info(f"downloadRootPaht: '{downloadRootPath}'")
downloadInfo: DownloadInfo = DownloadInfoService.getOneNoFinish()
if downloadInfo != None:
Logger.info("开始下载videoId:{}".format(downloadInfo.videoId))
# TODO 下载字幕文件或音频文件
DownloadUtil.downloadOne(downloadInfo.videoId, downloadRootPath)
# 重新获取下一个下载任务
downloadInfo: DownloadInfo = DownloadInfoService.getOneNoFinish()
else:

3
download_video_config.json

@ -9,5 +9,6 @@
"log": {
"dir": "./logs",
"fileName": "download_video"
}
},
"download_root_path": "E:/code/tmp/main"
}

45
sftp.py

@ -0,0 +1,45 @@
import os
import shutil
import paramiko
import argparse
import Contant
from LoggerUtils import Logger, initLogger
import configparser
import requests
import time
import json
if __name__ == "__main__":
# 读取配置文件
with open('search_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)
# 设置sftp client
hostname = data['sftp']['hostname']
port = data['sftp']['port']
username = data['sftp']['username']
password = data['sftp']['password']
Logger.info("host:{},port:{},username:{},password:{}".format(
hostname, port, username, password))
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sftp_client = None # 设置默认值
ssh_client.connect(hostname, port, username, password)
# 创建SFTP客户端
sftp_client = ssh_client.open_sftp()
Logger.info("SFTP客户端已经建立:{}".format(sftp_client))
remote_root = "/Inbound/YouTube Captions"
local_root = data['sftp']['local']
Logger.info("remote_root:{},local_root:{}".format(remote_root, local_root))
# 遍历所有文件,然后上传

20
sftp_config.json

@ -0,0 +1,20 @@
{
"mysql": {
"host": "47.108.20.249",
"port": "3306",
"username": "root",
"password": "casino888!",
"database": "youtube"
},
"log": {
"dir": "./logs",
"fileName": "sftp"
},
"sftp": {
"local": "E:/code/tmp/main",
"hostname": "filetransfer.blackrock.com",
"port": "22",
"username": "ftp_yunbo",
"password": "s8v{8SJr"
}
}
Loading…
Cancel
Save