Skip to content

Commit

Permalink
Update 0.8.9
Browse files Browse the repository at this point in the history
Merge pull request #54 from romanin-rf/dev
  • Loading branch information
romanin-rf authored Dec 21, 2023
2 parents b6606ea + 0ad36ac commit a6b8ecf
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 61 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Supports the following audio file formats: `MP3`, `OGG`, `WAV`, `FLAC`, `MIDI`.
Supports the following languages: `English`, `Русский`, `Українська`.

## Screenshots
![MainScreen-v0 8 1](https://github.com/romanin-rf/SeaPlayer/assets/60302782/84e1f498-beab-463b-ba2a-a8a109e607c0)
![ConfigurateScreen-v0 8 1](https://github.com/romanin-rf/SeaPlayer/assets/60302782/c8f0fa20-b4b8-4858-ac4a-bb8ddb8c0a39)
![Main Screen](https://github.com/romanin-rf/SeaPlayer/assets/60302782/84e1f498-beab-463b-ba2a-a8a109e607c0)
![Configurate Screen](https://github.com/romanin-rf/SeaPlayer/assets/60302782/c8f0fa20-b4b8-4858-ac4a-bb8ddb8c0a39)

## Using
```shell
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Version | Date | Tag | Changelog |
| ------- | ---- | --- | --------- |
| [v0.8.9](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.9) | 21.12.2023 | **HOTFIX** | - Fixed is `TypeError` in `AnySound.from_url`<br>- Update `VKMusic` plugin to **v0.4.0** |
| [v0.8.8](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.8) | 21.12.2023 | **HOTFIX** | - Fixed critical error: **TypeError: @deprecated decorator with non-None category must be applied to a class or callable, not <staticmethod object>** |
| [v0.8.7](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.7) | 21.12.2023 | **DEPRECATED** | - Added comments for documentation (not fully)<br>- Added API documentation (not fully)<br>- Removed `secrets`<br>- Fixed documentation |
| [v0.8.6](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.6) | 17.12.2023 | **STABLE** | - Added new methods for `seaplayer.plug.pluginloader.PluginLoaderConfigManager`: **remove_plugin** & **remove_plugin_by_name_id**<br>- Added new command for `seaplug`: **unload**<br>- Added version message for `seaplug`<br>- Fixed typing for: `seaplayer.plug.pluginloader.PluginLoader.search_plugins_paths` & `seaplayer.plug.pluginloader.PluginLoader.aio_search_plugins_paths`<br>- Replaced option `--recreate` with `--overwrite` in `seaplayer.plug.cli.cli.creating`<br>- Replaced option `--rewrite` with `--overwrite` in `seaplayer.plug.cli.cli.loading` |
Expand Down
1 change: 1 addition & 0 deletions docs-source/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Version | Date | Tag | Changelog |
| ------- | ---- | --- | --------- |
| [v0.8.9](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.9) | 21.12.2023 | **HOTFIX** | - Fixed is `TypeError` in `AnySound.from_url`<br>- Update `VKMusic` plugin to v0.4.0 |
| [v0.8.8](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.8) | 21.12.2023 | **HOTFIX** | - Fixed critical error: **TypeError: @deprecated decorator with non-None category must be applied to a class or callable, not <staticmethod object>** |
| [v0.8.7](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.7) | 21.12.2023 | **DEPRECATED** | - Added comments for documentation (not fully)<br>- Added API documentation (not fully)<br>- Removed `secrets`<br>- Fixed documentation |
| [v0.8.6](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.6) | 17.12.2023 | **STABLE** | - Added new methods for `seaplayer.plug.pluginloader.PluginLoaderConfigManager`: **remove_plugin** & **remove_plugin_by_name_id**<br>- Added new command for `seaplug`: **unload**<br>- Added version message for `seaplug`<br>- Fixed typing for: `seaplayer.plug.pluginloader.PluginLoader.search_plugins_paths` & `seaplayer.plug.pluginloader.PluginLoader.aio_search_plugins_paths`<br>- Replaced option `--recreate` with `--overwrite` in `seaplayer.plug.cli.cli.creating`<br>- Replaced option `--rewrite` with `--overwrite` in `seaplayer.plug.cli.cli.loading` |
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,12 @@ <h1 id="changelog">Changelog<a class="headerlink" href="#changelog" title="Perma
</thead>
<tbody>
<tr>
<td><a href="https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.9">v0.8.9</a></td>
<td>21.12.2023</td>
<td><strong>HOTFIX</strong></td>
<td>- Fixed is <code>TypeError</code> in <code>AnySound.from_url</code><br>- Update <code>VKMusic</code> plugin to v0.4.0</td>
</tr>
<tr>
<td><a href="https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.8">v0.8.8</a></td>
<td>21.12.2023</td>
<td><strong>HOTFIX</strong></td>
Expand Down
2 changes: 1 addition & 1 deletion docs/search/search_index.json

Large diffs are not rendered by default.

Binary file modified docs/sitemap.xml.gz
Binary file not shown.
26 changes: 19 additions & 7 deletions plugins/VKMusic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,35 @@
from seaplayer.objects import PopUpWindow, WaitButton
from vkpymusic import Service, TokenReceiverAsync
# > Typing
from typing import Tuple
from typing import Optional, Tuple, List
# > Local Imports
from .vkmcodec import VKMCodec
from .units import (
pcheck,
VKM_RANGE_PATTERN
pget,
VKM_RANGE_SUID_PATTERN,
VKM_TEXT_PATTERN,
VKM_TEXT_RANGE_PATTERN,
)

# ! Logging Disable
logging.disable()

# ! Plugin Class
class VKMusic(PluginBase):
def vkm_value_handler(self, value: str):
def vkm_value_handler(self, value: str) -> List[str]:
values = []
if (d:=pcheck(VKM_RANGE_PATTERN, value)) is not None:
for i in range(d['ssid'], d['esid']):
values.append(f"vkm://{d['uid']}/{i}")
if self.service is not None:
# "vkm://users/<uid:int>:<ssid:int>-<esid:int>"
if (d:=pget(VKM_RANGE_SUID_PATTERN, value)) is not None:
for sid in range(d['ssid'], d['esid']):
values.append(f"vkm://users/{d['uid']}:{sid}") # > "vkm://users/<uid:int>:<sid:int>"
# "vkm://songs:<text>:<count:int>"
elif (d:=pget(VKM_TEXT_RANGE_PATTERN, value)) is not None:
for offset in range(d['count']):
values.append(f"vkm://songs:{d['text']}:1:{offset}") # > "vkm://songs:<text>:<count:int>:<offset:int>"
# "vkm://songs:<text>"
elif (d:=pget(VKM_TEXT_PATTERN, value)) is not None:
values.append(f"vkm://songs:{d['text']}:1:0") # > "vkm://songs:<text>:<count:int>:<offset:int>"
return values

def exist_token(self) -> bool:
Expand Down Expand Up @@ -102,6 +113,7 @@ async def __init_service__(self) -> None:
self.add_codecs(VKMCodec)

def on_init(self) -> None:
self.service: Optional[Service] = None
self.configurated = self.exist_token()

async def on_ready(self):
Expand Down
2 changes: 1 addition & 1 deletion plugins/VKMusic/info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "VK Music",
"name_id": "seaplayer.plugins.vk.music",
"version": "0.3.1",
"version": "0.4.0",
"author": "Romanin",
"description": "Music downloader from VK.",
"url": "https://github.com/romanin-rf/SeaPlayer"
Expand Down
17 changes: 13 additions & 4 deletions plugins/VKMusic/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
# ! VBML Objects
PATCHER = Patcher()

VKM_MAIN_PATTERN = Pattern("vkm://<uid:int>/<sid:int>")
VKM_RANGE_PATTERN = Pattern("vkm://<uid:int>/<ssid:int>-<esid:int>")
VKM_SUID_PATTERN = Pattern("vkm://users/<uid:int>:<sid:int>") # ! vkmcodec
VKM_RANGE_SUID_PATTERN = Pattern("vkm://users/<uid:int>:<ssid:int>-<esid:int>") # > vkm_value_handler
VKM_TEXT_PATTERN = Pattern("vkm://songs:<text>") # > vkm_value_handler
VKM_TEXT_RANGE_PATTERN = Pattern("vkm://songs:<text>:<count:int>") # > vkm_value_handler
VKM_TEXT_RANGE_OFFSET_PATTERN = Pattern("vkm://songs:<text>:<count:int>:<offset:int>") # ! vkmcodec

# ! For VBML methods
def pcheck(pattern: Pattern, text: str) -> Optional[Dict[str, Any]]:
def pget(pattern: Pattern, text: str) -> Optional[Dict[str, Any]]:
if isinstance(data:=PATCHER.check(pattern, text), dict):
return data
return data

def pcheck(pattern: Pattern, text: str) -> bool:
return isinstance(PATCHER.check(pattern, text), dict)

def pchecks(text: str, *patterns: Pattern) -> bool:
return max([pcheck(pattern, text) for pattern in patterns])
46 changes: 27 additions & 19 deletions plugins/VKMusic/vkmcodec.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import asyncio
from vkpymusic import Service
from vkpymusic import Service, Song
from seaplayer.codecs.URLS import URLSoundCodec
from seaplayer.codecs.AnySound import AnySound
# > Typing
from typing import Optional, Tuple
from typing import Optional, List
# > Local Imports
from .units import PATCHER, VKM_MAIN_PATTERN
from .units import (
pget,
pchecks,
VKM_SUID_PATTERN,
VKM_TEXT_RANGE_OFFSET_PATTERN
)

# ! Methods
def parse_vkm(url: str) -> Tuple[int, int]:
d = PATCHER.check(VKM_MAIN_PATTERN, url)
if not isinstance(d, dict):
raise RuntimeError("The values from the 'url' could not be parsed.")
return d.get("uid"), d.get("sid")
def get_song(service: Service, value: str) -> Optional[Song]:
songs: List[Song] = []
if (d:=pget(VKM_SUID_PATTERN, value)) is not None: # "vkm://users/<uid:int>:<sid:int>"
songs += service.get_songs_by_userid(d['uid'], 1, d['sid'])
elif (d:=pget(VKM_TEXT_RANGE_OFFSET_PATTERN, value)) is not None: # "vkm://songs:<text>:<count:int>:<offset:int>"
songs += service.search_songs_by_text(d['text'], d['count'], d['offset'])
return songs[0] if len(songs) > 0 else None

# ! Main Class
class VKMCodec(URLSoundCodec):
Expand All @@ -21,30 +28,31 @@ class VKMCodec(URLSoundCodec):

# ! Check Methods
@staticmethod
def is_this_codec(url: str) -> bool:
return isinstance(PATCHER.check(VKM_MAIN_PATTERN, url), dict)
def is_this_codec(value: str) -> bool:
return pchecks(value, VKM_SUID_PATTERN, VKM_TEXT_RANGE_OFFSET_PATTERN)

@staticmethod
async def aio_is_this_codec(url: str) -> bool:
return isinstance(PATCHER.check(VKM_MAIN_PATTERN, url), dict)
async def aio_is_this_codec(value: str) -> bool:
return pchecks(value, VKM_SUID_PATTERN, VKM_TEXT_RANGE_OFFSET_PATTERN)

# ! Main Functions
def __init__(
self,
url: str,
sound_device_id: Optional[int]=None,
vkm_service: Optional[Service]=None,
sound_device_id: Optional[int]=None,
aio_init: bool=False,
**kwargs
) -> None:
if vkm_service is None:
raise RuntimeError("The 'service' argument is None.")
uid, sid = parse_vkm(url)
self.song = vkm_service.get_songs_by_userid(uid, 1, sid)[0]
raise RuntimeError("The VKM service has not been initialized.")
self.song = get_song(vkm_service, url)
if self.song is None:
raise RuntimeError("The sound could not be retrieved.")
self._title = (self.song.title if (len(self.song.title) > 0) else None) if isinstance(self.song.title, str) else None
self._artist = (self.song.artist if (len(self.song.artist) > 0) else None) if isinstance(self.song.artist, str) else None
super().__init__(self.song.url, sound_device_id, aio_init, **kwargs)
self.name = url
self.name = "<hidden>"

@staticmethod
async def __aio_init__(
Expand All @@ -53,8 +61,8 @@ async def __aio_init__(
vkm_service: Optional[Service]=None,
**kwargs
):
self = VKMCodec(url, sound_device_id, vkm_service, aio_init=True)
self._sound = await asyncio.to_thread(AnySound.from_url, self.song.url, device_id=sound_device_id)
self = VKMCodec(url, vkm_service=vkm_service, sound_device_id=sound_device_id, aio_init=True)
self._sound = await asyncio.to_thread(AnySound.from_url, self.song.url, device_id=sound_device_id, **kwargs)
return self

# ! Properys
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.8.8"
version = "0.8.9"
description = "SeaPlayer is a player that works in the terminal."
homepage = "https://romanin-rf.github.io/SeaPlayer"
repository = "https://github.com/romanin-rf/SeaPlayer"
Expand Down
32 changes: 9 additions & 23 deletions seaplayer/codecs/AnySound.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import subprocess
from tempfile import mkstemp
# > IO's
from urlopen2 import URLFile
from urlopen2 import URLFile, AsyncURLFile
# > Sound Works
from playsoundsimple import Sound
from playsoundsimple.sound import FPType, getfp
Expand Down Expand Up @@ -70,31 +70,17 @@ def from_midi(
return AnySound(npath, **{"is_temp": True, **kwargs})

@staticmethod
def from_url(
url: str,
download_buffer_size: int=65536,
**kwargs
):
def from_url(url: str, **kwargs):
path = mkstemp(suffix=".bin")[1]

with URLFile(url) as urlfile:
with open(path, "wb") as tempfile:
while len(data:=urlfile.read(download_buffer_size)) != 0:
tempfile.write(data)

with open(path, "wb") as tempfile:
with URLFile(url, tempfile) as urlfile:
urlfile.fulling()
return AnySound(path, is_temp=True, **kwargs)

@staticmethod
async def aio_from_url(
url: str,
download_buffer_size: int=65536,
**kwargs
):
async def aio_from_url(url: str, **kwargs):
path = mkstemp(suffix=".bin")[1]

with URLFile(url) as urlfile:
async with aiofiles.open(path, "wb") as tempfile:
while len(data:=urlfile.read(download_buffer_size)) != 0:
await tempfile.write(data)

async with aiofiles.open(path, "wb") as tempfile:
async with AsyncURLFile(url, tempfile) as urlfile:
await urlfile.fulling()
return AnySound(path, is_temp=True, **kwargs)
4 changes: 2 additions & 2 deletions seaplayer/seaplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,14 @@ async def add_sounds_to_list(self) -> None:
try:
sound: CodecBase = await codec.__aio_init__(value, **self.CODECS_KWARGS)
except Exception as e:
self.exception(e)
sound = None
raise e
else:
try:
sound: CodecBase = codec(value, **self.CODECS_KWARGS)
except Exception as e:
self.exception(e)
sound = None
raise e
if sound is not None:
if not await self.music_list_view.music_list.aio_exists_sha1(sound):
await self.music_list_view.aio_add_sound(sound)
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.8.8"
__version__ = "0.8.9"
__author__ = "Romanin"
__email__ = "[email protected]"
__url__ = "https://github.com/romanin-rf/SeaPlayer"
Expand Down

0 comments on commit a6b8ecf

Please sign in to comment.