More functionality added included playlist management.

This commit is contained in:
Storm Dragon
2025-12-15 22:25:07 -05:00
parent 555ca0bba9
commit 5507aa8faa
6 changed files with 800 additions and 41 deletions

View File

@@ -257,6 +257,42 @@ class SubsonicClient:
genresData = response.get('genres', {})
return [Genre.fromDict(g) for g in genresData.get('genre', [])]
def getAlbumList(self, listType: str, size: int = 20, offset: int = 0,
musicFolderId: str = None, genre: str = None,
fromYear: int = None, toYear: int = None) -> List[Album]:
"""
Get a list of albums by criteria (newest, frequent, recent, random, highest, alphabetical).
Args:
listType: Album list type (e.g., 'newest', 'frequent', 'recent', 'random', 'highest')
size: Number of albums to return
offset: Offset for pagination
musicFolderId: Optional folder filter
genre: Optional genre filter
fromYear: Optional starting year
toYear: Optional ending year
Returns:
List of Album objects
"""
params = {
'type': listType,
'size': size,
'offset': offset
}
if musicFolderId:
params['musicFolderId'] = musicFolderId
if genre:
params['genre'] = genre
if fromYear:
params['fromYear'] = fromYear
if toYear:
params['toYear'] = toYear
response = self._makeRequest('getAlbumList2', params)
albumsData = response.get('albumList2', {})
return [Album.fromDict(a) for a in albumsData.get('album', [])]
def getSongsByGenre(self, genre: str, count: int = 100, offset: int = 0) -> List[Song]:
"""
Get songs by genre
@@ -518,6 +554,52 @@ class SubsonicClient:
'songs': [Song.fromDict(s) for s in starredData.get('song', [])]
}
# ==================== Recommendations ====================
def getTopSongs(self, artist: str, count: int = 50) -> List[Song]:
"""
Get top songs for an artist
Args:
artist: Artist name
count: Number of songs to return
Returns:
List of Song objects
"""
if not artist:
return []
params = {'artist': artist, 'count': count}
response = self._makeRequest('getTopSongs', params)
topData = response.get('topSongs', {})
return [Song.fromDict(s) for s in topData.get('song', [])]
def getSimilarSongs(self, songId: str, count: int = 50) -> List[Song]:
"""
Get songs similar to a given song
Args:
songId: ID of the seed song
count: Number of songs to return
"""
if not songId:
return []
params = {'id': songId, 'count': count}
response = self._makeRequest('getSimilarSongs2', params)
data = response.get('similarSongs2', {})
return [Song.fromDict(s) for s in data.get('song', [])]
def getNowPlaying(self) -> List[Song]:
"""
Get songs currently being played by all users
Returns:
List of Song objects
"""
response = self._makeRequest('getNowPlaying')
nowPlayingData = response.get('nowPlaying', {})
return [Song.fromDict(s) for s in nowPlayingData.get('entry', [])]
# ==================== Lyrics ====================
def getLyrics(self, artist: str = None, title: str = None) -> Optional[str]: