This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
167 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .download import download | ||
from .search import search | ||
|
||
__all__ = ["download"] | ||
__all__ = ["download", "search"] |
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,37 @@ | ||
from typing import Optional | ||
|
||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
from youtube_bz.api import musicbrainz as MusicBrainzAPI | ||
|
||
|
||
def search( | ||
query: str, | ||
verbose: bool, | ||
artist: Optional[str] = None, | ||
artistname: Optional[str] = None, | ||
): | ||
client = MusicBrainzAPI.Client() | ||
results = client.search_release(query, artistname=artistname, artist=artist) | ||
|
||
if len(results["releases"]) == 0: | ||
print("No data to display") | ||
return | ||
|
||
table = Table(title="Seach Results") | ||
table.add_column("ID") | ||
table.add_column("Title") | ||
table.add_column("Artist") | ||
table.add_column("Score") | ||
|
||
for r in results["releases"]: | ||
table.add_row( | ||
f'[bold blue][link=https://musicbrainz.org/release/{r["id"]}]{r["id"]}[/link][/bold blue]', | ||
r["title"], | ||
r["artist-credit"][0]["name"], | ||
str(r["score"]), | ||
) | ||
|
||
console = Console() | ||
console.print(table) |
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,29 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
from youtube_bz import commands | ||
|
||
|
||
@patch("youtube_bz.api.musicbrainz.Client.search_release") | ||
def test_search_command(search_mock: Mock): | ||
search_mock.return_value = { | ||
"releases": [ | ||
{ | ||
"title": "amo", | ||
"media": [], | ||
"artist-credit": [{"name": "bmth"}], | ||
"id": "0000", | ||
"score": 100, | ||
} | ||
] | ||
} | ||
commands.search("query", False) | ||
search_mock.assert_called_once() | ||
|
||
|
||
@patch("youtube_bz.api.musicbrainz.Client.search_release") | ||
def test_search_command_no_results(search_mock: Mock, capsys): | ||
search_mock.return_value = {"releases": []} | ||
commands.search("query", False) | ||
search_mock.assert_called_once() | ||
capured = capsys.readouterr() | ||
assert "No data to display\n" == capured.out |
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