Skip to content

Commit

Permalink
Add the adjustment function of ms digit count in LRC lyrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chenmozhijin committed Apr 24, 2024
1 parent ab94bcd commit 0efd00b
Show file tree
Hide file tree
Showing 11 changed files with 1,700 additions and 1,630 deletions.
7 changes: 7 additions & 0 deletions LDDC.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ def closeEvent(self, event: QCloseEvent) -> None:
def connect_signals(self) -> None:
self.settings_widget.lyrics_order_listWidget.droped.connect(
self.search_widget.update_preview_lyric) # 修改歌词顺序时更新预览
self.settings_widget.lyrics_order_listWidget.droped.connect(
self.encrypted_lyrics_widget.update_lyrics())
self.settings_widget.lyrics_order_listWidget.droped.connect(
self.encrypted_lyrics_widget.change_lyrics_type)

self.settings_widget.lrc_ms_digit_count_spinBox.valueChanged.connect(
self.search_widget.update_preview_lyric)
self.settings_widget.lrc_ms_digit_count_spinBox.valueChanged.connect(
self.encrypted_lyrics_widget.update_lyrics)

self.about_widget.checkupdate_pushButton.clicked.connect(lambda: self.check_update(False))

def check_update(self, is_auto: bool) -> None:
Expand Down
Binary file modified res/i18n/LDDC_en.qm
Binary file not shown.
309 changes: 157 additions & 152 deletions res/i18n/LDDC_en.ts

Large diffs are not rendered by default.

2,939 changes: 1,473 additions & 1,466 deletions res/resource_rc.py

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions ui/settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>LRC歌词毫秒位数</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="lrc_ms_digit_count_spinBox">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>3</number>
</property>
<property name="value">
<number>3</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
Expand Down
20 changes: 20 additions & 0 deletions ui/settings_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
QPushButton,
QSizePolicy,
QSpacerItem,
QSpinBox,
QTextBrowser,
QVBoxLayout,
)
Expand Down Expand Up @@ -120,6 +121,24 @@ def setupUi(self, settings):

self.verticalLayout_6.addWidget(self.auto_select_checkBox)

self.horizontalLayout_7 = QHBoxLayout()
self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
self.label_6 = QLabel(self.groupBox_2)
self.label_6.setObjectName(u"label_6")

self.horizontalLayout_7.addWidget(self.label_6)

self.lrc_ms_digit_count_spinBox = QSpinBox(self.groupBox_2)
self.lrc_ms_digit_count_spinBox.setObjectName(u"lrc_ms_digit_count_spinBox")
self.lrc_ms_digit_count_spinBox.setMinimum(2)
self.lrc_ms_digit_count_spinBox.setMaximum(3)
self.lrc_ms_digit_count_spinBox.setValue(3)

self.horizontalLayout_7.addWidget(self.lrc_ms_digit_count_spinBox)


self.verticalLayout_6.addLayout(self.horizontalLayout_7)

self.verticalSpacer_2 = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)

self.verticalLayout_6.addItem(self.verticalSpacer_2)
Expand Down Expand Up @@ -295,6 +314,7 @@ def retranslateUi(self, settings):

self.skip_inst_lyrics_checkBox.setText(QCoreApplication.translate("settings", u"\u4fdd\u5b58\u4e13\u8f91/\u6b4c\u5355\u6b4c\u8bcd/\u672c\u5730\u5339\u914d\u65f6\u8df3\u8fc7\u7eaf\u97f3\u4e50", None))
self.auto_select_checkBox.setText(QCoreApplication.translate("settings", u"\u6b4c\u66f2\u641c\u7d22\u6b4c\u8bcd\u65f6\u81ea\u52a8\u9009\u62e9(\u9177\u72d7\u97f3\u4e50)", None))
self.label_6.setText(QCoreApplication.translate("settings", u"LRC\u6b4c\u8bcd\u6beb\u79d2\u4f4d\u6570", None))
self.groupBox.setTitle(QCoreApplication.translate("settings", u"\u4fdd\u5b58\u8bbe\u7f6e", None))
self.textBrowser.setHtml(QCoreApplication.translate("settings", u"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
Expand Down
2 changes: 1 addition & 1 deletion update_ts.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyside6-lupdate . LDDC.py view\search.py view\get_list_lyrics.py view\encrypted_lyrics.py view\local_match.py utils\worker.py view\setting.py utils\lyrics.py utils\song_info.py -ts resource\i18n\LDDC_en.ts
pyside6-lupdate . LDDC.py view\search.py view\get_list_lyrics.py view\encrypted_lyrics.py view\local_match.py utils\worker.py view\setting.py utils\lyrics.py utils\song_info.py -ts res\i18n\LDDC_en.ts
1 change: 1 addition & 0 deletions utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, current_directory: str) -> None:
"skip_inst_lyrics": True,
"auto_select": True,
"language": "auto",
"lrc_ms_digit_count": 3,
}
self.init_db()
self.read_config()
Expand Down
9 changes: 8 additions & 1 deletion utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 沉默の金
from difflib import SequenceMatcher

