Skip to content

Commit

Permalink
Merge pull request #12 from chenmozhijin/dev
Browse files Browse the repository at this point in the history
v0.7.2
  • Loading branch information
chenmozhijin authored Sep 19, 2024
2 parents fc52c79 + af8d1e0 commit 3ceb77e
Show file tree
Hide file tree
Showing 32 changed files with 1,172 additions and 1,115 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/build-nuitka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: build LDDC

on:
push:
branches: main
branches:
- main
- dev
paths:
- "**.py"
- ".github/workflows/build-nuitka.yml"
Expand Down Expand Up @@ -58,7 +60,7 @@ jobs:
sudo apt-get update
sudo apt-get install libegl1 upx
- name: Install create-dmg/upx
- name: Install create-dmg
if: ${{ runner.os == 'macOS' }}
run: |
brew install create-dmg
Expand Down Expand Up @@ -105,7 +107,7 @@ jobs:

disable-console: true

macos-app-icon: "res/img/icon/logo.png"
macos-app-icon: "res/img/icon/logo.icns"
macos-app-version: ${{ steps.info.outputs.version }}
macos-create-app-bundle: true
macos-target-arch: ${{ steps.arch.outputs.nuitka_arch }}
Expand All @@ -125,7 +127,7 @@ jobs:
product-version: ${{ steps.info.outputs.version }}
copyright: ${{ steps.info.outputs.copyright }}

windows-icon-from-ico: "res/img/icon/logo.png"
windows-icon-from-ico: "res/img/icon/logo.ico"
mingw64: true
windows-console-mode: 'attach'

Expand Down Expand Up @@ -252,7 +254,6 @@ jobs:
cd build
7z a -tzip -mx=9 ../upload/LDDC-${{ steps.info.outputs.version }}-windows-${{ steps.arch.outputs.arch }}.zip LDDC
- name: Upload
uses: actions/upload-artifact@v4
with:
Expand Down
24 changes: 13 additions & 11 deletions LDDC.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,49 @@
# SPDX-License-Identifier: GPL-3.0-only
import sys

from PySide6.QtCore import (
Qt,
QThread,
)
from PySide6.QtCore import QThread
from PySide6.QtWidgets import QApplication

import res.resource_rc
from backend.service import (
LDDCService,
)
from backend.service import LDDCService
from res import resource_rc
from utils.args import args
from utils.exit_manager import exit_manager
from utils.translator import load_translation
from utils.version import __version__

res.resource_rc.qInitResources()
resource_rc.qInitResources()


if __name__ == "__main__":

app = QApplication(sys.argv)
if args.get_service_port:
# 如果是获取服务端口,则只需实例化LDDCService(会获取并打印另一个LDDC进程服务端口),然后退出
LDDCService()
sys.exit()

show = args.show

# 启动服务线程
service = LDDCService()
service_thread = QThread(app)
exit_manager.threads.append(service_thread)
service.moveToThread(service_thread)
service_thread.start()
service.instance_del.connect(exit_manager.close_event)

exit_manager.close_signal.connect(service.stop_service, Qt.ConnectionType.BlockingQueuedConnection)

# 加载翻译
load_translation(False)
# 显示主窗口(如果需要)
if show:
from view.main_window import main_window
main_window.show()

# 检查更新
from utils.data import cfg
if cfg["auto_check_update"]:
from view.update import check_update
check_update(True, QApplication.translate("CheckUpdate", "LDDC主程序"), "chenmozhijin/LDDC", __version__)

