Skip to content

Commit

Permalink
Merge branch 'harry0703:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZhang19870314 authored Apr 15, 2024
2 parents 00052b4 + b836934 commit 17df9a1
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
- [ ] 自动上传到YouTube平台

## 交流讨论 💬
<img src="docs/wechat-01.jpg" width="300">
<img src="docs/wechat-03.jpg" width="300">

## 视频演示 📺

Expand Down
4 changes: 3 additions & 1 deletion app/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def save_config():
project_name = _cfg.get("project_name", "MoneyPrinterTurbo")
project_description = _cfg.get("project_description",
"<a href='https://github.com/harry0703/MoneyPrinterTurbo'>https://github.com/harry0703/MoneyPrinterTurbo</a>")
project_version = _cfg.get("project_version", "1.1.0")
project_version = _cfg.get("project_version", "1.1.1")
reload_debug = False

imagemagick_path = app.get("imagemagick_path", "")
Expand All @@ -63,3 +63,5 @@ def save_config():
ffmpeg_path = app.get("ffmpeg_path", "")
if ffmpeg_path and os.path.isfile(ffmpeg_path):
os.environ["IMAGEIO_FFMPEG_EXE"] = ffmpeg_path

logger.info(f"{project_name} v{project_version}")
15 changes: 14 additions & 1 deletion app/services/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
from typing import List
from loguru import logger
from moviepy.video.io.VideoFileClip import VideoFileClip

from app.config import config
from app.models.schema import VideoAspect, VideoConcatMode, MaterialInfo
Expand Down Expand Up @@ -105,7 +106,19 @@ def save_video(video_url: str, save_dir: str = "") -> str:
f.write(requests.get(video_url, proxies=proxies, verify=False, timeout=(60, 240)).content)

if os.path.exists(video_path) and os.path.getsize(video_path) > 0:
return video_path
try:
clip = VideoFileClip(video_path)
duration = clip.duration
fps = clip.fps
clip.close()
if duration > 0 and fps > 0:
return video_path
except Exception as e:
try:
os.remove(video_path)
except Exception as e:
pass
logger.warning(f"invalid video file: {video_path} => {str(e)}")
return ""


Expand Down
31 changes: 19 additions & 12 deletions app/services/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
def get_bgm_file(bgm_type: str = "random", bgm_file: str = ""):
if not bgm_type:
return ""

if bgm_file and os.path.exists(bgm_file):
return bgm_file

if bgm_type == "random":
suffix = "*.mp3"
song_dir = utils.song_dir()
files = glob.glob(os.path.join(song_dir, suffix))
return random.choice(files)

if os.path.exists(bgm_file):
return bgm_file

return ""


Expand Down Expand Up @@ -108,6 +109,7 @@ def combine_videos(combined_video_path: str,
logger=None,
temp_audiofile_path=output_dir,
audio_codec="aac",
fps=30,
)
logger.success(f"completed")
return combined_video_path
Expand All @@ -126,7 +128,7 @@ def get_text_size(inner_text):
if width <= max_width:
return text, height

logger.warning(f"wrapping text, max_width: {max_width}, text_width: {width}, text: {text}")
# logger.warning(f"wrapping text, max_width: {max_width}, text_width: {width}, text: {text}")

processed = True

Expand All @@ -150,7 +152,7 @@ def get_text_size(inner_text):
_wrapped_lines_ = [line.strip() for line in _wrapped_lines_]
result = '\n'.join(_wrapped_lines_).strip()
height = len(_wrapped_lines_) * height
logger.warning(f"wrapped text: {result}")
# logger.warning(f"wrapped text: {result}")
return result, height

_wrapped_lines_ = []
Expand All @@ -167,7 +169,7 @@ def get_text_size(inner_text):
_wrapped_lines_.append(_txt_)
result = '\n'.join(_wrapped_lines_).strip()
height = len(_wrapped_lines_) * height
logger.warning(f"wrapped text: {result}")
# logger.warning(f"wrapped text: {result}")
return result, height


