-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #41 from romanin-rf/dev
Update 0.8.3
Showing
23 changed files
with
200 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import logging | ||
from rich.console import Console | ||
from rich.prompt import Prompt | ||
from seaplayer.plug import PluginBase | ||
from vkpymusic import Service, TokenReceiver | ||
# > Local Imports | ||
from .vkmcodec import VKMCodec | ||
from .units import ( | ||
pcheck, | ||
VKM_MAIN_PATTERN, | ||
VKM_RANGE_PATTERN | ||
) | ||
|
||
# ! Logging Disable | ||
logging.disable() | ||
|
||
# ! Vars | ||
console = Console() | ||
|
||
# ! Plugin Value Hander | ||
def vkm_value_handler(value: 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}") | ||
return values | ||
|
||
# ! Plugin Class | ||
class VKMusic(PluginBase): | ||
def exist_token(self) -> bool: | ||
if (s:=Service.parse_config()) is not None: | ||
del s | ||
return True | ||
else: | ||
return False | ||
|
||
def on_init(self) -> None: | ||
self.configurated = self.exist_token() | ||
|
||
def on_run(self) -> None: | ||
if self.configurated: | ||
self.service = Service.parse_config() | ||
else: | ||
login, password = Prompt.ask("Login"), Prompt.ask("Password", password=True) | ||
while not self.configurated: | ||
tr = TokenReceiver(login, password) | ||
if tr.auth(on_2fa=lambda: Prompt.ask("Code 2FA")): | ||
tr.save_to_config() | ||
self.configurated = True | ||
else: | ||
console.print("[red]Failed to get a token, repeat...[/red]") | ||
self.service = Service.parse_config() | ||
self.app.info(f"Service is worked: {repr(self.service)}") | ||
# ! Registration | ||
self.app.CODECS_KWARGS["vkm_service"] = self.service | ||
self.add_value_handlers(vkm_value_handler) | ||
self.add_codecs(VKMCodec) | ||
|
||
# ! Registeration | ||
__plugin__ = VKMusic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "VK Music", | ||
"name_id": "seaplayer.plugins.vk.music", | ||
"version": "0.2.0", | ||
"author": "Romanin", | ||
"description": "Music downloader from VK.", | ||
"url": "https://github.com/romanin-rf/SeaPlayer" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vkpymusic>=2.2.4 | ||
vbml>=1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from vbml import Pattern, Patcher | ||
# > Typing | ||
from typing import Optional, Dict, Any | ||
|
||
# ! VBML Objects | ||
PATCHER = Patcher() | ||
|
||
VKM_MAIN_PATTERN = Pattern("vkm://<uid:int>/<sid:int>") | ||
VKM_RANGE_PATTERN = Pattern("vkm://<uid:int>/<ssid:int>-<esid:int>") | ||
|
||
# ! For VBML methods | ||
def pcheck(pattern: Pattern, text: str) -> Optional[Dict[str, Any]]: | ||
if isinstance(data:=PATCHER.check(pattern, text), dict): | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import asyncio | ||
from vkpymusic import Service | ||
from seaplayer.codecs.URLS import URLSoundCodec | ||
from seaplayer.codecs.AnySound import AnySound | ||
# > Typing | ||
from typing import Optional, Tuple | ||
# > Local Imports | ||
from .units import PATCHER, VKM_MAIN_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") | ||
|
||
# ! Main Class | ||
class VKMCodec(URLSoundCodec): | ||
codec_name = "VKM" | ||
codec_priority = 5.999 | ||
|
||
# ! Check Methods | ||
@staticmethod | ||
def is_this_codec(url: str) -> bool: | ||
return isinstance(PATCHER.check(VKM_MAIN_PATTERN, url), dict) | ||
|
||
@staticmethod | ||
async def aio_is_this_codec(url: str) -> bool: | ||
return isinstance(PATCHER.check(VKM_MAIN_PATTERN, url), dict) | ||
|
||
# ! Main Functions | ||
def __init__( | ||
self, | ||
url: str, | ||
sound_device_id: Optional[int]=None, | ||
vkm_service: Optional[Service]=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] | ||
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 | ||
|
||
@staticmethod | ||
async def __aio_init__( | ||
url: str, | ||
sound_device_id: Optional[int]=None, | ||
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) | ||
return self | ||
|
||
# ! Properys | ||
@property | ||
def title(self) -> str: | ||
return self._title | ||
|
||
@property | ||
def artist(self) -> str: | ||
return self._artist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
class OGGCodec(AnyCodec): | ||
codec_name: str = "OGG" | ||
codec_priority: float=3.0 | ||
|
||
# ! Testing | ||
@staticmethod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters