Skip to content

Commit

Permalink
Merge pull request #9 from chenmozhijin/dev
Browse files Browse the repository at this point in the history
v0.7.1
  • Loading branch information
chenmozhijin authored Aug 28, 2024
2 parents be7b7d9 + bd3c948 commit fc52c79
Show file tree
Hide file tree
Showing 24 changed files with 1,165 additions and 2,546 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build-nuitka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Install create-dmg/upx
if: ${{ runner.os == 'macOS' }}
run: |
brew install create-dmg upx
brew install create-dmg
- name: Install upx/7zip
if: ${{ runner.os == 'Windows' }}
Expand All @@ -88,14 +88,15 @@ jobs:
echo "version=$(python build_helper.py --task get_version)" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Build Executable
- name: Build Executable(Linux/macOS)
uses: Nuitka/Nuitka-Action@main
if : ${{ runner.os == 'Linux' || runner.os == 'macOS'}}
with:
nuitka-version: main
script-name: LDDC.py
standalone: true
onefile: false
report: nuitka-report.xml
enable-plugins: pyside6
product-name: "LDDC"
file-version: ${{ steps.info.outputs.version }}
Expand All @@ -109,14 +110,15 @@ jobs:
macos-create-app-bundle: true
macos-target-arch: ${{ steps.arch.outputs.nuitka_arch }}

- name: Build Executable
- name: Build Executable(Windows)
uses: Nuitka/Nuitka-Action@main
if : ${{ runner.os == 'Windows' }}
with:
nuitka-version: main
script-name: LDDC.py
standalone: true
onefile: false
report: nuitka-report.xml
enable-plugins: pyside6
product-name: "LDDC"
file-version: ${{ steps.info.outputs.version }}
Expand All @@ -134,7 +136,7 @@ jobs:
name: ${{ runner.os }} - ${{ matrix.arch }} report
path: |
nuitka-crash-report.xml
report.xml
nuitka-report.xml
- name: create dmg
if: ${{ runner.os == 'macOS' }}
Expand Down
2 changes: 1 addition & 1 deletion LDDC.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

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

from view.main_window import main_window
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"]:
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## 功能

- [x] 搜索QQ音乐、酷狗音乐、网易云音乐的单曲、专辑、歌单
- [x] 拖动歌曲到搜索界面自动搜索并匹配歌词
- [x] 一键下载整个 专辑、歌单 的歌词
- [x] 一键为本地歌曲文件匹配歌词
- [x] 支持保存为多种格式(逐字lrc、逐行lrc、增强型lrc、srt、ass)
Expand All @@ -32,9 +33,21 @@

## 预览

### 拖拽歌曲快速匹配歌词

![gif](img/drop.gif)

### 搜索界面

![image](img/zh_1.jpg)

### 打开歌词/本地匹配/设置界面

![image](img/zh_2.jpg)

### 桌面歌词

![image](img/zh_3.jpg)
![gif](img/desktop_lyrics.gif)

## 使用方法
Expand All @@ -49,7 +62,6 @@

