Skip to content

Commit

Permalink
Music Server: added setting whether to override the map music (#1162)
Browse files Browse the repository at this point in the history
* Music Server: added setting whether to override the map music.

* Fixed missing icon in lists + retrieving title/artist with '.
  • Loading branch information
TheMaximum committed Apr 13, 2022
1 parent 3b0f628 commit 5e934ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 16 additions & 4 deletions pyplanet/apps/contrib/music_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyplanet.apps.config import AppConfig
from pyplanet.apps.core.maniaplanet import callbacks as mp_signals
from pyplanet.contrib.command import Command
from pyplanet.contrib.setting import Setting
from .view import MusicListView
from .view import PlaylistView

Expand All @@ -27,10 +28,19 @@ def __init__(self, *args, **kwargs):
self.playlist = []
self.playlist_view = None

self.setting_override_map_music = Setting(
'override_map_music', 'Override map music', Setting.CAT_BEHAVIOUR, type=bool,
description='Whether to override the map music.',
default=True
)

async def on_start(self):
self.songs = await self.get_songs()
self.list_view = MusicListView(self)
self.playlist_view = PlaylistView(self)

await self.context.setting.register(self.setting_override_map_music)

await self.instance.command_manager.register(
Command(command='play', target=self.play_song, admin=True)
.add_param(name='songname', type=str, required=True),
Expand All @@ -39,6 +49,7 @@ async def on_start(self):
Command(command='playlist', target=self.show_playlist, admin=False),
Command(command='clearplaylist', target=self.clear_playlist, admin=True),
)

self.current_song_index = -1

async def song_list(self, player, *args, **kwargs):
Expand Down Expand Up @@ -98,7 +109,8 @@ async def map_end(self, *args, **kwargs):
new_song = self.songs[self.current_song_index + 1]
self.current_song_index += 1
try:
await self.instance.gbx('SetForcedMusic', True, new_song[0])
override_map_music = await self.setting_override_map_music.get_value()
await self.instance.gbx('SetForcedMusic', override_map_music, new_song[0])
self.current_song = new_song
except Exception as e:
await self.instance.chat(str(e))
Expand Down Expand Up @@ -143,12 +155,12 @@ async def get_tags(self, session, url):
for key, value in tags.items():
if fs.find(key.upper()) > 0:
end_of_key = fs.find(key.upper()) + len(key) + 1
end_of_value = fs.find('\\', fs.find(key.upper()))
end_of_value = fs.find('\\x', fs.find(key.upper()))
value = fs[end_of_key:end_of_value]
if value.find('(') > 0 or value.find('[') > 0:
tags[key] = re.sub(r'[^a-zA-Z\d\s\)\]]$', '', value)
tags[key] = re.sub(r'[^a-zA-Z\d\s\)\]]$', '', value).replace('\\', '')
else:
tags[key] = re.sub(r'[^a-zA-Z\d\s]*$', '', value)
tags[key] = re.sub(r'[^a-zA-Z\d\s]*$', '', value).replace('\\', '')
await response.release()
return tags

Expand Down
4 changes: 3 additions & 1 deletion pyplanet/apps/contrib/music_server/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class MusicListView(ManualListView):
title = 'Songs'
icon_style = 'Icons128*128_1'
icon_style = 'Icons128x128_1'
icon_substyle = 'Statistics'

def __init__(self, app):
Expand Down Expand Up @@ -57,6 +57,8 @@ async def action_playlist(self, player, values, song_info, *args, **kwargs):

class PlaylistView(ManualListView):
title = 'Playlist'
icon_style = 'Icons128x128_1'
icon_substyle = 'Statistics'

def __init__(self, app):
super().__init__(self)
Expand Down

0 comments on commit 5e934ea

Please sign in to comment.