# 进入事件循环
sys.exit(app.exec())
9 changes: 8 additions & 1 deletion backend/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ def qm_search(keyword: str, search_type: SearchType, page: int | str = 1) -> lis
if search_type not in (SearchType.SONG, SearchType.ARTIST, SearchType.ALBUM, SearchType.SONGLIST):
msg = f"搜索类型错误,类型为{search_type}"
raise ValueError(msg)
search_type_mapping = {
SearchType.SONG: 0,
SearchType.ARTIST: 1,
SearchType.ALBUM: 2,
SearchType.SONGLIST: 3,
SearchType.LYRICS: 7,
}
data = json.dumps({
"comm": {
"g_tk": 997034911,
Expand All @@ -386,7 +393,7 @@ def qm_search(keyword: str, search_type: SearchType, page: int | str = 1) -> lis
"num_per_page": 20,
"page_num": int(page),
"query": keyword,
"search_type": search_type.value,
"search_type": search_type_mapping[search_type],
},
},
}, ensure_ascii=False).encode("utf-8")
Expand Down
41 changes: 26 additions & 15 deletions backend/decryptor/eapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,40 @@
import json
from base64 import b64decode, b64encode

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from pyaes import AESModeOfOperationECB


def pkcs7_pad(data: bytes, block_size: int = 16) -> bytes:
pad_len = block_size - (len(data) % block_size)
padding = bytes([pad_len] * pad_len)
return data + padding


def pkcs7_unpad(data: bytes) -> bytes:
pad_len = data[-1]
if pad_len < 1 or pad_len > 16:
msg = "Invalid padding encountered."
raise ValueError(msg)
return data[:-pad_len]


def aes_encrypt(data: str | bytes, key: bytes) -> bytes:
if isinstance(data, str):
data = data.encode()
backend = default_backend()
cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=backend) # noqa: S305
encryptor = cipher.encryptor()
padder = padding.PKCS7(128).padder()
padded_data = padder.update(data) + padder.finalize()
return encryptor.update(padded_data) + encryptor.finalize()
padded_data = pkcs7_pad(data) # Ensure the data is padded
aes = AESModeOfOperationECB(key) # Using ECB mode
encrypted_data = b''
for i in range(0, len(padded_data), 16):
encrypted_data += aes.encrypt(padded_data[i:i + 16]) # Encrypt in 16-byte blocks
return encrypted_data


def aes_decrypt(cipher_buffer: bytes, key: bytes) -> bytes:
backend = default_backend()
cipher = Cipher(algorithms.AES(key), modes.ECB(), backend=backend) # noqa: S305
decryptor = cipher.decryptor()
unpadder = padding.PKCS7(128).unpadder()
decrypted_data = decryptor.update(cipher_buffer) + decryptor.finalize()
return unpadder.update(decrypted_data) + unpadder.finalize()
aes = AESModeOfOperationECB(key) # Using ECB mode
decrypted_data = b''
for i in range(0, len(cipher_buffer), 16):
decrypted_data += aes.decrypt(cipher_buffer[i:i + 16]) # Decrypt in 16-byte blocks
return pkcs7_unpad(decrypted_data) # Remove padding after decryption


def eapi_params_encrypt(path: bytes, params: dict) -> str:
Expand Down
6 changes: 3 additions & 3 deletions backend/decryptor/qmc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 沉默の金 <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

PRIVKey = [
PRIVKEY = (
0xc3, 0x4a, 0xd6, 0xca, 0x90, 0x67, 0xf7, 0x52,
0xd8, 0xa1, 0x66, 0x62, 0x9f, 0x5b, 0x09, 0x00,

Expand All @@ -28,9 +28,9 @@

0xc3, 0x00, 0x09, 0x5b, 0x9f, 0x62, 0x66, 0xa1,
0xd8, 0x52, 0xf7, 0x67, 0x90, 0xca, 0xd6, 0x4a,
]
)


def qmc1_decrypt(data: bytearray) -> None:
for i, _value in enumerate(data):
data[i] ^= PRIVKey[(i % 0x7FFF) & 0x7F] if i > 0x7FFF else PRIVKey[i & 0x7F]
data[i] ^= PRIVKEY[(i % 0x7FFF) & 0x7F] if i > 0x7FFF else PRIVKEY[i & 0x7F]
1 change: 1 addition & 0 deletions backend/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_full_timestamps_lyrics_data(data: LyricsData, duration: int | None, only

if only_line:
result.append(LyricsLine((line_start_time, line_end_time, line[2])))
continue

words = []
for j, word in enumerate(line[2]):
Expand Down
Loading

0 comments on commit 3ceb77e

Please sign in to comment.