Skip to content

Commit

Permalink
Update 0.5.8
Browse files Browse the repository at this point in the history
- Fixed highlighting in log menu
- Removed the use of outdated pydantic functions
- New version of the "Rich Discord Status plugin" (v0.2.0)
  • Loading branch information
romanin-rf committed Nov 27, 2023
1 parent 28f21a9 commit 2d0a2ea
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion SeaPlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
if __name__ == "__main__":
try:
from seaplayer.seaplayer import SeaPlayer

app = SeaPlayer()
app.run()
app.started = False
Expand Down
17 changes: 11 additions & 6 deletions plugins/RichDiscordStatus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ def get_status(self):
else:
data["details"] = os.path.basename(self.app.currect_sound.name)
if self.app.currect_sound.paused:
data["state"] = "Paused"
data["small_image"] = "pause"
data["small_text"] = "Paused"
elif self.app.currect_sound.playing:
data["state"] = "Playing"
data["small_image"] = "play"
data["small_text"] = "Playning"
else:
data["state"] = "Stopped"
data["small_image"] = "stop"
data["small_text"] = "Stoped"
else:
data["details"] = "Sound not selected"
data["state"] = "Waiting"
data["details"] = "<unknown>"
data["small_image"] = "question"
data["small_text"] = "Sount not selected"
return data

async def __status__(self) -> None:
Expand All @@ -52,10 +56,11 @@ def on_run(self) -> None:

async def on_compose(self):
self.running = True
self.app.run_worker(self.__status__, "Discord Rich Status", "seaplayer.plugins.discord.status", thread=True)
self.thread = self.app.run_worker(self.__status__, "Rich Discord Status", "seaplayer.plugins.discord.status", thread=True)

async def on_quit(self) -> None:
self.running = False
await self.thread.wait()

# ! Registration Plugin Class
plugin_main = RichDiscordStatus
4 changes: 2 additions & 2 deletions plugins/RichDiscordStatus/info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Discord Rich Status",
"name": "Rich Discord Status",
"name_id": "seaplayer.plugins.discord.status",
"version": "0.1.0",
"version": "0.2.0",
"author": "Romanin",
"description": "Now what you are listening to will be visible to everyone in Discord.",
"url": "https://github.com/romanin-rf/SeaPlayer"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "SeaPlayer"
version = "0.5.7"
version = "0.5.8"
description = "SeaPlayer is a player that works in the terminal."
repository = "https://github.com/romanin-rf/SeaPlayer"
authors = ["Romanin <semina054@gmail.com>"]
Expand Down
6 changes: 3 additions & 3 deletions seaplayer/plug/pluginbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ class PluginInfo(BaseModel):
# ! Plugin Base Class
class PluginBase:
def __init_repr__(self) -> str:
return f"[green]{self.info.name}[/] ({repr(self.info.name_id)}) [cyan]v{self.info.version}[/cyan] [yellow]is initialized[/yellow]!"
return f"[green]{self.info.name}[/] ({repr(self.info.name_id)}) [#00ffee]v{self.info.version}[/#00ffee] [yellow]is initialized[/yellow]!"

def __init__(self, app, pl, info: PluginInfo) -> None:
self.app = app
self.pl = pl
self.info = info

# > Logs
self.app.info(self.__init_repr__())

def on_init(self): pass
def on_run(self): pass
async def on_compose(self): pass
Expand Down
37 changes: 20 additions & 17 deletions seaplayer/plug/pluginloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,26 @@ def dump(path: str, data: PluginLoaderConfigModel) -> None:
@staticmethod
def load(path: str, default_data: Dict[str, Any]) -> PluginLoaderConfigModel:
try:
return PluginLoaderConfigModel.parse_file(path)
with open(path, 'rb') as file:
data = file.read()
return PluginLoaderConfigModel.model_validate_json(data)
except:
return default_data

def refresh(self) -> None: self.dump(self.filepath, self.config)
def refresh(self) -> None:
self.dump(self.filepath, self.config)

def __init__(self, path: str) -> None:
self.filepath = Path(path)

default_data = PluginLoaderConfigModel().dict()
default_data = PluginLoaderConfigModel().model_dump()
if self.filepath.exists():
self.config = self.load(self.filepath, default_data)
config_temp = default_data.copy()
config_temp.update(self.config)
self.config = PluginLoaderConfigModel.parse_obj(config_temp)
self.config = PluginLoaderConfigModel.model_validate(config_temp)
else:
self.config = PluginLoaderConfigModel.parse_obj(default_data)
self.config = PluginLoaderConfigModel.model_validate(default_data)
self.refresh()

