diff --git a/build.sh b/build.sh index 54c7121..6141f31 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ if [ -d unpack ]; then sudo rm -rf unpack fi -version="1.0.1" +version="1.0.2" mkdir -p unpack/DEBIAN diff --git a/debian/control b/debian/control index 03dd7b8..c898296 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: sonist -Version: 1.0.1 +Version: 1.0.2 Section: X11 Architecture: all Author: Yutent diff --git a/usr/lib/sonist/about_app.py b/usr/lib/sonist/about_app.py index 18cc9cc..7a380f3 100644 --- a/usr/lib/sonist/about_app.py +++ b/usr/lib/sonist/about_app.py @@ -21,7 +21,7 @@ class AboutWindow(Gtk.AboutDialog): self.set_logo(GdkPixbuf.Pixbuf.new_from_file(image_dict['sonist'])) self.set_license_type(Gtk.License.MIT_X11) - self.set_version('1.0.1') + self.set_version('1.0.2') self.set_website('https://github.com/app-cat/sonist-gtk') self.set_website_label('官网') self.set_authors([ diff --git a/usr/lib/sonist/mpd.py b/usr/lib/sonist/mpd.py index d2a5b40..f5680f6 100644 --- a/usr/lib/sonist/mpd.py +++ b/usr/lib/sonist/mpd.py @@ -67,12 +67,12 @@ class CommandError(Exception): self.command = None self.msg = None - match = ERROR_PATTERN.match(error) - if match: - self.errno = FailureResponseCode(int(match.group("errno"))) - self.offset = int(match.group("offset")) - self.command = match.group("command") - self.msg = match.group("msg") + matches = ERROR_PATTERN.match(error) + if matches: + self.errno = FailureResponseCode(int(matches.group("errno"))) + self.offset = int(matches.group("offset")) + self.command = matches.group("command") + self.msg = matches.group("msg") class CommandListError(Exception): diff --git a/usr/lib/sonist/sonist.py b/usr/lib/sonist/sonist.py index 5385801..656e986 100755 --- a/usr/lib/sonist/sonist.py +++ b/usr/lib/sonist/sonist.py @@ -18,13 +18,16 @@ home_dir = os.getenv('HOME') def get_music_dir(): - with open(f'{home_dir}/.mpd/mpd.conf', 'r') as f: - data = f.read() + mpd_config = f'{home_dir}/.mpd/mpd.conf' - matches = re.search('music_directory\s*"(.*)"', data).groups() - if len(matches) > 0: - return matches[0] - + if os.path.isfile(mpd_config): + 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' diff --git a/usr/lib/sonist/ui/option_menu.py b/usr/lib/sonist/ui/option_menu.py index 8c4858c..9d8a4de 100644 --- a/usr/lib/sonist/ui/option_menu.py +++ b/usr/lib/sonist/ui/option_menu.py @@ -48,23 +48,22 @@ class OptionMenu(Gtk.Menu): def on_menu_select(self, item): - match(item.name): - case '首选项': - self.app.preferences.show() + if item.name == '首选项': + self.app.preferences.show() - case '窗口置顶': - self.on_top = not self.on_top - self.app.window.set_keep_above(self.on_top) - if self.on_top: - item.select() - else: - item.deselect() + elif item.name == '窗口置顶': + self.on_top = not self.on_top + self.app.window.set_keep_above(self.on_top) + if self.on_top: + item.select() + else: + item.deselect() - case '退出应用': - self.app.quit_all() + elif item.name == '退出应用': + self.app.quit_all() - case '关于播放器': - self.app.about.present() + elif item.name == '关于播放器': + self.app.about.present() diff --git a/usr/lib/sonist/window.py b/usr/lib/sonist/window.py index 8abf40f..fba1ddd 100644 --- a/usr/lib/sonist/window.py +++ b/usr/lib/sonist/window.py @@ -129,7 +129,6 @@ class SonistWindow(Gtk.Window): #ImageButton:hover {{ background-color: rgba(255,255,255,.1); outline: transparent; - box-shadow:none; }} #Slider {{ @@ -188,35 +187,34 @@ class SonistWindow(Gtk.Window): def ctrl_clicked(self, box, btn): - match(btn): - case 'play_btn': - self.toggle_play() + if btn == 'play_btn': + self.toggle_play() - case 'mode_btn': - # repeat all - if self.ctrl_box.curr_mode == 0: - self.mpd.repeat(1) - self.mpd.random(0) - self.mpd.single(0) - # random - elif self.ctrl_box.curr_mode == 1: - self.mpd.repeat(0) - self.mpd.random(1) - self.mpd.single(0) - # single - else: - self.mpd.repeat(0) - self.mpd.random(0) - self.mpd.single(1) + elif btn == 'mode_btn': + # repeat all + if self.ctrl_box.curr_mode == 0: + self.mpd.repeat(1) + self.mpd.random(0) + self.mpd.single(0) + # random + elif self.ctrl_box.curr_mode == 1: + self.mpd.repeat(0) + self.mpd.random(1) + self.mpd.single(0) + # single + else: + self.mpd.repeat(0) + self.mpd.random(0) + self.mpd.single(1) - case 'prev_btn': - self.prev_song() + elif btn == 'prev_btn': + self.prev_song() - case 'next_btn': - self.next_song() + elif btn == 'next_btn': + self.next_song() - case 'vol_btn': - self.toggle_play() + elif btn == 'vol_btn': + self.toggle_play() @@ -254,9 +252,6 @@ class SonistWindow(Gtk.Window): if is_play: self.handler.reset(image_dict['handler_a']) - # song = self.mpd.currentsong() - # 更新歌曲信息 - # self.title_box.update(f"{song.get('artist')} - {song.get('title')}") else: self.handler.reset(image_dict['handler']) @@ -286,20 +281,21 @@ class SonistWindow(Gtk.Window): # 首次启动时, 更新数据库 if first: - if self.app.config_data['auto_scan']: - self.mpd.update() - song_num = int(self.mpd.stats().get('songs')) - playlist = [it['file'] for it in self.mpd.playlistinfo()] - - # 这里只做添加, 不做删除, 重建播放列表在设置里 - if len(playlist) < song_num: - songs = self.mpd.listall() - for it in songs: - if it['file'] in playlist: - continue - self.mpd.add(it['file']) + self.mpd.update() + song_num = int(self.mpd.stats().get('songs') or 0) + playlist = [it['file'] for it in self.mpd.playlistinfo()] - self.get_mpd_stat() + self.ctrl_box.disabled = song_num == 0 + + # 这里只做添加, 不做删除, 重建播放列表在设置里 + if song_num > 0 and len(playlist) < song_num: + songs = self.mpd.listall() + for it in songs: + if it['file'] in playlist: + continue + self.mpd.add(it['file']) + + self.get_mpd_stat() self.update_play_stat(state == 'play') @@ -316,36 +312,38 @@ class SonistWindow(Gtk.Window): if state != 'stop': song = song or self.mpd.currentsong() - # 更新歌曲信息 - self.title_box.update(f"{song.get('artist')} - {song.get('title')}") - title = song['file'] - title_hex = base64.b64encode(title.encode()).hex() + if song.get('id'): + # 更新歌曲信息 + self.title_box.update(f"{song.get('artist')} - {song.get('title')}") - filepath = f"{self.app.album_cache_dir}/{title_hex}.png" - songpath = f"{self.app.music_dir}/{title}" + title = song.get('title') + title_hex = base64.b64encode(title.encode()).hex() - if os.path.isfile(filepath): - self.update_album(filepath) - else: + filepath = f"{self.app.album_cache_dir}/{title_hex}.png" + songpath = f"{self.app.music_dir}/{title}" + + if os.path.isfile(filepath): + self.update_album(filepath) + else: + + id3 = mutagen.File(songpath) + pic = None + try: + if id3.tags.get('APIC:'): + pic = id3.tags['APIC:'] + elif len(id3.pictures) > 0: + pic = id3.pictures[0] + + if pic is None: + self.update_album() + else: + album = pic_to_pixbuf(pic) + self.update_album(album) + + except Exception as err: + pass - id3 = mutagen.File(songpath) - pic = None - try: - if id3.tags.get('APIC:'): - pic = id3.tags['APIC:'] - elif len(id3.pictures) > 0: - pic = id3.pictures[0] - - if pic is None: - self.update_album() - else: - album = pic_to_pixbuf(pic) - self.update_album(album) - - except Exception as err: - pass - @idle