from utils.data import data
from utils.enum import LyricsFormat


Expand All @@ -14,7 +15,13 @@ def get_divmod_time(ms: int) -> tuple[int, int, int, int]:

def ms2formattime(ms: int) -> str:
_h, m, s, ms = get_divmod_time(ms)
return f"{int(m):02d}:{int(s):02d}.{int(ms):03d}"
data.mutex.lock()
lrc_ms_digit_count = data.cfg["lrc_ms_digit_count"]
data.mutex.unlock()
if lrc_ms_digit_count == 2:
ms = round(ms / 10)
return f"{int(m):02d}:{int(s):02d}.{int(ms):02d}"
return f"{int(m):02d}:{int(s):02d}.{int(ms):03d}" # lrc_ms_digit_count == 3


def ms2srt_timestamp(ms: int) -> str:
Expand Down
14 changes: 4 additions & 10 deletions view/encrypted_lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def connect_signals(self) -> None:
self.romanized_checkBox.stateChanged.connect(self.change_lyrics_type)
self.original_checkBox.stateChanged.connect(self.change_lyrics_type)

self.lyricsformat_comboBox.currentIndexChanged.connect(self.change_lyrics_format)
self.offset_spinBox.valueChanged.connect(self.change_offset)
self.lyricsformat_comboBox.currentIndexChanged.connect(self.update_lyrics)
self.offset_spinBox.valueChanged.connect(self.update_lyrics)

def get_lyric_type(self) -> list:
lyric_type = []
Expand Down Expand Up @@ -109,6 +109,8 @@ def convert(self) -> None:
self.lyrics_type = "converted"

def update_lyrics(self) -> None:
if not (self.lyrics_type == "converted" and isinstance(self.lyrics, Lyrics)):
return
type_mapping = {"原文": "orig", "译文": "ts", "罗马音": "roma"}
data.mutex.lock()
lyrics_order = [type_mapping[type_] for type_ in data.cfg["lyrics_order"] if type_mapping[type_] in self.get_lyric_type()]
Expand All @@ -119,14 +121,6 @@ def change_lyrics_type(self) -> None:
if self.lyrics_type == "converted" and isinstance(self.lyrics, Lyrics) and self.lyrics.source == Source.KG:
self.update_lyrics()

def change_lyrics_format(self) -> None:
if self.lyrics_type == "converted" and isinstance(self.lyrics, Lyrics):
self.update_lyrics()

def change_offset(self) -> None:
if self.lyrics_type == "converted" and isinstance(self.lyrics, Lyrics):
self.update_lyrics()

def save(self) -> None:
match self.lyricsformat_comboBox.currentIndex():
case 0 | 1:
Expand Down
5 changes: 5 additions & 0 deletions view/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def init_ui(self) -> None:
self.language_comboBox.setCurrentIndex(1)
case "zh-Hans":
self.language_comboBox.setCurrentIndex(2)
self.lrc_ms_digit_count_spinBox.setValue(data.cfg["lrc_ms_digit_count"])

def select_default_save_path(self) -> None:
path = QFileDialog.getExistingDirectory(self, self.tr("选择默认保存路径"))
Expand Down Expand Up @@ -65,6 +66,10 @@ def connect_signals(self) -> None:

self.language_comboBox.currentIndexChanged.connect(self.language_comboBox_changed)

self.lrc_ms_digit_count_spinBox.valueChanged.connect(
lambda: data.write_config("lrc_ms_digit_count", self.lrc_ms_digit_count_spinBox.value())
)

def language_comboBox_changed(self, index: int) -> None:
match index:
case 0:
Expand Down

0 comments on commit 0efd00b

Please sign in to comment.