[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=WXRIW&repo=QQMusicDecoder)](https://github.com/WXRIW/QQMusicDecoder)
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=jixunmoe&repo=qmc-decode)](https://github.com/jixunmoe/qmc-decode)
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=parakeet-rs&repo=libparakeet)](https://github.com/parakeet-rs/libparakeet)

### 音乐平台api

Expand Down
14 changes: 13 additions & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Features

- [x] Search for singles, albums, and playlists on QQ Music, Kugou Music, and NetEase Cloud Music
- [x] Drag the song to the search interface to automatically search and match the lyrics
- [x] One-click download of lyrics for entire albums and playlists
- [x] One-click match lyrics for local song files
- [x] Support for saving in multiple formats (verbatim lrc,line by line lrc,Enhanced LRC, srt, ass)
Expand All @@ -32,9 +33,21 @@

## Preview

### Drag songs to quickly match lyrics

![gif](img/drop.gif)

### Search interface

![image](img/en_1.jpg)

### Open the lyrics/local matching/settings interface

![image](img/en_2.jpg)

### Desktop Lyrics

![image](img/en_3.jpg)
![gif](img/desktop_lyrics.gif)

## Usage
Expand All @@ -49,7 +62,6 @@ Some functionalities are implemented with reference to the following projects:

[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=WXRIW&repo=QQMusicDecoder)](https://github.com/WXRIW/QQMusicDecoder)
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=jixunmoe&repo=qmc-decode)](https://github.com/jixunmoe/qmc-decode)
[![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=parakeet-rs&repo=libparakeet)](https://github.com/parakeet-rs/libparakeet)

### Music Platform APIs

Expand Down
4 changes: 2 additions & 2 deletions backend/converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def convert2(lyrics: Lyrics,
if key == "source":
value: Source
json_dict["info"][key] = value.name
else:
elif value is not None:
json_dict["info"][key] = value

return json.dumps(json_dict, ensure_ascii=False)
return json.dumps(json_dict, ensure_ascii=False)

if not langs:
return ""
Expand Down
11 changes: 6 additions & 5 deletions backend/fetcher/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ def json2lyrics(json_data: dict, lyrics: Lyrics) -> None:
for key, value in json_data["info"].items():
key: str
value: str | int
if key in ("source", "title", "artist", "album", "mid", "accesskey") and not isinstance(value, str):
msg = f"JSON歌词数据中包含值类型不正确的键: {key}"
raise LyricsProcessingError(msg)
if key in ("id", "duration") and not isinstance(value, int):
msg = f"JSON歌词数据中包含值类型不正确的键: {key}"

if key == "source" and isinstance(value, str):
lyrics.source = Source.__members__.get(value)
if lyrics.source is None:
msg = f"JSON歌词数据中包含不正确的值: {value}"
raise LyricsProcessingError(msg)

elif ((key in ("source", "title", "album", "mid", "accesskey") and not isinstance(value, str)) or
(key == "duration" and not isinstance(value, int)) or
(key == "artist" and not isinstance(value, str | list)) or
(key == "id" and not isinstance(value, str | int))):
msg = f"JSON歌词数据中包含值类型不正确的键: {key}"
raise LyricsProcessingError(msg)
else:
setattr(lyrics, key, value)

Expand Down
2 changes: 1 addition & 1 deletion backend/searcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def search(keyword: str,
case Source.KG:
if search_type == SearchType.LYRICS and info:
results = kg_search(keyword=keyword, info=info, search_type=SearchType.LYRICS)
results = [{**info, **item} for item in results]
results = [{**info, **item, "duration": info["duration"]} for item in results]
elif search_type != SearchType.LYRICS:
results = kg_search(keyword=keyword, search_type=search_type, page=page)
else:
Expand Down
35 changes: 19 additions & 16 deletions backend/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
from random import SystemRandom
from typing import Literal

try:
import psutil
except ImportError:
psutil = None
import psutil
from PySide6.QtCore import (
QCoreApplication,
QEventLoop,
Expand Down Expand Up @@ -76,6 +73,10 @@ def __init__(self, service: "LDDCService", instance_id: int, client_id: int, pid
def handle_task(self, task: dict) -> None:
...

@abstractmethod
def init(self) -> None:
...

def stop(self) -> None:
self.loop.quit()
logger.info("Service instance %s stopped", self.instance_id)
Expand All @@ -87,6 +88,7 @@ def run(self) -> None:
logger.info("Service instance %s started", self.instance_id)
self.signals.handle_task.connect(self.handle_task)
self.loop = QEventLoop()
self.init()
self.loop.exec()


Expand All @@ -95,8 +97,6 @@ def run(self) -> None:


def clean_dead_instance() -> bool:
if not psutil:
return False
to_stop = []
instance_dict_mutex.lock()
for instance_id, instance in instance_dict.items():
Expand Down Expand Up @@ -238,8 +238,10 @@ def q_server_read_client(self) -> None:
client_connection.flush()
client_connection.disconnectFromServer()
case "show":
from view.main_window import main_window
in_main_thread(main_window.show_window)
def show_main_window() -> None:
from view.main_window import main_window
main_window.show_window()
in_main_thread(show_main_window)
client_connection.write(b"message_received")
client_connection.flush()
client_connection.disconnectFromServer()
Expand Down Expand Up @@ -337,7 +339,7 @@ def __init__(self, service: LDDCService, instance_id: int, json_data: dict, clie
# 任务ID 用于防止旧任务的结果覆盖新任务的结果
self.taskid = 0

def run(self) -> None:
def init(self) -> None:
# 初始化界面
in_main_thread(self.init_widget)
if "name" in self.client_info and "repo" in self.client_info and "ver" in self.client_info:
Expand Down Expand Up @@ -366,7 +368,6 @@ def run(self) -> None:
self.widget.menu.action_unlink_lyrics.triggered.connect(self.unlink_lyrics)

cfg.desktop_lyrics_changed.connect(self.cfg_changed_slot)
super().run()

def init_widget(self) -> None:
"""初始化界面(主线程)"""
Expand Down Expand Up @@ -426,9 +427,8 @@ def handle_task(self, task: dict) -> None:
case "start":
# 开始播放
logger.debug("start")
playback_time = self.get_playback_time(task)
if playback_time is not None:
self.start_time = int(time.time() * 1000)
if (playback_time := self.get_playback_time(task)) is not None:
self.start_time = int(time.time() * 1000) - playback_time
else:
self.start_time = int(time.time() * 1000) - self.current_time
if not self.timer.isActive():
Expand Down Expand Up @@ -458,6 +458,9 @@ def handle_task(self, task: dict) -> None:
logger.error("task:chang_music, invalid data")
return

if (playback_time := self.get_playback_time(task)) is not None:
self.start_time = int(time.time() * 1000) - playback_time

self.song_info = {"title": title, "artist": artist, "album": album, "duration": duration, "song_path": song_path,
"track_number": str(track) if isinstance(track, int) else track}
# 先在关联数据库中查找
Expand Down Expand Up @@ -625,20 +628,20 @@ def set_inst(self) -> None:
if self.song_info:
self.config["inst"] = True
self.widget.new_lyrics.emit({"inst": True})
self.show_artist_title(QCoreApplication.translate("DesktopLyrics", "纯音乐,请欣赏"))
self.unlink_lyrics()
self.unlink_lyrics(QCoreApplication.translate("DesktopLyrics", "纯音乐,请欣赏"))

def set_auto_search(self, is_disable: bool | None = None) -> None:
if self.song_info:
self.config["disable_auto_search"] = is_disable if is_disable is not None else bool(not self.config.get("disable_auto_search"))
self.update_db_data()

def unlink_lyrics(self) -> None:
def unlink_lyrics(self, msg: str = "") -> None:
if self.song_info:
self.lyrics_path = None
self.lyrics = None
self.offseted_lyrics = None
self.update_db_data()
self.show_artist_title(msg)

def update_db_data(self) -> None:
local_song_lyrics.set_song(**self.song_info, lyrics_path=self.lyrics_path, config={k: v for k, v in self.config.items()
Expand Down
Loading

0 comments on commit fc52c79

Please sign in to comment.