Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
876ccaf8d2 | |||
f287780bcd |
@ -13,7 +13,7 @@ license = "MIT"
|
||||
python = "^3.7"
|
||||
spotipy = "^2.18.0"
|
||||
spotify-model = {path = "../spotify_model", develop = true}
|
||||
PyYAML = "^5.4.1"
|
||||
PyYAML = "=5.3.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pre-commit = "^2.13.0"
|
||||
|
@ -13,24 +13,16 @@ from .util import exhaust
|
||||
class Query:
|
||||
"Query builder for Spotify search API"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
query: Optional[str] = None,
|
||||
artist: Optional[str] = None,
|
||||
label: Optional[str] = None,
|
||||
year: Optional[int] = None,
|
||||
) -> None:
|
||||
def __init__(self, query: Optional[str] = None, artist: Optional[str] = None, label: Optional[str] = None) -> None:
|
||||
self.query = query
|
||||
self.artist = artist
|
||||
self.label = label
|
||||
self.year = year
|
||||
|
||||
def __str__(self) -> str:
|
||||
query_items = [
|
||||
self.query,
|
||||
f'artist:"{self.artist}"' if self.artist is not None else None,
|
||||
f'label:"{self.label}"' if self.label is not None else None,
|
||||
f"year:{self.year}" if self.year is not None else None,
|
||||
]
|
||||
return " ".join([i for i in query_items if i is not None])
|
||||
|
||||
|
@ -21,7 +21,7 @@ def track_from_ids(
|
||||
yield track if isinstance(track, str) else track.spotify_id
|
||||
|
||||
for track_id_chunk in chunk(_to_id(), chunk_size):
|
||||
track_chunk = client.tracks(track_id_chunk)
|
||||
track_chunk = client.tracks(track_id_chunk)["tracks"]
|
||||
|
||||
for track in track_chunk:
|
||||
yield Track(**track)
|
||||
|
@ -32,13 +32,13 @@ def read_credentials_server(path: Path) -> Spotify:
|
||||
return Spotify(client_credentials_manager=credentials_manager)
|
||||
|
||||
|
||||
def read_credentials_oauth(path: Path, redirect_uri: str, scopes: List[str]) -> Spotify:
|
||||
def read_credentials_oauth(path: Path, redirect_uri: str, scopes: List[str], open_browser: bool = True) -> Spotify:
|
||||
"Read credentials from a YAML file and authorize a user"
|
||||
|
||||
with open(path, "r") as credentials_file:
|
||||
credentials = yaml.safe_load(credentials_file)
|
||||
credentials_manager = SpotifyOAuth(
|
||||
credentials["client_id"], credentials["client_secret"], redirect_uri, scope=scopes
|
||||
credentials["client_id"], credentials["client_secret"], redirect_uri, scope=scopes, open_browser=open_browser
|
||||
)
|
||||
return Spotify(client_credentials_manager=credentials_manager)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user