Expand Down Expand Up @@ -244,18 +246,23 @@ def create_text_clip(subtitle_item):

bgm_file = get_bgm_file(bgm_type=params.bgm_type, bgm_file=params.bgm_file)
if bgm_file:
bgm_clip = (AudioFileClip(bgm_file)
.set_duration(video_clip.duration)
.volumex(params.bgm_volume)
.audio_fadeout(3))
try:
bgm_clip = (AudioFileClip(bgm_file)
.volumex(params.bgm_volume)
.audio_fadeout(3))
bgm_clip = afx.audio_loop(bgm_clip, duration=video_clip.duration)
audio_clip = CompositeAudioClip([audio_clip, bgm_clip])
except Exception as e:
logger.error(f"failed to add bgm: {str(e)}")

audio_clip = CompositeAudioClip([audio_clip, bgm_clip])
video_clip = video_clip.set_audio(audio_clip)
video_clip.write_videofile(output_file,
audio_codec="aac",
temp_audiofile_path=output_dir,
threads=params.n_threads or 2,
logger=None)
logger=None,
fps=30,
)

logger.success(f"completed")

Expand Down
39 changes: 31 additions & 8 deletions app/services/voice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,21 +1019,27 @@ async def _do() -> SubMaker:
return None


def create_subtitle(sub_maker: submaker.SubMaker, text: str, subtitle_file: str):
"""
优化字幕文件
1. 将字幕文件按照标点符号分割成多行
2. 逐行匹配字幕文件中的文本
3. 生成新的字幕文件
"""
text = text.replace("\n", " ")
def _format_text(text: str) -> str:
# text = text.replace("\n", " ")
text = text.replace("[", " ")
text = text.replace("]", " ")
text = text.replace("(", " ")
text = text.replace(")", " ")
text = text.replace("{", " ")
text = text.replace("}", " ")
text = text.strip()
return text


def create_subtitle(sub_maker: submaker.SubMaker, text: str, subtitle_file: str):
"""
优化字幕文件
1. 将字幕文件按照标点符号分割成多行
2. 逐行匹配字幕文件中的文本
3. 生成新的字幕文件
"""

text = _format_text(text)

def formatter(idx: int, start_time: float, end_time: float, sub_text: str) -> str:
"""
Expand Down Expand Up @@ -1156,6 +1162,23 @@ async def _do():
"""

text = "[Opening scene: A sunny day in a suburban neighborhood. A young boy named Alex, around 8 years old, is playing in his front yard with his loyal dog, Buddy.]\n\n[Camera zooms in on Alex as he throws a ball for Buddy to fetch. Buddy excitedly runs after it and brings it back to Alex.]\n\nAlex: Good boy, Buddy! You're the best dog ever!\n\n[Buddy barks happily and wags his tail.]\n\n[As Alex and Buddy continue playing, a series of potential dangers loom nearby, such as a stray dog approaching, a ball rolling towards the street, and a suspicious-looking stranger walking by.]\n\nAlex: Uh oh, Buddy, look out!\n\n[Buddy senses the danger and immediately springs into action. He barks loudly at the stray dog, scaring it away. Then, he rushes to retrieve the ball before it reaches the street and gently nudges it back towards Alex. Finally, he stands protectively between Alex and the stranger, growling softly to warn them away.]\n\nAlex: Wow, Buddy, you're like my superhero!\n\n[Just as Alex and Buddy are about to head inside, they hear a loud crash from a nearby construction site. They rush over to investigate and find a pile of rubble blocking the path of a kitten trapped underneath.]\n\nAlex: Oh no, Buddy, we have to help!\n\n[Buddy barks in agreement and together they work to carefully move the rubble aside, allowing the kitten to escape unharmed. The kitten gratefully nuzzles against Buddy, who responds with a friendly lick.]\n\nAlex: We did it, Buddy! We saved the day again!\n\n[As Alex and Buddy walk home together, the sun begins to set, casting a warm glow over the neighborhood.]\n\nAlex: Thanks for always being there to watch over me, Buddy. You're not just my dog, you're my best friend.\n\n[Buddy barks happily and nuzzles against Alex as they disappear into the sunset, ready to face whatever adventures tomorrow may bring.]\n\n[End scene.]"

