././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4089956 mopidy_scrobbler-3.1.1/0000755000175100017510000000000015251266373014532 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9907794 mopidy_scrobbler-3.1.1/.copier-answers.yml0000644000175100017510000000042615251266366020300 0ustar00runnerrunner_commit: v2.4.0 _src_path: gh:mopidy/mopidy-ext-template author_email: stein.magnus@jodal.no author_full_name: Stein Magnus Jodal dist_name: mopidy-scrobbler ext_name: scrobbler github_username: mopidy short_description: Mopidy extension for scrobbling played tracks to Last.fm ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4041297 mopidy_scrobbler-3.1.1/.github/0000755000175100017510000000000015251266373016072 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1789226235.406258 mopidy_scrobbler-3.1.1/.github/workflows/0000755000175100017510000000000015251266373020127 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9913385 mopidy_scrobbler-3.1.1/.github/workflows/ci.yml0000644000175100017510000000460615251266366021255 0ustar00runnerrunnername: CI on: pull_request: push: branches: - main workflow_dispatch: # No permissions by default; each job requests what it needs. permissions: {} concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: build: name: Build runs-on: ubuntu-24.04 permissions: contents: read # Check out the repository. steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: hynek/build-and-inspect-python-package@2abe76da66d0a6a4a227101f9348ee855797cfa5 # v3.0.1 main: strategy: fail-fast: false matrix: include: - name: "pytest (3.13)" python: "3.13" tox: "3.13" - name: "pytest (3.14)" python: "3.14" tox: "3.14" coverage: true - name: "pyright" python: "3.14" tox: "pyright" - name: "ruff check" python: "3.14" tox: "ruff-check" - name: "ruff format" python: "3.14" tox: "ruff-format" name: ${{ matrix.name }} runs-on: ubuntu-24.04 # Deliberately unpinned: this is our own image, and we always want the # latest version of it. container: ghcr.io/mopidy/ci:latest # zizmor: ignore[unpinned-images] permissions: contents: read # Check out the repository. steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - name: Fix home dir permissions to enable pip caching run: chown -R root /github/home - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: ${{ matrix.python }} cache: pip allow-prereleases: true - run: python -m pip install tox - env: TOX_ENV: ${{ matrix.tox }} run: python -m tox -e "$TOX_ENV" if: ${{ ! matrix.coverage }} - env: TOX_ENV: ${{ matrix.tox }} run: python -m tox -e "$TOX_ENV" -- --cov-report=xml if: ${{ matrix.coverage }} - uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 if: ${{ matrix.coverage }} with: token: ${{ secrets.CODECOV_TOKEN }} ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9914277 mopidy_scrobbler-3.1.1/.github/workflows/release.yml0000644000175100017510000000170015251266366022272 0ustar00runnerrunnername: Release on: release: types: [published] # No permissions by default; each job requests what it needs. permissions: {} jobs: release: name: Release runs-on: ubuntu-24.04 environment: name: pypi url: https://pypi.org/project/mopidy-scrobbler/ permissions: contents: read # Check out the repository. id-token: write # Authenticate with PyPI using trusted publishing. steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: hynek/build-and-inspect-python-package@2abe76da66d0a6a4a227101f9348ee855797cfa5 # v3.0.1 id: build - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: name: ${{ steps.build.outputs.artifact-name }} path: dist - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9914277 mopidy_scrobbler-3.1.1/.gitignore0000644000175100017510000000012515251266366016522 0ustar00runnerrunner*.egg-info/ /*.lock /.*_cache/ /.coverage /.tox/ /.venv/ /build/ /dist/ __pycache__/ ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9914277 mopidy_scrobbler-3.1.1/LICENSE0000644000175100017510000002613515251266366015550 0ustar00runnerrunner Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4088173 mopidy_scrobbler-3.1.1/PKG-INFO0000644000175100017510000001151215251266373015627 0ustar00runnerrunnerMetadata-Version: 2.4 Name: mopidy-scrobbler Version: 3.1.1 Summary: Mopidy extension for scrobbling played tracks to Last.fm Author-email: Stein Magnus Jodal License: Apache-2.0 Project-URL: Homepage, https://github.com/mopidy/mopidy-scrobbler Classifier: Environment :: No Input/Output (Daemon) Classifier: Intended Audience :: End Users/Desktop Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: OS Independent Classifier: Topic :: Multimedia :: Sound/Audio :: Players Requires-Python: >=3.13 Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: mopidy>=4.0.2 Requires-Dist: pykka>=4.1 Requires-Dist: pylast>=5.3 Dynamic: license-file # mopidy-scrobbler [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-scrobbler)](https://pypi.org/p/mopidy-scrobbler) [![CI build status](https://img.shields.io/github/actions/workflow/status/mopidy/mopidy-scrobbler/ci.yml)](https://github.com/mopidy/mopidy-scrobbler/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/mopidy/mopidy-scrobbler)](https://codecov.io/gh/mopidy/mopidy-scrobbler) [Mopidy](https://www.mopidy.com/) extension for scrobbling played tracks to [Last.fm](https://www.last.fm/) or [Libre.fm](https://libre.fm/). This extension requires a free user account at Last.fm or Libre.fm. ## Maintainer wanted Mopidy-Scrobbler is currently kept on life support by the Mopidy core developers. It is in need of a more dedicated maintainer. If you want to be the maintainer of Mopidy-Scrobbler, please: 1. Make 2-3 good pull requests improving any part of the project. 2. Read and get familiar with all of the project's open issues. 3. Send a pull request removing this section and adding yourself as the "Current maintainer" in the "Credits" section below. In the pull request description, please refer to the previous pull requests and state that you've familiarized yourself with the open issues. As a maintainer, you'll be given push access to the repo and the authority to make releases to PyPI when you see fit. ## Installation Install by running: ```sh python3 -m pip install mopidy-scrobbler ``` See https://mopidy.com/ext/scrobbler/ for alternative installation methods. ## Configuration The extension is enabled by default when it is installed. You just need to add your Last.fm username and password to your Mopidy configuration file: ```ini [scrobbler] username = my-last.fm-username password = my-last.fm-password ``` To use Libre.fm instead, you must specify the `network` too: ```ini [scrobbler] network = librefm username = my-libre.fm-username password = my-libre.fm-password ``` The following configuration values are available: - `scrobbler/enabled`: If the scrobbler extension should be enabled or not. Defaults to enabled. - `scrobbler/network`: The scrobbling network to use. Can be either `lastfm` or `librefm`. Defaults to `lastfm`. - `scrobbler/username`: Your Last.fm or Libre.fm username. - `scrobbler/password`: Your Last.fm or Libre.fm password. ## Project resources - [Source code](https://github.com/mopidy/mopidy-scrobbler) - [Issues](https://github.com/mopidy/mopidy-scrobbler/issues) - [Releases](https://github.com/mopidy/mopidy-scrobbler/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone mopidy/mopidy-scrobbler ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-scrobbler/ uv sync ``` ### Running tests To run all tests and linters in isolated environments, use [tox](https://tox.wiki/): ```sh tox ``` To only run tests, use [pytest](https://pytest.org/): ```sh pytest ``` To format the code, use [ruff](https://docs.astral.sh/ruff/): ```sh ruff format . ``` To check for lints with ruff, run: ```sh ruff check . ``` To check for type errors, use [pyright](https://microsoft.github.io/pyright/): ```sh pyright . ``` ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/mopidy/mopidy-scrobbler/releases) and click the "Draft a new release" button. In the "choose a tag" dropdown, select the tag you want to release or create a new tag, e.g. `v0.1.0`. Add a title, e.g. `v0.1.0`, and a description of the changes. Decide if the release is a pre-release (alpha, beta, or release candidate) or should be marked as the latest release, and click "Publish release". Once the release is created, the `release.yml` GitHub Action will automatically build and publish the release to [PyPI](https://pypi.org/project/mopidy-scrobbler/). ## Credits - Original author: [Stein Magnus Jodal](https://github.com/jodal) - Current maintainer: None. Maintainer wanted, see section above. - [Contributors](https://github.com/mopidy/mopidy-scrobbler/graphs/contributors) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9914277 mopidy_scrobbler-3.1.1/README.md0000644000175100017510000001015715251266366016017 0ustar00runnerrunner# mopidy-scrobbler [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-scrobbler)](https://pypi.org/p/mopidy-scrobbler) [![CI build status](https://img.shields.io/github/actions/workflow/status/mopidy/mopidy-scrobbler/ci.yml)](https://github.com/mopidy/mopidy-scrobbler/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/mopidy/mopidy-scrobbler)](https://codecov.io/gh/mopidy/mopidy-scrobbler) [Mopidy](https://www.mopidy.com/) extension for scrobbling played tracks to [Last.fm](https://www.last.fm/) or [Libre.fm](https://libre.fm/). This extension requires a free user account at Last.fm or Libre.fm. ## Maintainer wanted Mopidy-Scrobbler is currently kept on life support by the Mopidy core developers. It is in need of a more dedicated maintainer. If you want to be the maintainer of Mopidy-Scrobbler, please: 1. Make 2-3 good pull requests improving any part of the project. 2. Read and get familiar with all of the project's open issues. 3. Send a pull request removing this section and adding yourself as the "Current maintainer" in the "Credits" section below. In the pull request description, please refer to the previous pull requests and state that you've familiarized yourself with the open issues. As a maintainer, you'll be given push access to the repo and the authority to make releases to PyPI when you see fit. ## Installation Install by running: ```sh python3 -m pip install mopidy-scrobbler ``` See https://mopidy.com/ext/scrobbler/ for alternative installation methods. ## Configuration The extension is enabled by default when it is installed. You just need to add your Last.fm username and password to your Mopidy configuration file: ```ini [scrobbler] username = my-last.fm-username password = my-last.fm-password ``` To use Libre.fm instead, you must specify the `network` too: ```ini [scrobbler] network = librefm username = my-libre.fm-username password = my-libre.fm-password ``` The following configuration values are available: - `scrobbler/enabled`: If the scrobbler extension should be enabled or not. Defaults to enabled. - `scrobbler/network`: The scrobbling network to use. Can be either `lastfm` or `librefm`. Defaults to `lastfm`. - `scrobbler/username`: Your Last.fm or Libre.fm username. - `scrobbler/password`: Your Last.fm or Libre.fm password. ## Project resources - [Source code](https://github.com/mopidy/mopidy-scrobbler) - [Issues](https://github.com/mopidy/mopidy-scrobbler/issues) - [Releases](https://github.com/mopidy/mopidy-scrobbler/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone mopidy/mopidy-scrobbler ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-scrobbler/ uv sync ``` ### Running tests To run all tests and linters in isolated environments, use [tox](https://tox.wiki/): ```sh tox ``` To only run tests, use [pytest](https://pytest.org/): ```sh pytest ``` To format the code, use [ruff](https://docs.astral.sh/ruff/): ```sh ruff format . ``` To check for lints with ruff, run: ```sh ruff check . ``` To check for type errors, use [pyright](https://microsoft.github.io/pyright/): ```sh pyright . ``` ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/mopidy/mopidy-scrobbler/releases) and click the "Draft a new release" button. In the "choose a tag" dropdown, select the tag you want to release or create a new tag, e.g. `v0.1.0`. Add a title, e.g. `v0.1.0`, and a description of the changes. Decide if the release is a pre-release (alpha, beta, or release candidate) or should be marked as the latest release, and click "Publish release". Once the release is created, the `release.yml` GitHub Action will automatically build and publish the release to [PyPI](https://pypi.org/project/mopidy-scrobbler/). ## Credits - Original author: [Stein Magnus Jodal](https://github.com/jodal) - Current maintainer: None. Maintainer wanted, see section above. - [Contributors](https://github.com/mopidy/mopidy-scrobbler/graphs/contributors) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9914277 mopidy_scrobbler-3.1.1/pyproject.toml0000644000175100017510000000620015251266366017446 0ustar00runnerrunner[project] name = "mopidy-scrobbler" description = "Mopidy extension for scrobbling played tracks to Last.fm" readme = "README.md" requires-python = ">= 3.13" license = { text = "Apache-2.0" } authors = [{ name = "Stein Magnus Jodal", email = "stein.magnus@jodal.no" }] classifiers = [ "Environment :: No Input/Output (Daemon)", "Intended Audience :: End Users/Desktop", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Topic :: Multimedia :: Sound/Audio :: Players", ] dynamic = ["version"] dependencies = [ "mopidy >= 4.0.2", "pykka >= 4.1", "pylast >= 5.3", ] [project.urls] Homepage = "https://github.com/mopidy/mopidy-scrobbler" [project.entry-points."mopidy.ext"] scrobbler = "mopidy_scrobbler:Extension" [build-system] requires = ["setuptools >= 78", "setuptools-scm >= 8.2"] build-backend = "setuptools.build_meta" [dependency-groups] dev = [ "tox", { include-group = "ruff" }, { include-group = "tests" }, { include-group = "typing" }, ] ruff = ["ruff"] tests = ["pytest", "pytest-cov"] typing = ["pyright"] [tool.coverage.paths] source = ["src/", "*/site-packages/"] [tool.coverage.run] source_pkgs = ["mopidy_scrobbler"] [tool.coverage.report] show_missing = true [tool.pyright] pythonVersion = "3.13" typeCheckingMode = "standard" # Not all dependencies have type hints: reportMissingTypeStubs = false # Already covered by ruff's flake8-self checks: reportPrivateImportUsage = false [tool.pytest.ini_options] filterwarnings = [ # By default, fail tests on warnings from our own code "error:::mopidy_scrobbler", # # Add any warnings you want to ignore here: ] [tool.ruff] target-version = "py313" [tool.ruff.lint] select = ["ALL"] ignore = [ # Add rules you want to ignore here "CPY", # flake8-copyright "D", # pydocstyle "D203", # one-blank-line-before-class "D213", # multi-line-summary-second-line "G004", # logging-f-string "TD002", # missing-todo-author "TD003", # missing-todo-link # # Conflicting with `ruff format` "COM812", # missing-trailing-comma "ISC001", # single-line-implicit-string-concatenation ] [tool.ruff.lint.per-file-ignores] "tests/*" = [ "ARG", # flake8-unused-arguments "D", # pydocstyle "S101", # assert ] [tool.setuptools.package-data] "*" = ["*.conf"] [tool.setuptools_scm] # This section, even if empty, must be present for setuptools_scm to work [tool.tox] env_list = [ "3.13", "3.14", "pyright", "ruff-check", "ruff-format", ] [tool.tox.env_run_base] package = "wheel" wheel_build_env = ".pkg" dependency_groups = ["tests"] commands = [ [ "pytest", "--cov", "--basetemp={envtmpdir}", { replace = "posargs", extend = true }, ], ] [tool.tox.env.pyright] dependency_groups = ["typing"] commands = [["pyright", "{posargs:src}"]] [tool.tox.env.ruff-check] skip_install = true dependency_groups = ["ruff"] commands = [["ruff", "check", "{posargs:.}"]] [tool.tox.env.ruff-format] skip_install = true dependency_groups = ["ruff"] commands = [["ruff", "format", "--check", "--diff", "{posargs:.}"]] ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4092524 mopidy_scrobbler-3.1.1/setup.cfg0000644000175100017510000000004615251266373016353 0ustar00runnerrunner[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4048173 mopidy_scrobbler-3.1.1/src/0000755000175100017510000000000015251266373015321 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4068553 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler/0000755000175100017510000000000015251266373020657 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1789226229.991802 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler/__init__.py0000644000175100017510000000146715251266366023002 0ustar00runnerrunnerimport pathlib from importlib.metadata import version from mopidy import config, ext __version__ = version("mopidy-scrobbler") class Extension(ext.Extension): dist_name = "mopidy-scrobbler" ext_name = "scrobbler" version = __version__ def get_default_config(self) -> str: return config.read(pathlib.Path(__file__).parent / "ext.conf") def get_config_schema(self) -> config.ConfigSchema: schema = super().get_config_schema() schema["network"] = config.String(choices=["lastfm", "librefm"]) schema["username"] = config.String() schema["password"] = config.Secret() return schema def setup(self, registry: ext.Registry) -> None: from .frontend import ScrobblerFrontend # noqa: PLC0415 registry.add("frontend", ScrobblerFrontend) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9918802 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler/ext.conf0000644000175100017510000000010215251266366022321 0ustar00runnerrunner[scrobbler] enabled = true network = lastfm username = password = ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9918802 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler/frontend.py0000644000175100017510000001141415251266366023053 0ustar00runnerrunnerfrom __future__ import annotations import datetime as dt import logging from typing import TYPE_CHECKING, cast, override import pykka import pylast from mopidy.core import CoreListener from mopidy.httpclient import format_proxy from mopidy_scrobbler.types import NetworkConfig if TYPE_CHECKING: from mopidy.config import Config from mopidy.core import CoreProxy from mopidy.models import TlTrack from mopidy.types import DurationMs from mopidy_scrobbler.types import ScrobblerConfig logger = logging.getLogger(__name__) NETWORK_CONFIG = { "lastfm": NetworkConfig( name="Last.fm", network_class=pylast.LastFMNetwork, api_key="2236babefa8ebb3d93ea467560d00d04", api_secret="94d9a09c0cd5be955c4afaeaffcaefcd", # noqa: S106 ), "librefm": NetworkConfig( name="Libre.fm", network_class=pylast.LibreFMNetwork, # # Libre.fm API key may expire 2031-04-25 api_key="339f358f9ba0dc49e00a400c8cdd773e", api_secret="4c3d7cf6f6379cb86e4c08231a347cda", # noqa: S106 ), } # Limits from https://www.last.fm/api/scrobbling MIN_DURATION = dt.timedelta(seconds=30) MIN_PLAYED_TIME = dt.timedelta(minutes=4) MIN_PLAYED_PERCENT = 50 class ScrobblerFrontend(pykka.ThreadingActor, CoreListener): network: pylast.LastFMNetwork | pylast.LibreFMNetwork last_start_time: dt.datetime | None @override def __init__( self, *, config: Config, core: CoreProxy, ) -> None: super().__init__() self.config = config self.last_start_time = None @override def on_start(self) -> None: scrobbler_config = cast("ScrobblerConfig", self.config["scrobbler"]) network_config = NETWORK_CONFIG[scrobbler_config["network"]] try: self.network = network_config.network_class( api_key=network_config.api_key, api_secret=network_config.api_secret, username=scrobbler_config["username"], password_hash=pylast.md5(scrobbler_config["password"]), proxy=format_proxy(self.config["proxy"]), ) logger.info(f"Scrobbler connected to {network_config.name}") except pylast.PyLastError as exc: logger.error(f"Error during {network_config.name} setup: {exc}") # noqa: TRY400 self.stop() @override def track_playback_started(self, tl_track: TlTrack) -> None: track = tl_track.track artists = ", ".join(sorted([a.name for a in track.artists if a.name])) duration = (track.length and track.length // 1000) or 0 self.last_start_time = dt.datetime.now(tz=dt.UTC) logger.debug(f"Now playing track: {artists} - {track.name}") try: self.network.update_now_playing( artists, (track.name or ""), album=((track.album and track.album.name) or ""), duration=str(duration), track_number=str(track.track_no or 0), mbid=(track.musicbrainz_id or ""), ) except pylast.PyLastError as exc: logger.warning(f"Error submitting playing track to Last.fm: {exc}") @override def track_playback_ended( self, tl_track: TlTrack, time_position: DurationMs, ) -> None: track = tl_track.track duration = dt.timedelta(milliseconds=track.length) if track.length else None position = dt.timedelta(milliseconds=time_position) if duration is None or duration < MIN_DURATION: logger.debug( f"Track too short to scrobble (<{MIN_DURATION.total_seconds()}s)" ) return if ( position < (duration * MIN_PLAYED_PERCENT / 100) and position < MIN_PLAYED_TIME ): logger.debug( "Track not played long enough to scrobble: " f"{MIN_PLAYED_PERCENT}% or {MIN_PLAYED_TIME.total_seconds()}s" ) return if self.last_start_time is None: self.last_start_time = dt.datetime.now(tz=dt.UTC) - duration artists = ", ".join(sorted([a.name for a in track.artists if a.name])) logger.debug(f"Scrobbling track: {artists} - {track.name}") try: self.network.scrobble( artists, (track.name or ""), round(self.last_start_time.timestamp()), album=((track.album and track.album.name) or ""), track_number=track.track_no, duration=round(duration.total_seconds()), mbid=(track.musicbrainz_id or ""), ) except pylast.PyLastError as exc: logger.warning(f"Error submitting played track to Last.fm: {exc}") ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9918802 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler/types.py0000644000175100017510000000067715251266366022411 0ustar00runnerrunnerfrom __future__ import annotations from dataclasses import dataclass from typing import TYPE_CHECKING, Literal, TypedDict if TYPE_CHECKING: import pylast class ScrobblerConfig(TypedDict): enabled: bool network: Literal["lastfm", "librefm"] username: str password: str @dataclass class NetworkConfig: name: str network_class: type[pylast.LastFMNetwork | pylast.LibreFMNetwork] api_key: str api_secret: str ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4081318 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/0000755000175100017510000000000015251266373022351 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3934643 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/PKG-INFO0000644000175100017510000001151215251266373023446 0ustar00runnerrunnerMetadata-Version: 2.4 Name: mopidy-scrobbler Version: 3.1.1 Summary: Mopidy extension for scrobbling played tracks to Last.fm Author-email: Stein Magnus Jodal License: Apache-2.0 Project-URL: Homepage, https://github.com/mopidy/mopidy-scrobbler Classifier: Environment :: No Input/Output (Daemon) Classifier: Intended Audience :: End Users/Desktop Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: OS Independent Classifier: Topic :: Multimedia :: Sound/Audio :: Players Requires-Python: >=3.13 Description-Content-Type: text/markdown License-File: LICENSE Requires-Dist: mopidy>=4.0.2 Requires-Dist: pykka>=4.1 Requires-Dist: pylast>=5.3 Dynamic: license-file # mopidy-scrobbler [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-scrobbler)](https://pypi.org/p/mopidy-scrobbler) [![CI build status](https://img.shields.io/github/actions/workflow/status/mopidy/mopidy-scrobbler/ci.yml)](https://github.com/mopidy/mopidy-scrobbler/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/mopidy/mopidy-scrobbler)](https://codecov.io/gh/mopidy/mopidy-scrobbler) [Mopidy](https://www.mopidy.com/) extension for scrobbling played tracks to [Last.fm](https://www.last.fm/) or [Libre.fm](https://libre.fm/). This extension requires a free user account at Last.fm or Libre.fm. ## Maintainer wanted Mopidy-Scrobbler is currently kept on life support by the Mopidy core developers. It is in need of a more dedicated maintainer. If you want to be the maintainer of Mopidy-Scrobbler, please: 1. Make 2-3 good pull requests improving any part of the project. 2. Read and get familiar with all of the project's open issues. 3. Send a pull request removing this section and adding yourself as the "Current maintainer" in the "Credits" section below. In the pull request description, please refer to the previous pull requests and state that you've familiarized yourself with the open issues. As a maintainer, you'll be given push access to the repo and the authority to make releases to PyPI when you see fit. ## Installation Install by running: ```sh python3 -m pip install mopidy-scrobbler ``` See https://mopidy.com/ext/scrobbler/ for alternative installation methods. ## Configuration The extension is enabled by default when it is installed. You just need to add your Last.fm username and password to your Mopidy configuration file: ```ini [scrobbler] username = my-last.fm-username password = my-last.fm-password ``` To use Libre.fm instead, you must specify the `network` too: ```ini [scrobbler] network = librefm username = my-libre.fm-username password = my-libre.fm-password ``` The following configuration values are available: - `scrobbler/enabled`: If the scrobbler extension should be enabled or not. Defaults to enabled. - `scrobbler/network`: The scrobbling network to use. Can be either `lastfm` or `librefm`. Defaults to `lastfm`. - `scrobbler/username`: Your Last.fm or Libre.fm username. - `scrobbler/password`: Your Last.fm or Libre.fm password. ## Project resources - [Source code](https://github.com/mopidy/mopidy-scrobbler) - [Issues](https://github.com/mopidy/mopidy-scrobbler/issues) - [Releases](https://github.com/mopidy/mopidy-scrobbler/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone mopidy/mopidy-scrobbler ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-scrobbler/ uv sync ``` ### Running tests To run all tests and linters in isolated environments, use [tox](https://tox.wiki/): ```sh tox ``` To only run tests, use [pytest](https://pytest.org/): ```sh pytest ``` To format the code, use [ruff](https://docs.astral.sh/ruff/): ```sh ruff format . ``` To check for lints with ruff, run: ```sh ruff check . ``` To check for type errors, use [pyright](https://microsoft.github.io/pyright/): ```sh pyright . ``` ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/mopidy/mopidy-scrobbler/releases) and click the "Draft a new release" button. In the "choose a tag" dropdown, select the tag you want to release or create a new tag, e.g. `v0.1.0`. Add a title, e.g. `v0.1.0`, and a description of the changes. Decide if the release is a pre-release (alpha, beta, or release candidate) or should be marked as the latest release, and click "Publish release". Once the release is created, the `release.yml` GitHub Action will automatically build and publish the release to [PyPI](https://pypi.org/project/mopidy-scrobbler/). ## Credits - Original author: [Stein Magnus Jodal](https://github.com/jodal) - Current maintainer: None. Maintainer wanted, see section above. - [Contributors](https://github.com/mopidy/mopidy-scrobbler/graphs/contributors) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.4015913 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/SOURCES.txt0000644000175100017510000000123715251266373024240 0ustar00runnerrunner.copier-answers.yml .gitignore LICENSE README.md pyproject.toml .github/workflows/ci.yml .github/workflows/release.yml src/mopidy_scrobbler/__init__.py src/mopidy_scrobbler/ext.conf src/mopidy_scrobbler/frontend.py src/mopidy_scrobbler/types.py src/mopidy_scrobbler.egg-info/PKG-INFO src/mopidy_scrobbler.egg-info/SOURCES.txt src/mopidy_scrobbler.egg-info/dependency_links.txt src/mopidy_scrobbler.egg-info/entry_points.txt src/mopidy_scrobbler.egg-info/requires.txt src/mopidy_scrobbler.egg-info/scm_file_list.json src/mopidy_scrobbler.egg-info/scm_version.json src/mopidy_scrobbler.egg-info/top_level.txt tests/__init__.py tests/test_extension.py tests/test_frontend.py././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3936987 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/dependency_links.txt0000644000175100017510000000000115251266373026417 0ustar00runnerrunner ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3940005 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/entry_points.txt0000644000175100017510000000006415251266373025647 0ustar00runnerrunner[mopidy.ext] scrobbler = mopidy_scrobbler:Extension ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3942146 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/requires.txt0000644000175100017510000000004515251266373024750 0ustar00runnerrunnermopidy>=4.0.2 pykka>=4.1 pylast>=5.3 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3916664 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/scm_file_list.json0000644000175100017510000000065415251266373026065 0ustar00runnerrunner{ "files": [ ".copier-answers.yml", ".github/workflows/ci.yml", ".github/workflows/release.yml", ".gitignore", "LICENSE", "README.md", "pyproject.toml", "src/mopidy_scrobbler/__init__.py", "src/mopidy_scrobbler/ext.conf", "src/mopidy_scrobbler/frontend.py", "src/mopidy_scrobbler/types.py", "tests/__init__.py", "tests/test_extension.py", "tests/test_frontend.py" ] } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3866897 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/scm_version.json0000644000175100017510000000024015251266373025567 0ustar00runnerrunner{ "tag": "3.1.1", "distance": 0, "node": "g4f0e3b84fbdbd16ccce9514833fe9c74612f2004", "dirty": false, "branch": "HEAD", "node_date": "2026-09-12" } ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226235.3943527 mopidy_scrobbler-3.1.1/src/mopidy_scrobbler.egg-info/top_level.txt0000644000175100017510000000002115251266373025074 0ustar00runnerrunnermopidy_scrobbler ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1789226235.408549 mopidy_scrobbler-3.1.1/tests/0000755000175100017510000000000015251266373015674 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9918802 mopidy_scrobbler-3.1.1/tests/__init__.py0000644000175100017510000000000015251266366017775 0ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9921775 mopidy_scrobbler-3.1.1/tests/test_extension.py0000644000175100017510000000142415251266366021324 0ustar00runnerrunnerfrom unittest import mock from mopidy_scrobbler import Extension from mopidy_scrobbler import frontend as frontend_lib def test_get_default_config() -> None: ext = Extension() config = ext.get_default_config() assert "[scrobbler]" in config assert "enabled = true" in config assert "network = lastfm" in config assert "username =" in config assert "password =" in config def test_get_config_schema() -> None: ext = Extension() schema = ext.get_config_schema() assert "network" in schema assert "username" in schema assert "password" in schema def test_setup() -> None: ext = Extension() registry = mock.Mock() ext.setup(registry) registry.add.assert_called_once_with("frontend", frontend_lib.ScrobblerFrontend) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1789226229.9921775 mopidy_scrobbler-3.1.1/tests/test_frontend.py0000644000175100017510000002132215251266366021126 0ustar00runnerrunnerfrom __future__ import annotations import datetime as dt from typing import TYPE_CHECKING, cast from unittest import mock import pylast import pytest from mopidy import models from mopidy.types import DurationMs, TracklistId, Uri from mopidy_scrobbler.frontend import NETWORK_CONFIG, ScrobblerFrontend if TYPE_CHECKING: from collections.abc import Generator @pytest.fixture def pylast_mock( monkeypatch: pytest.MonkeyPatch, ) -> Generator[mock.MagicMock]: with mock.patch("mopidy_scrobbler.frontend.pylast", spec=pylast) as mock_obj: mock_obj.PyLastError = pylast.PyLastError for config in NETWORK_CONFIG.values(): monkeypatch.setattr( config, "network_class", getattr(mock_obj, config.network_class.__name__), ) yield mock_obj @pytest.fixture def frontend() -> ScrobblerFrontend: config = { "scrobbler": { "network": "lastfm", "username": "alice", "password": "secret", }, "proxy": { "scheme": None, "hostname": None, "port": None, "username": None, "password": None, }, } core = mock.sentinel.core return ScrobblerFrontend( config=config, # pyright: ignore[reportArgumentType] core=core, ) @pytest.mark.parametrize("network_name", list(NETWORK_CONFIG)) def test_on_start_creates_network( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, network_name: str, ) -> None: pylast_mock.md5.return_value = mock.sentinel.password_hash network_config = NETWORK_CONFIG[network_name] frontend.config["scrobbler"]["network"] = network_name # pyright: ignore[reportIndexIssue] frontend.on_start() network_class = cast("mock.MagicMock", network_config.network_class) network_class.assert_called_with( api_key=network_config.api_key, api_secret=network_config.api_secret, username="alice", password_hash=mock.sentinel.password_hash, proxy=None, ) @pytest.mark.parametrize("network_name", list(NETWORK_CONFIG)) def test_on_start_passes_configured_proxy( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, network_name: str, ) -> None: pylast_mock.md5.return_value = mock.sentinel.password_hash network_config = NETWORK_CONFIG[network_name] frontend.config["scrobbler"]["network"] = network_name # pyright: ignore[reportIndexIssue] frontend.config["proxy"] = { # pyright: ignore[reportIndexIssue] "scheme": "https", "hostname": "proxy.example.com", "port": 8080, "username": "bob", "password": "hunter2", } frontend.on_start() network_class = cast("mock.MagicMock", network_config.network_class) network_class.assert_called_with( api_key=network_config.api_key, api_secret=network_config.api_secret, username="alice", password_hash=mock.sentinel.password_hash, proxy="https://bob:hunter2@proxy.example.com:8080", ) def test_on_start_stops_actor_on_error( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: pylast_mock.NetworkError = pylast.NetworkError pylast_mock.LastFMNetwork.side_effect = pylast.NetworkError(None, "foo") frontend.stop = mock.Mock() frontend.on_start() frontend.stop.assert_called_with() def test_track_playback_started_updates_now_playing( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) artists = frozenset([models.Artist(name="ABC"), models.Artist(name="XYZ")]) album = models.Album(name="The Collection") track = models.Track( uri=Uri("test:123"), name="One Two Three", artists=artists, album=album, track_no=3, length=DurationMs(180432), musicbrainz_id="59e2b08a-f428-4db6-85aa-a757f026aa2a", ) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_started(tl_track) frontend.network.update_now_playing.assert_called_with( "ABC, XYZ", "One Two Three", duration="180", album="The Collection", track_number="3", mbid="59e2b08a-f428-4db6-85aa-a757f026aa2a", ) def test_track_playback_started_has_default_values( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) track = models.Track(uri=Uri("test:foo")) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_started(tl_track) frontend.network.update_now_playing.assert_called_with( "", "", duration="0", album="", track_number="0", mbid="" ) def test_track_playback_started_catches_pylast_error( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) pylast_mock.NetworkError = pylast.NetworkError frontend.network.update_now_playing.side_effect = pylast.NetworkError(None, "foo") track = models.Track(uri=Uri("test:foo")) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_started(tl_track) def test_track_playback_ended_scrobbles_played_track( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.last_start_time = dt.datetime(1970, 1, 1, 0, 2, 3, tzinfo=dt.UTC) frontend.network = mock.Mock(spec=pylast.LastFMNetwork) artists = frozenset([models.Artist(name="ABC"), models.Artist(name="XYZ")]) album = models.Album(name="The Collection") track = models.Track( uri=Uri("test:123"), name="One Two Three", artists=artists, album=album, track_no=3, length=DurationMs(180432), musicbrainz_id="59e2b08a-f428-4db6-85aa-a757f026aa2a", ) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(150000)) frontend.network.scrobble.assert_called_with( "ABC, XYZ", "One Two Three", 123, duration=180, album="The Collection", track_number=3, mbid="59e2b08a-f428-4db6-85aa-a757f026aa2a", ) def test_track_playback_ended_has_default_values( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.last_start_time = dt.datetime(1970, 1, 1, 0, 2, 3, tzinfo=dt.UTC) frontend.network = mock.Mock(spec=pylast.LastFMNetwork) track = models.Track(uri=Uri("test:foo"), length=DurationMs(180432)) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(150000)) frontend.network.scrobble.assert_called_with( "", "", 123, duration=180, album="", track_number=None, mbid="", ) def test_does_not_scrobble_tracks_shorter_than_30_sec( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) track = models.Track(uri=Uri("test:foo"), length=DurationMs(20432)) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(20432)) assert frontend.network.scrobble.call_count == 0 def test_does_not_scrobble_if_played_less_than_half( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) track = models.Track(uri=Uri("test:foo"), length=DurationMs(180432)) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(60432)) assert frontend.network.scrobble.call_count == 0 def test_does_scrobble_if_played_not_half_but_240_sec( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) track = models.Track(uri=Uri("test:foo"), length=DurationMs(180432)) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(241432)) assert frontend.network.scrobble.call_count == 1 def test_track_playback_ended_catches_pylast_error( pylast_mock: mock.MagicMock, frontend: ScrobblerFrontend, ) -> None: frontend.network = mock.Mock(spec=pylast.LastFMNetwork) pylast_mock.NetworkError = pylast.NetworkError frontend.network.scrobble.side_effect = pylast.NetworkError(None, "foo") track = models.Track(uri=Uri("test:foo"), length=DurationMs(180432)) tl_track = models.TlTrack(track=track, tlid=TracklistId(17)) frontend.track_playback_ended(tl_track, DurationMs(150000))