优化mpd未配置时的读取异常; 降级python语法, 兼容更低版本的python3

master 1.0.2
yutent 2023-08-26 23:07:43 +08:00
parent 3329e3ed8f
commit 5b314fd899
7 changed files with 97 additions and 97 deletions

View File

@ -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

2
debian/control vendored
View File

@ -1,5 +1,5 @@
Package: sonist
Version: 1.0.1
Version: 1.0.2
Section: X11
Architecture: all
Author: Yutent

View File

@ -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([

View File

@ -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):

View File

@ -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'

View File

@ -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()

View File

@ -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