fix #2998 支持从视频文件生成集缩略图

This commit is contained in:
jxxghp 2023-02-09 20:25:52 +08:00
parent a5f6d97ae8
commit cd69d47462
9 changed files with 65 additions and 7 deletions

View File

@ -820,7 +820,8 @@ class FileTransfer:
scraper_nfo=self._scraper_nfo,
scraper_pic=self._scraper_pic,
dir_path=ret_dir_path,
file_name=os.path.basename(ret_file_path))
file_name=os.path.basename(ret_file_path),
file_ext=file_ext)
# 更新进度
self.progress.update(ptype="filetransfer",
value=round(total_count / len(Medias) * 100),

View File

@ -13,3 +13,4 @@ from .opensubtitles import OpenSubtitles
from .words_helper import WordsHelper
from .submodule_helper import SubmoduleHelper
from .cookiecloud_helper import CookieCloudHelper
from .ffmpeg_helper import FfmpegHelper

View File

@ -0,0 +1,19 @@
from app.utils import SystemUtils
class FfmpegHelper:
@staticmethod
def get_thumb_image_from_video(video_path, image_path, frames="00:03:01"):
"""
使用ffmpeg从视频文件中截取缩略图
"""
if not video_path or not image_path:
return False
cmd = 'ffmpeg -i "{video_path}" -ss {frames} -vframes 1 -f image2 "{image_path}"'.format(video_path=video_path,
frames=frames,
image_path=image_path)
result = SystemUtils.execute(cmd)
if result:
return True
return False

View File

@ -3,6 +3,7 @@ import time
from xml.dom import minidom
import log
from app.helper import FfmpegHelper
from app.media.douban import DouBan
from config import TMDB_IMAGE_W500_URL
from app.utils import DomUtils, RequestUtils, ExceptionUtils
@ -283,14 +284,15 @@ class Scraper:
with open(out_file, "wb") as xml_file:
xml_file.write(xml_str)
def gen_scraper_files(self, media, scraper_nfo, scraper_pic, dir_path, file_name):
def gen_scraper_files(self, media, scraper_nfo, scraper_pic, dir_path, file_name, file_ext):
"""
刮削元数据
:param media: 已识别的媒体信息
:param scraper_nfo: NFO刮削配置
:param scraper_pic: 图片刮削配置
:param dir_path: 文件路径
:param file_name: 文件名
:param file_name: 文件名不含后缀
:param file_ext: 文件后缀
"""
if not scraper_nfo:
scraper_nfo = {}
@ -455,6 +457,15 @@ class Scraper:
self.__save_image(seasonthumb,
os.path.dirname(dir_path),
"season%s-landscape" % media.get_season_seq().rjust(2, '0'))
# 处理集
if scraper_tv_pic.get("episode_thumb"):
episode_thumb = os.path.join(dir_path, file_name, "-thumb.jpg")
if not os.path.exists(episode_thumb):
video_path = os.path.join(dir_path, file_name + file_ext)
log.info(f"【Scraper】正在生成缩略图{video_path} ...")
FfmpegHelper().get_thumb_image_from_video(video_path=video_path,
image_path=episode_thumb)
log.info(f"【Scraper】缩略图生成完成{episode_thumb}")
except Exception as e:
ExceptionUtils.exception_traceback(e)

View File

@ -91,8 +91,12 @@ class SystemUtils:
"""
执行命令获得返回结果
"""
with os.popen(cmd) as p:
return p.readline().strip()
try:
with os.popen(cmd) as p:
return p.readline().strip()
except Exception as err:
print(str(err))
return ""
@staticmethod
def is_docker():

View File

@ -275,7 +275,8 @@ def update_config():
"thumb": True,
"season_poster": True,
"season_banner": True,
"season_thumb": True}
"season_thumb": True,
"episode_thumb": False}
}
overwrite_cofig = True

View File

@ -163,6 +163,8 @@ scraper_pic:
season_poster: true
season_banner: true
season_thumb: true
# 集
episode_thumb: false
# 【配置消息通知服务】
message:

View File

@ -15,4 +15,5 @@ xvfb
inotify-tools
chromium-chromedriver
npm
dumb-init
dumb-init
ffmpeg

View File

@ -974,6 +974,24 @@
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="mb-3">
<label class="form-label">电视剧-集图片 </label>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-3">
<div class="mb-3">
<label class="form-check">
<input class="form-check-input" type="checkbox" id="scraper_pic.tv.episode_thumb" {% if
Config.scraper_pic and Config.scraper_pic.tv.episode_thumb %}checked{% endif %}>
<span class="form-check-label">thumb <span class="form-help" title="开启后将读取视频文件生成集缩略图需要ffmpeg最新Docker镜像已包含" data-bs-toggle="tooltip">?</span></span>
</label>
</div>
</div>
</div>
</div>
</div>
</div>