fix: don't crash when non-song items are in the playlist
This commit is contained in:
parent
8a06ec23bf
commit
440d85c91f
4 changed files with 50 additions and 12 deletions
17
app.py
17
app.py
|
@ -47,14 +47,15 @@ def playlist(id: str):
|
|||
|
||||
artists = {}
|
||||
for track in tracks:
|
||||
for artist in track['track']['artists']:
|
||||
if artists.get(artist['uri'], None):
|
||||
artists[artist['uri']]['count'] += 1
|
||||
else:
|
||||
artists[artist['uri']] = {
|
||||
'count': 1,
|
||||
'name': artist['name'],
|
||||
}
|
||||
if 'artists' in track['track']:
|
||||
for artist in track['track']['artists']:
|
||||
if artists.get(artist['uri'], None):
|
||||
artists[artist['uri']]['count'] += 1
|
||||
else:
|
||||
artists[artist['uri']] = {
|
||||
'count': 1,
|
||||
'name': artist['name'],
|
||||
}
|
||||
artists = list(map(lambda artist: artist, artists.values()))
|
||||
artists.sort(key=lambda artist: artist['name'])
|
||||
artists.sort(key=lambda artist: -artist['count'])
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
in
|
||||
{
|
||||
devShell = pkgs.mkShell {
|
||||
nativeBuildInputs = [ py ];
|
||||
nativeBuildInputs = [ py pkgs.poetry ];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
41
poetry.lock
generated
41
poetry.lock
generated
|
@ -199,6 +199,7 @@ files = [
|
|||
|
||||
[package.dependencies]
|
||||
click = ">=8.0"
|
||||
importlib-metadata = {version = ">=3.6.0", markers = "python_version < \"3.10\""}
|
||||
itsdangerous = ">=2.0"
|
||||
Jinja2 = ">=3.0"
|
||||
Werkzeug = ">=2.2.2"
|
||||
|
@ -266,6 +267,26 @@ files = [
|
|||
{file = "idna-3.4.tar.gz", hash = "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "importlib-metadata"
|
||||
version = "6.0.0"
|
||||
description = "Read metadata from Python packages"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "importlib_metadata-6.0.0-py3-none-any.whl", hash = "sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad"},
|
||||
{file = "importlib_metadata-6.0.0.tar.gz", hash = "sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
zipp = ">=0.5"
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"]
|
||||
perf = ["ipython"]
|
||||
testing = ["flake8 (<5)", "flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "itsdangerous"
|
||||
version = "2.1.2"
|
||||
|
@ -863,7 +884,23 @@ files = [
|
|||
{file = "wrapt-1.14.1.tar.gz", hash = "sha256:380a85cf89e0e69b7cfbe2ea9f765f004ff419f34194018a6827ac0e3edfed4d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zipp"
|
||||
version = "3.11.0"
|
||||
description = "Backport of pathlib-compatible object wrapper for zip files"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "zipp-3.11.0-py3-none-any.whl", hash = "sha256:83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa"},
|
||||
{file = "zipp-3.11.0.tar.gz", hash = "sha256:a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)"]
|
||||
testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "ae2afedfa0922de5bc8e826b7bdb6815af468e86d3b821f958be0b7c97ac8afd"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "e05fedca2cc74685ae5404f99f74a89f43640f62ecadf2c4fa8fbdcaae076174"
|
||||
|
|
|
@ -8,7 +8,7 @@ readme = "README.md"
|
|||
packages = [{ include = "app.py" }]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
python = "^3.9"
|
||||
spotipy = {git = "https://github.com/plamere/spotipy.git"}
|
||||
Flask = "^2.2.2"
|
||||
python-dotenv = "^0.21.0"
|
||||
|
|
Loading…
Reference in a new issue