Skip to content

Commit

Permalink
Merge pull request #42 from ScottSloan/dev
Browse files Browse the repository at this point in the history
🐛 fix: 修复通知弹出无效的问题
  • Loading branch information
ScottSloan authored Nov 28, 2024
2 parents 90a17b5 + 8e47860 commit f50ad54
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 29 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ Bili23 Downloader GUI
- 视频 av、BV 号
- 剧集 ep、md、ss 号

解析完成后,点击右上角小齿轮图标可自定义清晰度和音质等设置。

[![pA4xzQJ.png](https://s21.ax1x.com/2024/11/28/pA4xzQJ.png)](https://imgse.com/i/pA4xzQJ)

### **下载**
[![pAl4IxO.png](https://s21.ax1x.com/2024/09/27/pAl4IxO.png)](https://imgse.com/i/pAl4IxO)

程序支持多线程下载(最多 8 线程)、并行下载(上限为 8 个,支持动态调整)、断点续传、下载限速、出错重试等功能。

# 更新日志
### **Version 1.53.0 (2024/11/28)**
### **Version 1.53 (2024/11/28)**
Version 1.53.0 正式版发布

本次更新内容:
Expand Down
15 changes: 7 additions & 8 deletions src/gui/dialog/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,18 @@ def onPlayStreamEVT(self, event):
match Config.Misc.player_preference:
case Config.Type.PLAYER_PREFERENCE_DEFAULT:
# 寻找关联的播放器
_default = FileDirectoryTool.get_file_ext_associated_app(".mp4")
result = FileDirectoryTool.get_file_ext_associated_app(".mp4")

if not result[0]:
wx.MessageDialog(self, "无法获取默认播放器\n\n无法获取系统默认播放器,请手动设置\n\n请使用支持播放 m3u8 视频流的播放器(如 VLC、PotPlayer、MPV等),Windows 默认的媒体播放器不支持播放,请知悉", "警告", wx.ICON_WARNING).ShowModal()
return

match Config.Sys.platform:
case "windows":
cmd = _default.replace("%1", self.m3u8_link_box.GetValue())
cmd = result[1].replace("%1", self.m3u8_link_box.GetValue())

case "linux":
cmd = _default.replace("%U", f'"{self.m3u8_link_box.GetValue()}"')

case "darwin":
wx.MessageDialog(self, "无法获取默认播放器\n\nmacOS 平台不支持获取默认播放器,无法播放直播视频流,请手动设置", "警告", wx.ICON_WARNING).ShowModal()

return
cmd = result[1].replace("%U", f'"{self.m3u8_link_box.GetValue()}"')

case Config.Type.PLAYER_PREFERENCE_CUSTOM:
cmd = f'"{Config.Misc.player_path}" "{self.m3u8_link_box.GetValue()}"'
Expand Down
77 changes: 65 additions & 12 deletions src/gui/download_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import wx
import time
import json
import wx.adv
import requests
import subprocess
from typing import Dict, List, Callable
Expand All @@ -12,7 +13,7 @@
from gui.dialog.cover import CoverViewerDialog

from utils.config import Config
from utils.data_type import DownloadTaskInfo, DownloaderCallback, DownloaderInfo, UtilsCallback, TaskPanelCallback, ErrorLog
from utils.data_type import DownloadTaskInfo, DownloaderCallback, DownloaderInfo, UtilsCallback, TaskPanelCallback, ErrorLog, NotificationMessage
from utils.icon_v2 import IconManager, RESUME_ICON, PAUSE_ICON, DELETE_ICON, FOLDER_ICON, RETRY_ICON
from utils.thread import Thread
from utils.tool_v2 import RequestTool, FileDirectoryTool, DownloadFileTool, FormatTool, UniversalTool
Expand Down Expand Up @@ -308,22 +309,57 @@ def stop_download_callback(cid: int):
if start_download:
self.start_download()

def update_task_count_label(self):
def update_task_count_label(self, message: NotificationMessage = None, stop_by_manual: bool = False):
def _show_notification():
if Config.Download.show_notification:
if message:
_show_notification_failed()

if not stop_by_manual:
_show_notification_finish()

self.RequestUserAttention(wx.USER_ATTENTION_ERROR)

def _show_notification_finish():
notification = wx.adv.NotificationMessage("下载完成", "所有下载任务均已完成", parent = self, flags = wx.ICON_INFORMATION)
notification.Show()

def _show_notification_failed():
match message.status:
case Config.Type.DOWNLOAD_STATUS_MERGE_FAILED:
match message.video_merge_type:
case Config.Type.MERGE_TYPE_ALL | Config.Type.MERGE_TYPE_VIDEO:
_title = "合成失败"
_message = f'任务 "{message.video_title}" 合成失败'

case Config.Type.MERGE_TYPE_AUDIO:
_title = "转换失败"
_message = f'任务 "{message.video_title}" 转换失败'

case Config.Type.DOWNLOAD_STATUS_DOWNLOAD_FAILED:
_title = "下载失败"
_message = f'任务 "{message.video_title}" 下载失败'

notification = wx.adv.NotificationMessage(_title, _message, parent = self, flags = wx.ICON_ERROR)
notification.Show()

count = self.get_download_task_count(Config.Type.DOWNLOAD_STATUS_ALIVE_LIST)

if count:
_label = f"{count} 个任务正在下载"
else:
_label = "下载管理"

_show_notification()

self.task_count_lab.SetLabel(_label)

def refresh_task_list_panel_ui(self):
# 刷新面板 ui
self.download_task_list_panel.Layout()
self.download_task_list_panel.SetupScrolling(scroll_x = False, scrollToTop = False)

wx.CallAfter(self.update_task_count_label)
wx.CallAfter(self.update_task_count_label, stop_by_manual = True)

class DownloadUtils:
def __init__(self, task_info: DownloadTaskInfo, callback: UtilsCallback):
Expand Down Expand Up @@ -440,16 +476,20 @@ def _get_dolby(_json_dash: Dict):
# 视频不存在音频,标记 flag 为仅下载视频
self.task_info.video_merge_type = Config.Type.MERGE_TYPE_VIDEO

json_dash = get_json()
try:
json_dash = get_json()

self._video_download_url_list = self._audio_download_url_list = []
self._video_download_url_list = self._audio_download_url_list = []

get_video_available_quality()
get_video_available_quality()

get_video_available_codec()
get_video_available_codec()

get_audio_available_quality()

except Exception:
self.callback.onDownloadFailedCallback()

get_audio_available_quality()

def get_downloader_info_list(self):
self.get_video_bangumi_download_url()

Expand Down Expand Up @@ -494,7 +534,7 @@ def clear_files():
_error_log.return_code = _process.returncode
_error_log.time = UniversalTool.get_current_time()

self.callback.onErrorCallback(_error_log)
self.callback.onMergeFailedCallback(_error_log)

def _get_shell_cmd(self):
def _get_audio_cmd():
Expand Down Expand Up @@ -815,7 +855,8 @@ def get_downloader_callback():
def get_utils_callback():
_callback = UtilsCallback()
_callback.onMergeFinishCallback = self.onMergeFinish
_callback.onErrorCallback = self.onMergeFailed
_callback.onMergeFailedCallback = self.onMergeFailed
_callback.onDownloadFailedCallback = self.onDownloadFailed

return _callback

Expand Down Expand Up @@ -1027,6 +1068,13 @@ def callback():

self.pause_btn.Enable(True)
self.stop_btn.Enable(True)

message = NotificationMessage()
message.video_title = self.task_info.title
message.status = self.task_info.status
message.video_merge_type = self.task_info.video_merge_type

self.callback.onUpdateTaskCountCallback(message)

self._error_log = error_log

Expand All @@ -1038,7 +1086,12 @@ def callback():
self.update_download_status(Config.Type.DOWNLOAD_STATUS_DOWNLOAD_FAILED)
self.speed_lab.SetLabel("下载失败")

self.callback.onUpdateTaskCountCallback()
message = NotificationMessage()
message.video_title = self.task_info.title
message.status = self.task_info.status
message.video_merge_type = self.task_info.video_merge_type

self.callback.onUpdateTaskCountCallback(message)
self.callback.onStartNextCallback()

wx.CallAfter(callback)
Expand Down
4 changes: 2 additions & 2 deletions src/gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _layout():

self.add_number_chk = wx.CheckBox(self.scrolled_panel, -1, "批量下载视频时自动添加序号")
self.delete_history_chk = wx.CheckBox(self.scrolled_panel, -1, "下载完成后清除本地下载记录")
self.show_toast_chk = wx.CheckBox(self.scrolled_panel, -1, "下载完成后弹出通知")
self.show_toast_chk = wx.CheckBox(self.scrolled_panel, -1, "允许弹出通知提示")

vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(path_lab, 0, wx.ALL, 10)
Expand Down Expand Up @@ -329,7 +329,7 @@ def onVideoCodecTipEVT(self, event):
wx.MessageDialog(self, "视频编码格式选项说明\n\n指定下载视频的编码格式,取决于视频的支持情况;若视频无所选的编码格式,则默认下载 AVC/H.264", "说明", wx.ICON_INFORMATION).ShowModal()

def onDolbyTipEVT(self, event):
wx.MessageDialog(self, '自动下载杜比选项说明\n\n当上方选择 "自动" 时,若视频支持杜比,则自动下载杜比视界或杜比全景声,否则需要手动选择\n开启此项前请先确认设备是否支持杜比', "说明", wx.ICON_INFORMATION).ShowModal()
wx.MessageDialog(self, '自动下载杜比选项说明\n\n当上方选择 "自动" 时,若视频支持杜比,则自动下载杜比视界或杜比全景声,否则需要手动选择\n\n开启此项前请先确认设备是否支持杜比', "说明", wx.ICON_INFORMATION).ShowModal()

class MergeTab(wx.Panel):
def __init__(self, parent, _main_window):
Expand Down
9 changes: 8 additions & 1 deletion src/utils/data_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ def __init__(self):
class UtilsCallback:
def __init__(self):
self.onMergeFinishCallback: Callable = None
self.onErrorCallback: Callable = None
self.onMergeFailedCallback: Callable = None
self.onDownloadFailedCallback: Callable = None

class TaskPanelCallback:
def __init__(self):
Expand All @@ -174,3 +175,9 @@ def __init__(self):
self.log: str = ""
self.time: str = ""
self.return_code: int = 0

class NotificationMessage:
def __init__(self):
self.video_title: str = ""
self.status: int = 0
self.video_merge_type: int = 0
14 changes: 9 additions & 5 deletions src/utils/tool_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ def _linux():

match Config.Sys.platform:
case "windows":
return FileDirectoryTool._msw_AssocQueryStringW(file_ext)
result, buffer = FileDirectoryTool._msw_AssocQueryStringW(file_ext)

if result == 0:
return (True, str(buffer.value))
else:
return (False, "")

case "linux":
return _linux()
return (True, _linux())

case "darwin":
# macOS 不支持获取默认程序
return
return (False, "")

@staticmethod
def _msw_SHOpenFolderAndSelectItems(path: str):
Expand Down Expand Up @@ -495,5 +500,4 @@ def _get_ffmpeg_cwd_path():
if os.path.isfile(possible_path) and os.access(possible_path, os.X_OK):
ffmpeg_path = possible_path

return ffmpeg_path

return ffmpeg_path

0 comments on commit f50ad54

Please sign in to comment.