Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User.get_now_playing: Add album and cover image to info #330

Merged
merged 6 commits into from Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 17 additions & 22 deletions .github/workflows/lint.yml
Expand Up @@ -4,39 +4,34 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v2

- name: pip cache
uses: actions/cache@v1
- name: Cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: lint-pip-${{ hashFiles('**/setup.py') }}
path: |
~/.cache/pip
~/.cache/pre-commit
key:
lint-v2-${{ hashFiles('**/setup.py') }}-${{
hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
lint-pip-
lint-v2-

- name: pre-commit cache
uses: actions/cache@v1
- name: Set up Python
uses: actions/setup-python@v2
with:
path: ~/.cache/pre-commit
key: lint-pre-commit-v1-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
lint-pre-commit-v1-

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox
python -m pip install -U pip
python -m pip install -U tox

- name: Lint
run: tox -e lint
env:
PRE_COMMIT_COLOR: always
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.4.1
rev: v2.4.4
hooks:
- id: pyupgrade
args: ["--py3-plus"]
Expand All @@ -15,7 +15,7 @@ repos:
types: []

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.0a2
rev: 3.8.2
hooks:
- id: flake8
additional_dependencies: [flake8-2020, flake8-implicit-str-concat]
Expand All @@ -36,7 +36,7 @@ repos:
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v3.1.0
hooks:
- id: check-merge-conflict
- id: check-yaml
5 changes: 4 additions & 1 deletion src/pylast/__init__.py
Expand Up @@ -2128,6 +2128,8 @@ def is_fulltrack_available(self):

def get_album(self):
"""Returns the album object of this track."""
if "album" in self.info and self.info["album"] is not None:
return Album(self.artist, self.info["album"], self.network)

doc = self._request(self.ws_prefix + ".getInfo", True)

Expand Down Expand Up @@ -2338,8 +2340,9 @@ def get_now_playing(self):

artist = _extract(e, "artist")
title = _extract(e, "name")
info = {"album": _extract(e, "album"), "image": _extract_all(e, "image")}

return Track(artist, title, self.network, self.name)
return Track(artist, title, self.network, self.name, info=info)

def get_recent_tracks(self, limit=10, cacheable=True, time_from=None, time_to=None):
"""
Expand Down
28 changes: 11 additions & 17 deletions tests/test_album.py
Expand Up @@ -2,8 +2,6 @@
"""
Integration (not unit) tests for pylast.py
"""
import unittest

import pylast

from .test_pylast import TestPyLastWithLastFm
Expand All @@ -18,8 +16,8 @@ def test_album_tags_are_topitems(self):
tags = album.get_top_tags(limit=1)

# Assert
self.assertGreater(len(tags), 0)
self.assertIsInstance(tags[0], pylast.TopItem)
assert len(tags) > 0
assert isinstance(tags[0], pylast.TopItem)

def test_album_is_hashable(self):
# Arrange
Expand All @@ -37,7 +35,7 @@ def test_album_in_recent_tracks(self):
track = lastfm_user.get_recent_tracks(limit=2)[0]

# Assert
self.assertTrue(hasattr(track, "album"))
assert hasattr(track, "album")

def test_album_wiki_content(self):
# Arrange
Expand All @@ -47,8 +45,8 @@ def test_album_wiki_content(self):
wiki = album.get_wiki_content()

# Assert
self.assertIsNotNone(wiki)
self.assertGreaterEqual(len(wiki), 1)
assert wiki is not None
assert len(wiki) >= 1

def test_album_wiki_published_date(self):
# Arrange
Expand All @@ -58,8 +56,8 @@ def test_album_wiki_published_date(self):
wiki = album.get_wiki_published_date()

# Assert
self.assertIsNotNone(wiki)
self.assertGreaterEqual(len(wiki), 1)
assert wiki is not None
assert len(wiki) >= 1

def test_album_wiki_summary(self):
# Arrange
Expand All @@ -69,24 +67,24 @@ def test_album_wiki_summary(self):
wiki = album.get_wiki_summary()

# Assert
self.assertIsNotNone(wiki)
self.assertGreaterEqual(len(wiki), 1)
assert wiki is not None
assert len(wiki) >= 1

def test_album_eq_none_is_false(self):
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)

# Act / Assert
self.assertNotEqual(album1, album2)
assert album1 != album2

def test_album_ne_none_is_true(self):
# Arrange
album1 = None
album2 = pylast.Album("Test Artist", "Test Album", self.network)

# Act / Assert
self.assertNotEqual(album1, album2)
assert album1 != album2

def test_get_cover_image(self):
# Arrange
Expand All @@ -98,7 +96,3 @@ def test_get_cover_image(self):
# Assert
self.assert_startswith(image, "https://")
self.assert_endswith(image, ".png")


if __name__ == "__main__":
unittest.main(failfast=True)