From b27c816047ba052768e4fa517105895bbe70be92 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 22 Aug 2023 20:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A8=E6=80=81=E8=AF=BB=E5=8F=96mpd?= =?UTF-8?q?=E7=9A=84=E6=AD=8C=E6=9B=B2=E7=9B=AE=E5=BD=95=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 18 ++++++++++++++++-- ui/image_button.py | 2 ++ ui/timebar.py | 2 ++ window.py | 46 +++++++++++++++++++++++++--------------------- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index 3f580e4..f3dcf42 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import gi, sys, os, threading, time +import gi, sys, os, threading, time, re # import dbus # import dbus.service, dbus.mainloop.glib from pprint import pprint as print @@ -16,6 +16,7 @@ from about_app import AboutWindow from mpd.base import MPDClient app_id = 'fun.wkit.sonist' +home_dir = os.getenv('HOME') def run_async(func): @@ -27,6 +28,17 @@ def run_async(func): return wrapper +def get_music_dir(): + with open(f'{home_dir}/.mpd/mpd.conf', 'r') as f: + data = f.read() + + matches = re.search('music_directory\s*"(.*)"', data).groups() + if len(matches) > 0: + return matches[0] + + return '/data/music' + + class Application(Gtk.Application): __gsignals__ = { @@ -44,6 +56,8 @@ class Application(Gtk.Application): self.mpd = MPDClient() + self.music_dir = get_music_dir() + self.connect('window-removed', self.on_window_removed) @@ -97,7 +111,7 @@ class Application(Gtk.Application): self.about = AboutWindow() self.add_window(self.window) self.window.show_all() - self.about.show_all() + # self.about.show_all() self.ping() diff --git a/ui/image_button.py b/ui/image_button.py index 6840d47..acd3c65 100644 --- a/ui/image_button.py +++ b/ui/image_button.py @@ -35,6 +35,8 @@ class ImageButton(Gtk.Button): }} #ImageButton:hover {{ background-color: rgba(255,255,255,.1); + outline: transparent; + box-shadow:none; }} """ css_provider.load_from_data(style.encode('UTF-8')) diff --git a/ui/timebar.py b/ui/timebar.py index 6ea4c60..ed91599 100644 --- a/ui/timebar.py +++ b/ui/timebar.py @@ -32,8 +32,10 @@ class Timebar(Gtk.Fixed): self.curr = Gtk.Label() self.duration = Gtk.Label() + self.curr.set_name('text') self.duration.set_justify(Gtk.Justification.RIGHT) self.duration.set_xalign(1) + self.duration.set_name('text') self.slider.connect('change-value', self.on_timeupdate) diff --git a/window.py b/window.py index 742db05..95e6ec3 100644 --- a/window.py +++ b/window.py @@ -80,6 +80,7 @@ class SonistWindow(Gtk.Window): # self.title_box = TextBox(256, 20) self.title_box = Gtk.Label() + self.title_box.set_name('text') self.title_box.set_text('mpd loading...') layout.put(self.title_box, 27, 244) @@ -129,6 +130,9 @@ class SonistWindow(Gtk.Window): background-size: 100% 100%; background-position: center; }} + #text {{ + color: #f2f5fc; + }} """ # 加载CSS样式 css_provider = Gtk.CssProvider() @@ -240,33 +244,33 @@ class SonistWindow(Gtk.Window): elif self.stat.get('random') == '1': self.ctrl_box.toggle_mode_btn(mode = 'random') - - # 更新歌曲信息 - self.title_box.set_text("%s - %s" % (song.get('artist'), song.get('title'))) - self.update_playtime() + if played != 'stop': + # 更新歌曲信息 + self.title_box.set_text("%s - %s" % (song.get('artist'), song.get('title'))) + self.update_playtime() - filepath = f"./album/{song['title']}.png" - songpath = f"/data/music/{song['file']}" + filepath = f"./album/{song['title']}.png" + songpath = f"{self.app.music_dir}/{song['file']}" - if os.path.isfile(filepath): - self.update_album(filepath) - else: - - id3 = mutagen.File(songpath) + if os.path.isfile(filepath): + self.update_album(filepath) + else: + + id3 = mutagen.File(songpath) - try: - if id3.tags.get('APIC:'): - pic = id3.tags['APIC:'] - elif len(id3.pictures) > 0: - pic = id3.pictures[0] + try: + if id3.tags.get('APIC:'): + pic = id3.tags['APIC:'] + elif len(id3.pictures) > 0: + pic = id3.pictures[0] - if pic is not None: - album = pic_to_pixbuf(pic) - self.update_album(album) - except: - pass + if pic is not None: + album = pic_to_pixbuf(pic) + self.update_album(album) + except: + pass def update_album(self, filepath):