diff --git a/modules/framework/manager/ConfigManager.py b/modules/framework/manager/ConfigManager.py index 1a3027e..66075df 100644 --- a/modules/framework/manager/ConfigManager.py +++ b/modules/framework/manager/ConfigManager.py @@ -10,6 +10,7 @@ class ConfigKey(): CACHE_PATH = "CachePath" COMPLETE_PATH = "CompletePath" SYS_FFMPEG_PATH = "SysFFmpegPath" + DECRYPT_M4S_TYPE = "decryptM4sType" appName = "HLB站缓存合并1.1" diff --git a/modules/home/BaseDataWorkPage.py b/modules/home/BaseDataWorkPage.py index 4013583..fc243e9 100644 --- a/modules/home/BaseDataWorkPage.py +++ b/modules/home/BaseDataWorkPage.py @@ -50,6 +50,7 @@ def saveConfigData(self): configJson = { # ConfigKey.SYS_FFMPEG_PATH: self.getSysFFmpegPath(), ConfigKey.CACHE_PATH: self.getCachePath(), + ConfigKey.DECRYPT_M4S_TYPE: self.getDecryptM4sType(), # ConfigKey.COMPLETE_PATH: self.getCompletePath() } self.ConfigManager.updateByDict(configJson) @@ -93,3 +94,9 @@ def getCacheFileTpye(self): def setCacheFileTpye(self, value): self.DataManager.cacheFileTpye = value + + def getDecryptM4sType(self): + return self.DataManager.decryptM4sType + + def setDecryptM4sType(self, value): + self.DataManager.decryptM4sType = value diff --git a/modules/home/convertbar/BaseAction.py b/modules/home/convertbar/BaseAction.py index 6cda51b..38f2f6c 100644 --- a/modules/home/convertbar/BaseAction.py +++ b/modules/home/convertbar/BaseAction.py @@ -58,8 +58,16 @@ def fixM4s(self, cacheInfo): hlbAudio = os.path.join(path, "hlbAudio.mp3") hlbVideo = os.path.join(path, "hlbVideo.mp4") try: - FileUtils.decryptM4s(audio_path, hlbAudio) - FileUtils.decryptM4s(video_path, hlbVideo) + decryptM4sType = self.getContext().getDecryptM4sType() + if(decryptM4sType == '方式1'): + FileUtils.decryptM4s(audio_path, hlbAudio) + FileUtils.decryptM4s(video_path, hlbVideo) + elif(decryptM4sType == '方式2'): + FileUtils.decryptM4s2(audio_path, hlbAudio) + FileUtils.decryptM4s2(video_path, hlbVideo) + else: + Log.i("decryptM4sType配置错误") + except Exception as e: Log.i("fixM4s解密失败") diff --git a/modules/home/init/DataManager.py b/modules/home/init/DataManager.py index d0783b6..f122ac7 100644 --- a/modules/home/init/DataManager.py +++ b/modules/home/init/DataManager.py @@ -16,3 +16,4 @@ def __init__(self, mContext): self.configJsonPath: str self.sysFFmpegPath: str self.cacheFileTpye = None + self.decryptM4sType :str diff --git a/modules/home/init/InitManager.py b/modules/home/init/InitManager.py index cbdbf22..a615681 100644 --- a/modules/home/init/InitManager.py +++ b/modules/home/init/InitManager.py @@ -67,6 +67,9 @@ def initData(self): sysFFmpegPath = configManager.get(ConfigKey.SYS_FFMPEG_PATH) context.setSysFFmpegPath(sysFFmpegPath) + decryptM4sType = configManager.get(ConfigKey.DECRYPT_M4S_TYPE) + context.setDecryptM4sType(decryptM4sType) + # 检查ffmpeg是否有执行权限 SysUtils.checkFFmpegExecPermissions(sysFFmpegPath) @@ -91,7 +94,8 @@ def initNeedPath(self, context): ConfigKey.INIT_NEED_PATH: 1, ConfigKey.SYS_FFMPEG_PATH: sysFFmpegPath, ConfigKey.CACHE_PATH: cachePath, - ConfigKey.COMPLETE_PATH: completePath + ConfigKey.COMPLETE_PATH: completePath, + ConfigKey.DECRYPT_M4S_TYPE: "方式2" } # 将数据写入到config.json文件中 context.ConfigManager.addByDict(configJson) diff --git a/modules/settings/BaseSettingsPage.py b/modules/settings/BaseSettingsPage.py index bf70aef..c24b3dc 100644 --- a/modules/settings/BaseSettingsPage.py +++ b/modules/settings/BaseSettingsPage.py @@ -1,5 +1,5 @@ from PySide6.QtWidgets import QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QFileDialog, QLabel, \ - QLineEdit, QSpacerItem, QSizePolicy + QLineEdit, QSpacerItem, QSizePolicy, QComboBox # 基础设置页面 from modules.home.base.BaseServiceWidget import BaseServiceWidget @@ -22,6 +22,8 @@ def __init__(self, mContext): icon = SysUtils.getTransparentIcon() self.setWindowIcon(icon) + self.total_layout = QVBoxLayout() + # 初始化主布局和底部布局 self.main_layout = QHBoxLayout() self.bottom_layout = QHBoxLayout() @@ -41,6 +43,28 @@ def __init__(self, mContext): self.main_layout.addWidget(self.label) self.main_layout.addWidget(self.edit_line) self.main_layout.addWidget(self.select_path_btn) + self.total_layout.addLayout(self.main_layout) + + #解密方式选择 + decryptionOptionsLayout = QHBoxLayout() + + decryptionOptionslabel = QLabel("B站电脑客户端缓存解密:") + decryptionOptionsLayout.addWidget(decryptionOptionslabel) + + self.decryptionOptionsCombobox = QComboBox() + self.decryptionOptionsCombobox.addItem("方式1") + self.decryptionOptionsCombobox.addItem("方式2") + decryptM4sType = mContext.getDecryptM4sType() + self.decryptionOptionsCombobox.setCurrentText(decryptM4sType) + self.decryptionOptionsCombobox.setStyleSheet("background-color: rgb(33, 37, 43);") + + self.decryptionOptionsCombobox.currentIndexChanged.connect(self.saveConfigData) + decryptionOptionsLayout.addWidget(self.decryptionOptionsCombobox) + + central_widget = QWidget() + central_widget.setLayout(decryptionOptionsLayout) + self.total_layout.addWidget(central_widget) + # 创建保存和关闭按钮 self.save_btn = QPushButton("保存") @@ -48,17 +72,17 @@ def __init__(self, mContext): self.save_btn.setStyleSheet("background-color: rgb(33, 37, 43);") self.save_btn.setMinimumSize(120, 30) - # self.close_btn = QPushButton("关闭") - # self.close_btn.setStyleSheet("background-color: rgb(33, 37, 43);") - # self.close_btn.setMinimumSize(120, 30) + self.reset_btn = QPushButton("重置") + self.reset_btn.setStyleSheet("background-color: rgb(33, 37, 43);") + self.reset_btn.setMinimumSize(120, 30) # 将保存和关闭按钮添加到底部布局 self.bottom_layout.addStretch(1) + self.bottom_layout.addWidget(self.reset_btn) self.bottom_layout.addWidget(self.save_btn) - # self.bottom_layout.addWidget(self.close_btn) # 创建总布局并添加主布局和底部布局 - self.total_layout = QVBoxLayout() - self.total_layout.addLayout(self.main_layout) + + self.total_layout.addItem(QSpacerItem(0, 0, QSizePolicy.Expanding, QSizePolicy.Expanding)) self.total_layout.addLayout(self.bottom_layout) @@ -80,5 +104,9 @@ def open_file_dialog(self): def saveConfigData(self): context = self.getContext() context.setCompletePath(self.edit_line.text()) + context.setDecryptM4sType(self.decryptionOptionsCombobox.currentText()) context.saveConfigData() context.Toast.shows("保存成功") + + def ttt(self): + pass diff --git a/modules/utils/FileUtils.py b/modules/utils/FileUtils.py index c0f724d..9346ec9 100644 --- a/modules/utils/FileUtils.py +++ b/modules/utils/FileUtils.py @@ -44,6 +44,21 @@ def decryptM4s(target_path: str, output_path: str, bufsize: int = 256 * 1024 * 1 while i: output_file.write(i) i = target_file.read(bufsize) + # 解密m4s + @staticmethod + def decryptM4s2(target_path: str, output_path: str, bufsize: int = 256 * 1024 * 1024) -> None: + assert bufsize > 0 + with open(target_path, 'rb') as target_file: + header = target_file.read(32) + new_header = header.replace(b'000000000', b'') + # new_header = new_header.replace(b'$', b' ') + # new_header = new_header.replace(b'avc1', b'') + with open(output_path, 'wb') as output_file: + output_file.write(new_header) + i = target_file.read(bufsize) + while i: + output_file.write(i) + i = target_file.read(bufsize) @staticmethod def compareFileSize(file1, file2):