Did some refactor, add YouTube as search variant

This commit is contained in:
BarsTiger
2023-10-25 15:48:07 +03:00
parent 6959853d87
commit 7380beeabb
28 changed files with 265 additions and 117 deletions

View File

@@ -0,0 +1 @@
pass

View File

@@ -0,0 +1 @@
from .song import BaseSongItem

View File

@@ -0,0 +1,21 @@
from attrs import define
@define
class BaseSongItem:
name: str
id: str
artists: list[str]
preview_url: str | None
thumbnail: str
@property
def all_artists(self):
return ', '.join(self.artists)
@property
def full_name(self):
return f"{self.all_artists} - {self.name}"
def __str__(self):
return self.full_name

View File

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

View File

@@ -2,43 +2,25 @@ from attrs import define
from .driver import DeezerDriver
from ..common.song import BaseSongItem
@define
class SongItem:
name: str
id: int
id_s: str
artist: str
preview_url: str | None
thumbnail: str
class SongItem(BaseSongItem):
@classmethod
def from_deezer(cls, song_item: dict):
return cls(
name=song_item['title'],
id=song_item['id'],
id_s=str(song_item['id']),
artist=song_item['artist']['name'],
id=str(song_item['id']),
artists=[song_item['artist']['name']],
preview_url=song_item.get('preview'),
thumbnail=song_item['album']['cover_medium']
)
@property
def full_name(self):
return f"{self.artist} - {self.name}"
def __str__(self):
return self.full_name
@define
class FullSongItem:
name: str
id: str
artists: list[str]
preview_url: str | None
class FullSongItem(BaseSongItem):
duration: int
thumbnail: str
track_dict: dict
@classmethod
@@ -60,17 +42,6 @@ class FullSongItem:
track_dict=song_item
)
@property
def all_artists(self):
return ', '.join(self.artists)
@property
def full_name(self):
return f"{self.all_artists} - {self.name}"
def __str__(self):
return self.full_name
@define
class Songs(object):

View File

@@ -1,15 +1,11 @@
from attrs import define
import spotipy
from ..common.song import BaseSongItem
@define
class SongItem:
name: str
id: str
artists: list[str]
preview_url: str | None
thumbnail: str
class SongItem(BaseSongItem):
@classmethod
def from_spotify(cls, song_item: dict):
return cls(
@@ -21,17 +17,6 @@ class SongItem:
thumbnail=song_item['album']['images'][1]['url']
)
@property
def all_artists(self):
return ', '.join(self.artists)
@property
def full_name(self):
return f"{self.all_artists} - {self.name}"
def __str__(self):
return f"{', '.join(self.artists)} - {self.name}"
@define
class Songs(object):

View File

@@ -5,13 +5,12 @@ from .downloader import Downloader, YouTubeBytestream
from typing import Awaitable
from ..common.song import BaseSongItem
@define
class SongItem:
name: str
id: str
artists: list[str]
thumbnail: str
class SongItem(BaseSongItem):
preview_url: None = None
@classmethod
def from_youtube(cls, song_item: dict):
@@ -22,16 +21,14 @@ class SongItem:
thumbnail=song_item['thumbnails'][1]['url']
)
@property
def all_artists(self):
return ', '.join(self.artists)
@property
def full_name(self):
return f"{self.all_artists} - {self.name}"
def __str__(self):
return self.full_name
@classmethod
def from_details(cls, details: dict):
return cls(
name=details['title'],
id=details['videoId'],
artists=details['author'].split(' & '),
thumbnail=details['thumbnail']['thumbnails'][1]['url']
)
def to_bytestream(self) -> Awaitable[YouTubeBytestream]:
return Downloader.from_id(self.id).to_bytestream()
@@ -58,4 +55,4 @@ class Songs(object):
if r is None:
return None
return SongItem.from_youtube(r)
return SongItem.from_details(r['videoDetails'])