Add deezer as default search

This commit is contained in:
BarsTiger
2023-10-24 23:19:09 +03:00
parent 495202d949
commit 4c7a885665
16 changed files with 155 additions and 42 deletions

View File

@@ -16,6 +16,7 @@ class Db(object):
self.config = DBDict('config')
self.inline = DBDict('inline')
self.spotify = DBDict('spotify')
self.deezer = DBDict('deezer')
async def write(self):
await self.config.write()

View File

@@ -1,4 +1,5 @@
from .deezer import Deezer
from .downloader import DeezerBytestream
from bot.utils.config import config
@@ -6,4 +7,4 @@ deezer = Deezer(
arl=config.tokens.deezer.arl,
)
__all__ = ['deezer']
__all__ = ['deezer', 'DeezerBytestream']

View File

@@ -33,19 +33,19 @@ class DeezerBytestream:
@define
class Downloader:
driver: DeezerDriver
song_id: int
song_id: str
track: dict
song: FullSongItem
@classmethod
async def build(
cls,
song_id: int,
song_id: str,
driver: DeezerDriver
):
track = await driver.reverse_get_track(song_id)
return cls(
song_id=song_id,
song_id=str(song_id),
driver=driver,
track=track['results'],
song=await FullSongItem.from_deezer(track)
@@ -91,7 +91,7 @@ class Downloader:
class DownloaderBuilder:
driver: DeezerDriver
async def from_id(self, song_id: int):
async def from_id(self, song_id: str):
return await Downloader.build(
song_id=song_id,
driver=self.driver

View File

@@ -16,11 +16,11 @@ class DeezerDriver:
return data
async def reverse_get_track(self, track_id: int | str):
async def reverse_get_track(self, track_id: str):
return await self.engine.call_api(
'song.getData',
params={
'SNG_ID': str(track_id)
'SNG_ID': track_id
}
)

View File

@@ -7,6 +7,7 @@ from .driver import DeezerDriver
class SongItem:
name: str
id: int
id_s: str
artist: str
preview_url: str | None
thumbnail: str
@@ -16,6 +17,7 @@ class SongItem:
return cls(
name=song_item['title'],
id=song_item['id'],
id_s=str(song_item['id']),
artist=song_item['artist']['name'],
preview_url=song_item.get('preview'),
thumbnail=song_item['album']['cover_medium']
@@ -32,11 +34,12 @@ class SongItem:
@define
class FullSongItem:
name: str
id: int
id: str
artists: list[str]
preview_url: str | None
duration: int
thumbnail: str
track_dict: dict
@classmethod
async def from_deezer(cls, song_item: dict):
@@ -53,7 +56,8 @@ class FullSongItem:
else None),
thumbnail=f'https://e-cdns-images.dzcdn.net/images/cover/'
f'{song_item["ALB_PICTURE"]}/320x320.jpg',
duration=int(song_item['DURATION'])
duration=int(song_item['DURATION']),
track_dict=song_item
)
@property
@@ -83,7 +87,7 @@ class Songs(object):
async def search_one(self, query: str) -> SongItem | None:
return (await self.search(query, limit=1) or [None])[0]
async def from_id(self, song_id: int) -> FullSongItem | None:
async def from_id(self, song_id: str) -> FullSongItem | None:
r = await self.driver.reverse_get_track(song_id)
if r is None:

View File

@@ -63,9 +63,9 @@ class ChunkDecrypter:
cipher: Cipher
@classmethod
def from_track_id(cls, track_id: int):
def from_track_id(cls, track_id: str):
cipher = Cipher(
algorithms.Blowfish(get_blowfish_key(str(track_id))),
algorithms.Blowfish(get_blowfish_key(track_id)),
modes.CBC(bytes([i for i in range(8)])),
default_backend()
)