Skip to content

Commit

Permalink
Add getAlbumList2 endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kutu committed Apr 22, 2024
1 parent 403988d commit b36316d
Show file tree
Hide file tree
Showing 27 changed files with 1,049 additions and 107 deletions.
13 changes: 5 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.279
rev: v0.4.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: [types-requests, types-python-dateutil, pytest, responses]
36 changes: 19 additions & 17 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# TODO
- [ ] Implement missing endpoints.
- [ ] indexes mock data should use mock artist data.
- [ ] Add the `subsonic.system.check_subsonic_extension()` method.
- [ ] Improve error handling:
- [ ] Check and rewrite all docstrings taking care about raising exceptions.
- [ ] Remove unnecessary packages installed in GitHub Actions `tests` job.
- [ ] Spin up a `MkDocs` documentation.
- [ ] Add the URL in the GitHub page.

Expand Down Expand Up @@ -33,36 +35,36 @@ The final objetive of Knuckles to be a fully compatible implementation wrapper a
- [x] `getOpenSubsonicExtensions`

#### Browsing
- [x] `getMusicFolders` REMOVE?
- [ ] `getIndexes` **[MISSING]**
- [ ] `getMusicDirectory` **[MISSING]**
- [x] `getMusicFolders`
- [x] `getIndexes`
- [x] `getMusicDirectory`
- [x] `getGenres`
- [x] `getArtists`
- [x] `getArtist`
- [x] `getAlbum`
- [x] `getSong`
- [ ] `getVideos` **[MISSING]**
- [ ] `getVideoInfo` **[MISSING]**
- [ ] `getArtistInfo` **[MISSING]**
- [ ] `getVideos` **[VIDEO]**
- [ ] `getVideoInfo` **[VIDEO]**
- [ ] `getArtistInfo` **[No ID3]**
- [x] `getArtistInfo2`
- [ ] `getAlbumInfo` **[MISSING]**
- [ ] `getAlbumInfo` **[No ID3]**
- [x] `getAlbumInfo2`
- [ ] `getSimilarSongs` **[MISSING]**
- [ ] `getSimilarSongs2` **[MISSING]**
- [ ] `getTopSongs` **[MISSING]**
- [ ] `getSimilarSongs` **[No ID3]**
- [x] `getSimilarSongs2`
- [x] `getTopSongs`

#### Album/song lists
- [ ] `getAlbumList` **[MISSING]**
- [ ] `getAlbumList` **[No ID3]**
- [ ] `getAlbumList2` **[MISSING]**
- [ ] `getRandomSongs` **[MISSING]**
- [ ] `getSongsByGenre` **[MISSING]**
- [ ] `getNowPlaying` **[MISSING]**
- [ ] `getStarred` **[MISSING]**
- [ ] `getStarred` **[No ID3]**
- [ ] `getStarred2` **[MISSING]**

#### Searching
- [x] `search` (Will never be implemented, deprecated)
- [ ] `search2` **[MISSING]**
- [x] `search` _(Will never be implemented, deprecated)_
- [ ] `search2` **[No ID3]**
- [x] `search3`

#### Playlists
Expand All @@ -73,12 +75,12 @@ The final objetive of Knuckles to be a fully compatible implementation wrapper a
- [x] `deletePlaylist`

#### Media retrieval
- [x] `stream` *(Only URL handling)*
- [x] `stream` _(Only URL handling)_
- [x] `download`
- [x] `hls` *(Only URL handling)*
- [x] `hls` _(Only URL handling)_
- [x] `getCaptions`
- [x] `getCoverArt`
- [ ] `getLyrics` **[MISSING]**
- [x] `getLyrics`
- [x] `getAvatar`

#### Media annotation
Expand Down
46 changes: 23 additions & 23 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ requests = "^2.31.0"
python-dateutil = "^2.8.2"

[tool.poetry.group.dev.dependencies]
black = "^23.7.0"
mypy = "^1.4.1"
pytest = "^7.4.0"
ruff = "^0.1.2"
mypy = "^1.4.1"
types-requests = "^2.31.0.1"
types-python-dateutil = "^2.8.19.14"
responses = "^0.23.1"
ruff = "^0.0.280"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
[tool.ruff.lint]
select = ["E", "F", "I001"]

[tool.mypy]
Expand Down
31 changes: 31 additions & 0 deletions src/knuckles/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from .models.album import Album, AlbumInfo
from .models.artist import Artist, ArtistInfo
from .models.genre import Genre
from .models.index import Index
from .models.music_directory import MusicDirectory
from .models.music_folder import MusicFolder
from .models.song import Song

Expand Down Expand Up @@ -52,6 +54,21 @@ def get_music_folder(self, id_: str) -> MusicFolder | None:

return None

def get_indexes(self, music_folder_id: str, modified_since: int) -> Index:
response = self.api.json_request(
"getIndexes",
{"musicFolderId": music_folder_id, "ifModifiedSince": modified_since},
)["indexes"]

return Index(subsonic=self.subsonic, **response)

def get_music_directory(self, music_directory_id: str) -> MusicDirectory:
response = self.api.json_request(
"getMusicDirectory", {"id": music_directory_id}
)["directory"]

return MusicDirectory(subsonic=self.subsonic, **response)

def get_genres(self) -> list[Genre]:
"""Calls the "getGenres" endpoint of the API.
Expand Down Expand Up @@ -183,3 +200,17 @@ def get_artist_info(
)["artistInfo2"]

return ArtistInfo(self.subsonic, id_, **response)

def get_similar_songs(self, song_id: str, count: int | None = None) -> list[Song]:
response = self.api.json_request(
"getSimilarSongs2", {"id": song_id, "count": count}
)["similarSongs2"]["song"]

return [Song(subsonic=self.subsonic, **song) for song in response]

def get_top_songs(self, artist_name: str, max_num_of_songs: int) -> list[Song]:
response = self.api.json_request(
"getTopSongs", {"artist": artist_name, "count": max_num_of_songs}
)["topSongs"]["song"]

return [Song(subsonic=self.subsonic, **song) for song in response]
2 changes: 1 addition & 1 deletion src/knuckles/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(
message: str = (
"Unable to generate the model as it does not exist in the server"
),
*args: str
*args: str,
) -> None:
super().__init__(message, *args)

Expand Down
Loading

0 comments on commit b36316d

Please sign in to comment.