text = "大家好,我是乔哥,一个想帮你把信用卡全部还清的家伙!\n今天我们要聊的是信用卡的取现功能。\n你是不是也曾经因为一时的资金紧张,而拿着信用卡到ATM机取现?如果是,那你得好好看看这个视频了。\n现在都2024年了,我以为现在不会再有人用信用卡取现功能了。前几天一个粉丝发来一张图片,取现1万。\n信用卡取现有三个弊端。\n一,信用卡取现功能代价可不小。会先收取一个取现手续费,比如这个粉丝,取现1万,按2.5%收取手续费,收取了250元。\n二,信用卡正常消费有最长56天的免息期,但取现不享受免息期。从取现那一天开始,每天按照万5收取利息,这个粉丝用了11天,收取了55元利息。\n三,频繁的取现行为,银行会认为你资金紧张,会被标记为高风险用户,影响你的综合评分和额度。\n那么,如果你资金紧张了,该怎么办呢?\n乔哥给你支一招,用破思机摩擦信用卡,只需要少量的手续费,而且还可以享受最长56天的免息期。\n最后,如果你对玩卡感兴趣,可以找乔哥领取一本《卡神秘籍》,用卡过程中遇到任何疑惑,也欢迎找乔哥交流。\n别忘了,关注乔哥,回复用卡技巧,免费领取《2024用卡技巧》,让我们一起成为用卡高手!"

text = """
2023全年业绩速览
公司全年累计实现营业收入1476.94亿元,同比增长19.01%,归母净利润747.34亿元,同比增长19.16%。EPS达到59.49元。第四季度单季,营业收入444.25亿元,同比增长20.26%,环比增长31.86%;归母净利润218.58亿元,同比增长19.33%,环比增长29.37%。这一阶段
的业绩表现不仅突显了公司的增长动力和盈利能力,也反映出公司在竞争激烈的市场环境中保持了良好的发展势头。
2023年Q4业绩速览
第四季度,营业收入贡献主要增长点;销售费用高增致盈利能力承压;税金同比上升27%,扰动净利率表现。
业绩解读
利润方面,2023全年贵州茅台,>归母净利润增速为19%,其中营业收入正贡献18%,营业成本正贡献百分之一,管理费用正贡献百分之一点四。(注:归母净利润增速值=营业收入增速+各科目贡献,展示贡献/拖累的前四名科目,且要求贡献值/净利润增速>15%)
"""

text = _format_text(text)
lines = utils.split_string_by_punctuations(text)
print(lines)

for voice_name in voice_names:
voice_file = f"{temp_dir}/tts-{voice_name}.mp3"
subtitle_file = f"{temp_dir}/tts.mp3.srt"
Expand Down
24 changes: 23 additions & 1 deletion app/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,34 @@ def str_contains_punctuation(word):
def split_string_by_punctuations(s):
result = []
txt = ""
for char in s:

previous_char = ""
next_char = ""
for i in range(len(s)):
char = s[i]
if char == "\n":
result.append(txt.strip())
txt = ""
continue

if i > 0:
previous_char = s[i - 1]
if i < len(s) - 1:
next_char = s[i + 1]

if char == "." and previous_char.isdigit() and next_char.isdigit():
# 取现1万,按2.5%收取手续费, 2.5 中的 . 不能作为换行标记
txt += char
continue

if char not in const.PUNCTUATIONS:
txt += char
else:
result.append(txt.strip())
txt = ""

# filter empty string
result = list(filter(None, result))
return result


Expand Down
Binary file removed docs/wechat-01.jpg
Binary file not shown.
Binary file added docs/wechat-03.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions webui/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def get_all_fonts():
for file in files:
if file.endswith(".ttf") or file.endswith(".ttc"):
fonts.append(file)
fonts.sort()
return fonts


Expand Down

0 comments on commit 17df9a1

Please sign in to comment.