|
@ -30,17 +30,24 @@ class DownloadUtil: |
|
|
Logger.info("VideoId: {} 已收录", videoId) |
|
|
Logger.info("VideoId: {} 已收录", videoId) |
|
|
return |
|
|
return |
|
|
subs = pysrt.open(srtFilePath) |
|
|
subs = pysrt.open(srtFilePath) |
|
|
|
|
|
srtFiles = [] |
|
|
ordinal = 1 |
|
|
ordinal = 1 |
|
|
for sub in subs: |
|
|
for sub in subs: |
|
|
srtStartTime = str(sub.start.to_time()).rstrip("0") |
|
|
srtStartTime = str(sub.start.to_time()).rstrip("0") |
|
|
|
|
|
if ordinal == 1: |
|
|
|
|
|
srtStartTime = sub.start.to_time() |
|
|
srtEndTime = str(sub.end.to_time()).rstrip("0") |
|
|
srtEndTime = str(sub.end.to_time()).rstrip("0") |
|
|
SrtFileService.insertOne(videoId=videoId, channelId=channelId, ordinal=ordinal, |
|
|
srtFile: Srtfile = Srtfile(videoId=videoId, channelId=channelId, ordinal=ordinal, |
|
|
srtStartTime=srtStartTime, srtEndTime=srtEndTime, srtText=sub.text, isScan=0) |
|
|
srtStartTime=srtStartTime, srtEndTime=srtEndTime, srtText=sub.text, isScan=0) |
|
|
ordinal = ordinal + 1 |
|
|
ordinal = ordinal + 1 |
|
|
|
|
|
srtFiles.append(srtFile) |
|
|
|
|
|
# 批量插入字幕数据 |
|
|
|
|
|
SrtFileService.insertList(srtFiles=srtFiles) |
|
|
|
|
|
Logger.info( |
|
|
|
|
|
f"读取srt文件成功 videoId:{videoId} channelId:{channelId} srtFilePath:{srtFilePath}") |
|
|
|
|
|
|
|
|
def downLoadMP3(videoId, storePath): |
|
|
def downLoadMP3(videoId, storePath): |
|
|
video:Video = VideoService.getOneByVideoId(videoId) |
|
|
video: Video = VideoService.queryOneByVideoId(videoId) |
|
|
channel:Channel = ChannelService.queryOneByChannelId(video.channelId) |
|
|
|
|
|
videoUrl = "https://www.youtube.com/watch?v={}".format(videoId) |
|
|
videoUrl = "https://www.youtube.com/watch?v={}".format(videoId) |
|
|
yt = YouTube(videoUrl, on_progress_callback=on_progress) |
|
|
yt = YouTube(videoUrl, on_progress_callback=on_progress) |
|
|
ys = yt.streams.get_audio_only() |
|
|
ys = yt.streams.get_audio_only() |
|
@ -48,7 +55,7 @@ class DownloadUtil: |
|
|
if not os.path.exists(mp3OutPutPath): |
|
|
if not os.path.exists(mp3OutPutPath): |
|
|
Logger.info("开始创建文件夹:" + mp3OutPutPath) |
|
|
Logger.info("开始创建文件夹:" + mp3OutPutPath) |
|
|
os.makedirs(mp3OutPutPath) |
|
|
os.makedirs(mp3OutPutPath) |
|
|
fileName = "{}.mp3".format(videoId) |
|
|
fileName = "{}".format(videoId) |
|
|
ys.download(output_path=mp3OutPutPath, filename=fileName, mp3=True) |
|
|
ys.download(output_path=mp3OutPutPath, filename=fileName, mp3=True) |
|
|
|
|
|
|
|
|
@func_set_timeout(60) |
|
|
@func_set_timeout(60) |
|
@ -98,8 +105,7 @@ class DownloadUtil: |
|
|
videoId=videoId) |
|
|
videoId=videoId) |
|
|
if downloadInfo is not None: |
|
|
if downloadInfo is not None: |
|
|
DownloadInfoService.updateIsFinishByVideoId(videoId, 1, 1) |
|
|
DownloadInfoService.updateIsFinishByVideoId(videoId, 1, 1) |
|
|
DownloadUtil.iterateSrt(storePath, videoId, video.channelId) |
|
|
DownloadUtil.iterateSrt(storePathSrt, videoId, video.channelId) |
|
|
pass |
|
|
|
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
Logger.error(e) |
|
|
Logger.error(e) |
|
|
logStr = "Exception...{}".format(e) |
|
|
logStr = "Exception...{}".format(e) |
|
|