def exists_plugin(self, info: PluginInfo) -> bool:
Expand Down Expand Up @@ -118,7 +121,7 @@ def enable_plugin_by_name_id(self, name_id: str) -> None:
# ! Plugin Loader Class
class PluginLoader:
__title__: str = "PluginLoader"
__version__: str = "0.1.4"
__version__: str = "0.1.5"
__author__: str = "Romanin"
__email__: str = "semina054@gmail.com"

Expand Down Expand Up @@ -170,38 +173,38 @@ def search_plugins_paths():
yield info_path, init_path

@staticmethod
def load_plugin_info(path: str) -> PluginInfo: return PluginInfo.parse_file(path)
def load_plugin_info(path: str) -> PluginInfo:
with open(path, 'rb') as file:
data = file.read()
return PluginInfo.model_validate_json(data)

def on_init(self) -> None:
self.app.info(f"{self.__title__} v{self.__version__} from {self.__author__} ({self.__email__})")
self.app.info(f"{self.__title__} [#00ffee]v{self.__version__}[/#00ffee] from {self.__author__} ({self.__email__})")
plugins_paths = list(self.search_plugins_paths())
self.app.info(f"Found plugins : {repr([os.path.basename(os.path.dirname(i[0])) for i in plugins_paths])}")
for info_path, init_path in plugins_paths:
info = None
try:
info = self.load_plugin_info(info_path)

if not self.config.exists_plugin(info):
self.config.add_plugin(info)

if self.config.is_enable_plugin(info):
plugin_module = load_module(init_path)
plugin = plugin_from_module(self.app, self, info, plugin_module)

try:
plugin.on_init()
except:
self.app.info(f"Failed to do [green]`on_init`[/green] in: {plugin}")
self.app.error(f"Failed to do [green]`on_init`[/green] in: {plugin}")

self.on_plugins.append(plugin)
else:
self.off_plugins.append(info)
except Exception as e:
self.error_plugins.append( (info_path, init_path) )
if info is not None:
self.app.info(f"Failed to load plugin: {repr(info)}")
self.app.error(f"Failed to load plugin: {repr(info)}")
else:
self.app.info(f"Failed to load plugin: {repr(os.path.basename(os.path.dirname(info_path)))}")
self.app.error(f"Failed to load plugin: {repr(os.path.basename(os.path.dirname(info_path)))}")
raise e
self.app.info(f"Plugins loaded ([green]ON [/green]) : {repr(self.on_plugins)}")
self.app.info(f"Plugins loaded ([red]OFF[/red]) : {repr(self.off_plugins)}")
Expand All @@ -211,18 +214,18 @@ def on_run(self) -> None:
try:
i.on_run()
except:
self.app.info(f"Failed to do [green]`on_run`[/green] in: {i}")
self.app.error(f"Failed to do [green]`on_run`[/green] in: {i}")

async def on_compose(self) -> None:
async for i in aiter(self.on_plugins):
try:
await i.on_compose()
except:
self.app.info(f"Failed to do [green]`await on_compose`[/green] in: {i}")
self.app.error(f"Failed to do [green]`await on_compose`[/green] in: {i}")

async def on_quit(self) -> None:
async for i in aiter(self.on_plugins):
try:
await i.on_quit()
except:
self.app.info(f"Failed to do [green]`await on_quit`[/green] in: {i}")
self.app.error(f"Failed to do [green]`await on_quit`[/green] in: {i}")
2 changes: 1 addition & 1 deletion seaplayer/seaplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def update_loop_playback(self) -> None:
def compose(self) -> ComposeResult:
# * Other
self.info("---")
self.info(f"{__title__} v{__version__} from {__author__} ({__email__})")
self.info(f"{__title__} [#00ffee]v{__version__}[/#00ffee] from {__author__} ({__email__})")
self.info(f"Source : {__url__}")
self.info(f"Codecs : {repr(self.CODECS)}")
self.info(f"Config Path : {repr(self.config.filepath)}")
Expand Down
2 changes: 1 addition & 1 deletion seaplayer/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# ! Metadata
__title__ = "SeaPlayer"
__version__ = "0.5.7"
__version__ = "0.5.8"
__author__ = "Romanin"
__email__ = "semina054@gmail.com"
__url__ = "https://github.com/romanin-rf/SeaPlayer"
Expand Down

0 comments on commit 2d0a2ea

Please sign in to comment.