Skip to content

Commit

Permalink
Functional Update
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatDamon committed Mar 8, 2024
1 parent b71a2bc commit 838b8b9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
10 changes: 7 additions & 3 deletions i18n/en_US.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
}

songList = {
"songList": "Song List",
"construction": "Under Construction"
"songList": "Play List"
}

dialog = {
Expand Down Expand Up @@ -122,6 +121,7 @@
"langNameOrigial": "Name: ",
"langCode": "Language Code: ",
"langFont": "Language Font: ",
"appearancesSys": "Use the settings on current language",
"langRTL": "Default RTL Mode: ",
"appearances": "Appearances",
"colorMode": "Color Mode: ",
Expand All @@ -140,9 +140,13 @@
"defaultVolume": "Default Volume: ",
"lyrics": "Lyrics",
"lyricsDefaultVis": "Lyrics display by default",
"webMusic": "Online music",
"online": "Online",
"onlineMusic": "Online Music: ",
"inputAPI": "Enter the API URL: ",
"setToDefault": "Set to default",
"webAPIInfo": "Deployment scenarios from https://github.com/Kevin0z0/Python_NetEaseMusicAPI must be used to ensure compatibility!",
"webUpdate": "Update: ",
"onlineSys": "Use the API settings on current language",
"systemIntegration": "System integration",
"enableSMTC": "Enable SMTC (incomplete)",
"Advance": "Advance",
Expand Down
10 changes: 7 additions & 3 deletions i18n/zh_CN.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
}

songList = {
"songList": "播放列表",
"construction": "施工中"
"songList": "播放列表"
}

dialog = {
Expand Down Expand Up @@ -133,16 +132,21 @@
"green": "绿色",
"brown": "棕色",
"purple": "紫色",
"appearancesSys": "外观使用当前语言中设置",
"rtl": "从右到左模式",
"play": "播放",
"immediatelyPlay": "加载歌曲后立即播放",
"defaultLoop": "默认循环播放",
"defaultVolume": "默认音量: ",
"lyrics": "歌词",
"lyricsDefaultVis": "歌词默认显示",
"webMusic": "在线歌曲",
"online": "在线",
"onlineMusic": "在线歌曲: ",
"inputAPI": "输入 API 地址: ",
"setToDefault": "恢复默认",
"webAPIInfo": "必须使用 https://github.com/Kevin0z0/Python_NetEaseMusicAPI 的部署方案以保证兼容性!",
"webUpdate": "更新: ",
"onlineSys": "在线更新 API 使用当前语言中设置",
"systemIntegration": "系统集成",
"enableSMTC": "启用 SMTC (未完成)",
"advance": "高级",
Expand Down
10 changes: 6 additions & 4 deletions lib/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
audioTitleText = None
audioArtistText = None
audioState = None
audioStateType = None
audioLoaded = False

apiUrl = cfg.cfgData["online"][0]["onlineAPI"]
if apiUrl[-1] != '/':
Expand Down Expand Up @@ -296,15 +298,15 @@ def balanceMiddle(e):
log_init.logging.info("playAudio updated")

def stateSet(e):
global audioState
audioState = e.data
log_init.logging.info("State changed:" + e.data)
global audioStateType
audioStateType = e.data
log_init.logging.info("State changed:" + e.data)

playAudio = ft.Audio(
autoplay = False,
volume = cfg.cfgData["play"][0]["defaultVolume"] / 100,
balance = 0,
on_duration_changed = lambda e: log_init.logging.info("Duration changed:" + e.data),
on_state_changed = stateSet,
on_seek_complete = lambda _: log_init.logging.info("Seek complete"),
on_seek_complete = lambda _: log_init.logging.info("Seek complete")
)
30 changes: 23 additions & 7 deletions pages/settingsPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def colorModeWrite(e):
disabled = True
)

appearancesSystemSets_switch = ft.Switch(label = i18n.lang.sets["appearancesSys"], value = False, disabled = True)

def enableRTLWrite(e):
if rtlEnable_switch.value == True:
cfg.cfgData["appearances"][0]["rtl"] = True
Expand All @@ -135,6 +137,8 @@ def enableRTLWrite(e):
colorMode_dropd,
ft.Text(value = i18n.lang.sets["colorSchemes"]),
colorSchemes_radio,
ft.Divider(),
appearancesSystemSets_switch,
rtlEnable_switch
]
),
Expand Down Expand Up @@ -167,7 +171,7 @@ def defaultPlayInLoopWrite(e):

def defaultVolumeWrite(e):
cfg.cfgData["play"][0]["defaultVolume"] = defaultVolume_slider.value
log_init.logging.info("Set defaultVolume at play as " + onlineAPI_tf.value)
log_init.logging.info("Set defaultVolume at play as " + defaultVolume_slider.value)
cfg.saveConfig()

defaultVolume_slider = ft.Slider(min = 0, max = 100, divisions = 100, label = "{value}", value = cfg.cfgData["play"][0]["defaultVolume"], on_change_end = defaultVolumeWrite)
Expand Down Expand Up @@ -214,18 +218,30 @@ def lyricsDefaultVisibleWrite(e):
)

