Skip to content

Commit

Permalink
修复B站电脑客户端因为缓存文件的加密格式更改导致的合并失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
molihuan committed Mar 14, 2024
1 parent f6dbdc8 commit b8f23a3
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
1 change: 1 addition & 0 deletions modules/framework/manager/ConfigManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ConfigKey():
CACHE_PATH = "CachePath"
COMPLETE_PATH = "CompletePath"
SYS_FFMPEG_PATH = "SysFFmpegPath"
DECRYPT_M4S_TYPE = "decryptM4sType"


appName = "HLB站缓存合并1.1"
Expand Down
7 changes: 7 additions & 0 deletions modules/home/BaseDataWorkPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions modules/home/convertbar/BaseAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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解密失败")

Expand Down
1 change: 1 addition & 0 deletions modules/home/init/DataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ def __init__(self, mContext):
self.configJsonPath: str
self.sysFFmpegPath: str
self.cacheFileTpye = None
self.decryptM4sType :str
6 changes: 5 additions & 1 deletion modules/home/init/InitManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
42 changes: 35 additions & 7 deletions modules/settings/BaseSettingsPage.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -41,24 +43,46 @@ 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("保存")

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)

Expand All @@ -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
15 changes: 15 additions & 0 deletions modules/utils/FileUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit b8f23a3

Please sign in to comment.