def onlineAPIWrite(e):
cfg.cfgData["online"][0]["onlineAPI"] = onlineAPI_tf.value
log_init.logging.info("Set onlineAPI at online as " + onlineAPI_tf.value)
cfg.cfgData["online"][0]["onlineAPI"] = onlineMusicAPI_tf.value
log_init.logging.info("Set onlineAPI at online as " + onlineMusicAPI_tf.value)
cfg.saveConfig()

onlineAPI_tf = ft.TextField(label = i18n.lang.sets["inputAPI"], value = cfg.cfgData["online"][0]["onlineAPI"], on_change = onlineAPIWrite)
onlineMusicAPI_tf = ft.TextField(label = i18n.lang.sets["inputAPI"], value = cfg.cfgData["online"][0]["onlineAPI"], on_change = onlineAPIWrite)

def setMusicAPIToDefault(e):
onlineMusicAPI_tf.value = "https://music.dsb.ink/api/"

onlineSystemSets_switch = ft.Switch(label = i18n.lang.sets["onlineSys"], value = True, disabled = True)
onlineUpdateAPI_tf = ft.TextField(label = i18n.lang.sets["inputAPI"], visible = False)

onlineSetCard = ft.Card(
content = ft.Container(
content = ft.Column(controls = [
ft.Row(controls = [ft.Icon(ft.icons.MUSIC_NOTE_OUTLINED), ft.Text(value = i18n.lang.sets["webMusic"], size = 18)]),
onlineAPI_tf,
ft.Text(value = i18n.lang.sets["webAPIInfo"], selectable = True)
ft.Row(controls = [ft.Icon(ft.icons.MUSIC_NOTE_OUTLINED), ft.Text(value = i18n.lang.sets["online"], size = 18)]),
ft.Text(value = i18n.lang.sets["onlineMusic"]),
ft.ResponsiveRow(controls = [onlineMusicAPI_tf, ft.FilledTonalButton(text = i18n.lang.sets["setToDefault"], icon = ft.icons.REFRESH_OUTLINED, on_click = setMusicAPIToDefault, disabled = True)]),
ft.Text(value = i18n.lang.sets["webAPIInfo"], selectable = True),
ft.Divider(),
ft.Text(value = i18n.lang.sets["webUpdate"]),
onlineSystemSets_switch,
ft.ResponsiveRow(controls = [onlineUpdateAPI_tf, ft.FilledTonalButton(text = i18n.lang.sets["setToDefault"], icon = ft.icons.REFRESH_OUTLINED, on_click = setMusicAPIToDefault, disabled = True, visible = False)]),
ft.Text(value = i18n.lang.sets["webAPIInfo"], selectable = True, visible = False) # need strings
]
),
padding = 15
Expand Down
20 changes: 15 additions & 5 deletions player.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import flet as ft
import platform, os, time
import platform, os

from lib import cfg
cfg.loadConfig()
Expand All @@ -15,6 +15,7 @@
lyricFile = ""
audioListShown = False
firstPlay = True
audioLoaded = None
currentDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(currentDir)

Expand Down Expand Up @@ -177,9 +178,18 @@ def readSong(audioPathTemp):
if work.audioState == True:
playOrPauseMusic(0)
if cfg.cfgData["play"][0]["immediatelyPlay"] == True:
time.sleep(0.8)
playOrPauseMusic(0)
global audioLoaded
while(True):
if audioLoaded == True:
playOrPauseMusic(0)
audioLoaded = False
break

def loadAudio(e):
global audioLoaded, audioFile, audioArtistText, audioTitleText
audioLoaded = True
log_init.logging.info("Audio loaded: " + audioFile + " => " + audioArtistText + " - " + audioTitleText)

def pickFolderResult(e: ft.FilePickerResultEvent):
allowed_extensions = ['mp3']
songList = []
Expand Down Expand Up @@ -332,7 +342,7 @@ def autoKeepAudioProgress(e):
lyricExistAndRead()
elif getReturn == True:
lyricsProcess()
if work.audioState == "completed":
if work.audioStateType == "completed":
work.resetPlay()
ctrlRowUpdate()
page.update()
Expand Down Expand Up @@ -737,7 +747,7 @@ def viewPop(e):
audioDetail = ft.Column(controls = [audioTitle, audioArtistAndAlbum, audioProgressStatus])
audioBasicInfo = ft.Container(content = ft.Row(controls = [audioCover, audioDetail]), padding = 3)
audioProgressBar = ft.Slider(min = 0, max = 1000, tooltip = lang.tooltips["audioPosition"], on_change_start = autoStopKeepAudioProgress, on_change_end = progressCtrl)
work.playAudio.on_loaded = lambda _: log_init.logging.info("Audio loaded: " + audioFile + " => " + audioArtistText + " - " + audioTitleText)
work.playAudio.on_loaded = loadAudio
work.playAudio.on_position_changed = autoKeepAudioProgress

skipPrevious_btn = ft.IconButton(
Expand Down

0 comments on commit 838b8b9

Please sign in to comment.