././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779919194.137667 mopidy_somafm-2.1.0/0000755000175100017510000000000015205664532014033 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/.copier-answers.yml0000644000175100017510000000037615205664524017604 0ustar00runnerrunner_commit: v2.3.0 _src_path: gh:mopidy/cookiecutter-mopidy-ext author_email: alpetitjean@gmail.com author_full_name: Alexandre Petitjean dist_name: mopidy-somafm ext_name: somafm github_username: AlexandrePTJ short_description: Mopidy extension for SomaFM ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779919194.1341214 mopidy_somafm-2.1.0/.github/0000755000175100017510000000000015205664532015373 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779919194.1360478 mopidy_somafm-2.1.0/.github/workflows/0000755000175100017510000000000015205664532017430 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/.github/workflows/ci.yml0000644000175100017510000000300215205664524020542 0ustar00runnerrunnername: CI on: pull_request: push: branches: - main workflow_dispatch: jobs: build: name: Build runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v6 - uses: hynek/build-and-inspect-python-package@v2 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 container: ghcr.io/mopidy/ci:latest steps: - uses: actions/checkout@v6 - name: Fix home dir permissions to enable pip caching run: chown -R root /github/home - uses: actions/setup-python@v6 with: python-version: ${{ matrix.python }} cache: pip allow-prereleases: true - run: python -m pip install tox - run: python -m tox -e ${{ matrix.tox }} if: ${{ ! matrix.coverage }} - run: python -m tox -e ${{ matrix.tox }} -- --cov-report=xml if: ${{ matrix.coverage }} - uses: codecov/codecov-action@v6 if: ${{ matrix.coverage }} with: token: ${{ secrets.CODECOV_TOKEN }} ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/.github/workflows/release.yml0000644000175100017510000000102015205664524021565 0ustar00runnerrunnername: Release on: release: types: [published] jobs: release: runs-on: ubuntu-24.04 environment: name: pypi url: https://pypi.org/project/mopidy-somafm/ permissions: id-token: write steps: - uses: actions/checkout@v6 - uses: hynek/build-and-inspect-python-package@v2 id: build - uses: actions/download-artifact@v8 with: name: ${{ steps.build.outputs.artifact-name }} path: dist - uses: pypa/gh-action-pypi-publish@release/v1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/.gitignore0000644000175100017510000000012515205664524016022 0ustar00runnerrunner*.egg-info/ /*.lock /.*_cache/ /.coverage /.tox/ /.venv/ /build/ /dist/ __pycache__/ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/CHANGES.md0000644000175100017510000000355715205664524015440 0ustar00runnerrunnerChangelog ========= v2.1.0 (2026-05-27) ------------------- - Migrate to mopidy >= 3.4.x v2.0.2 (2021-02-10) ------------------- - #40 Fix exception on URI parsing v2.0.1 (2021-01-07) ------------------- - #37 Fix image display (Thanks to @dreamlayers and @morithil) v2.0.0 (2020-03-11) ------------------- - #36 Ready for Mopidy 3.0 v2.0.0rc1 (2019-12-04) ---------------------- - #32 Migrate to Python 3.7 v1.1.0 (2017-10-14) ------------------- - #24: Graceful fallback - #28: Various fix (DJ as artist, station ordering) v1.0.1 (2016-01-19) ------------------- - Use httpclient helper from Mopidy >= 1.1 v0.8.0 (2015-11-09) ------------------- - #20: Replace HTTP with HTTPS for channels.xml v0.7.1 (2015-01-04) ------------------- - #11: Add Low Bitrate encoding (aacp) v0.7.0 (2014-07-29) ------------------- - #10: Remove playlists provider v0.6.0 (2014-03-15) ------------------- - Directly show PLS in browser - Add precision about 'quality' and 'encoding' couple v0.5.1 (2014-03-09) ------------------- - Fix doc typo v0.5.0 (2014-03-03) ------------------- - #5: Select prefered quality and format from config - Add tests and Travis-CI support v0.4.0 (2014-02-16) ------------------- - Add browse support for LibraryController v0.3.1 (2014-01-30) ------------------- - #3: Correct wrong subclassing v0.3.0 (2014-01-29) ------------------- - Require Mopidy >= 0.18 - Add proxy support for downloading SomaFM content - #1: handle 'requests' exceptions - Use builtin Mopidy's .pls support - Internal code cleanup v0.2.0 (2013-09-22) ------------------- - PLS files are downloaded to local temp directory - Implement library::lookup to allow adding tracks from playlist uri v0.1.1 (2013-09-14) ------------------- - Update Licence information v0.1.0 (2013-09-13) ------------------- - Initial release - Create SomaFM extension for Mopidy ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/LICENSE0000644000175100017510000002613615205664524015051 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=1779919194.1376448 mopidy_somafm-2.1.0/PKG-INFO0000644000175100017510000001062115205664532015130 0ustar00runnerrunnerMetadata-Version: 2.4 Name: mopidy-somafm Version: 2.1.0 Summary: Mopidy extension for SomaFM Author-email: Alexandre Petitjean License: Apache-2.0 Project-URL: Homepage, https://github.com/AlexandrePTJ/mopidy-somafm 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>=3.4.1 Requires-Dist: pykka>=4.1 Dynamic: license-file # mopidy-somafm [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-somafm)](https://pypi.org/p/mopidy-somafm) [![CI build status](https://img.shields.io/github/actions/workflow/status/AlexandrePTJ/mopidy-somafm/ci.yml)](https://github.com/AlexandrePTJ/mopidy-somafm/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/AlexandrePTJ/mopidy-somafm)](https://codecov.io/gh/AlexandrePTJ/mopidy-somafm) Mopidy extension for SomaFM ## Installation Install by running: ```sh python3 -m pip install mopidy-somafm ``` See https://mopidy.com/ext/somafm/ for alternative installation methods. ## Configuration Before starting Mopidy, you must add configuration for mopidy-somafm to your Mopidy configuration file: ```ini [somafm] encoding = aac quality = highest ``` - ``encoding`` must be either ``aac``, ``mp3`` or ``aacp`` - ``quality`` must be one of ``highest``, ``fast``, ``slow``, ``firewall`` If the preferred quality is not available for a channel, the extension will fallback to ``fast``. And afterwards if the preferred encoding is not available for that quality, it will fallback to using ``mp3``. It seems that all channels support the combination ``fast`` + ``mp3`` You can also choose to use the channel DJ as the reported track artist (default behavior):: ```ini [somafm] dj_as_artist = true ``` ## Project resources - [Source code](https://github.com/AlexandrePTJ/mopidy-somafm) - [Issues](https://github.com/AlexandrePTJ/mopidy-somafm/issues) - [Releases](https://github.com/AlexandrePTJ/mopidy-somafm/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone AlexandrePTJ/mopidy-somafm ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-somafm/ 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 . ``` ### Setup before first release Before the first release, you must [enable trusted publishing on PyPI](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/) so that the `release.yml` GitHub Action can create the PyPI project and publish releases to PyPI. When following the instructions linked above, use the following values in the form at PyPI: - Publisher: GitHub - PyPI project name: `mopidy-somafm` - Owner: `AlexandrePTJ` - Repository name: `mopidy-somafm` - Workflow name: `release.yml` - Environment name: `pypi` (must match environment name in `release.yml`) ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/AlexandrePTJ/mopidy-somafm/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-somafm/). ## Credits - Original author: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - Current maintainer: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - [Contributors](https://github.com/AlexandrePTJ/mopidy-somafm/graphs/contributors) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/README.md0000644000175100017510000000735515205664524015325 0ustar00runnerrunner# mopidy-somafm [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-somafm)](https://pypi.org/p/mopidy-somafm) [![CI build status](https://img.shields.io/github/actions/workflow/status/AlexandrePTJ/mopidy-somafm/ci.yml)](https://github.com/AlexandrePTJ/mopidy-somafm/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/AlexandrePTJ/mopidy-somafm)](https://codecov.io/gh/AlexandrePTJ/mopidy-somafm) Mopidy extension for SomaFM ## Installation Install by running: ```sh python3 -m pip install mopidy-somafm ``` See https://mopidy.com/ext/somafm/ for alternative installation methods. ## Configuration Before starting Mopidy, you must add configuration for mopidy-somafm to your Mopidy configuration file: ```ini [somafm] encoding = aac quality = highest ``` - ``encoding`` must be either ``aac``, ``mp3`` or ``aacp`` - ``quality`` must be one of ``highest``, ``fast``, ``slow``, ``firewall`` If the preferred quality is not available for a channel, the extension will fallback to ``fast``. And afterwards if the preferred encoding is not available for that quality, it will fallback to using ``mp3``. It seems that all channels support the combination ``fast`` + ``mp3`` You can also choose to use the channel DJ as the reported track artist (default behavior):: ```ini [somafm] dj_as_artist = true ``` ## Project resources - [Source code](https://github.com/AlexandrePTJ/mopidy-somafm) - [Issues](https://github.com/AlexandrePTJ/mopidy-somafm/issues) - [Releases](https://github.com/AlexandrePTJ/mopidy-somafm/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone AlexandrePTJ/mopidy-somafm ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-somafm/ 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 . ``` ### Setup before first release Before the first release, you must [enable trusted publishing on PyPI](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/) so that the `release.yml` GitHub Action can create the PyPI project and publish releases to PyPI. When following the instructions linked above, use the following values in the form at PyPI: - Publisher: GitHub - PyPI project name: `mopidy-somafm` - Owner: `AlexandrePTJ` - Repository name: `mopidy-somafm` - Workflow name: `release.yml` - Environment name: `pypi` (must match environment name in `release.yml`) ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/AlexandrePTJ/mopidy-somafm/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-somafm/). ## Credits - Original author: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - Current maintainer: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - [Contributors](https://github.com/AlexandrePTJ/mopidy-somafm/graphs/contributors) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/pyproject.toml0000644000175100017510000000604215205664524016752 0ustar00runnerrunner[project] name = "mopidy-somafm" description = "Mopidy extension for SomaFM" readme = "README.md" requires-python = ">= 3.13" license = { text = "Apache-2.0" } authors = [{ name = "Alexandre Petitjean", email = "alpetitjean@gmail.com" }] 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 >= 3.4.1", "pykka >= 4.1", ] [project.urls] Homepage = "https://github.com/AlexandrePTJ/mopidy-somafm" [project.entry-points."mopidy.ext"] somafm = "mopidy_somafm: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_somafm"] [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_somafm", # # 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 "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=1779919194.1379118 mopidy_somafm-2.1.0/setup.cfg0000644000175100017510000000004615205664532015654 0ustar00runnerrunner[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779919194.1341214 mopidy_somafm-2.1.0/src/0000755000175100017510000000000015205664532014622 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779919194.1363268 mopidy_somafm-2.1.0/src/mopidy_somafm/0000755000175100017510000000000015205664532017465 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/src/mopidy_somafm/__init__.py0000644000175100017510000000153715205664524021605 0ustar00runnerrunnerimport logging import pathlib from importlib.metadata import version from mopidy import config, ext __version__ = version("mopidy-somafm") logger = logging.getLogger(__name__) class Extension(ext.Extension): dist_name = "mopidy-somafm" ext_name = "somafm" version = __version__ def get_default_config(self): return config.read(pathlib.Path(__file__).parent / "ext.conf") def get_config_schema(self): schema = super().get_config_schema() schema["encoding"] = config.String(choices=("aac", "mp3", "aacp")) schema["quality"] = config.String( choices=("highest", "fast", "slow", "firewall") ) schema["dj_as_artist"] = config.Boolean() return schema def setup(self, registry): from .backend import SomaFMBackend registry.add("backend", SomaFMBackend) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/src/mopidy_somafm/backend.py0000644000175100017510000000775515205664524021445 0ustar00runnerrunnerimport configparser import logging import random import httpx import pykka from mopidy import backend, httpclient from mopidy.models import Album, Artist, Image, Ref, Track import mopidy_somafm from .somafm import SomaFMClient, extract_somafm_channel_name_from_uri logger = logging.getLogger(__name__) class SomaFMBackend(pykka.ThreadingActor, backend.Backend): def __init__(self, config, audio): super().__init__() user_agent = f"{mopidy_somafm.Extension.dist_name}/{mopidy_somafm.__version__}" self.somafm = SomaFMClient(config["proxy"], user_agent) self.library = SomaFMLibraryProvider(backend=self) self.playback = SomaFMPlayback( audio=audio, backend=self, proxy_config=config["proxy"], user_agent=user_agent, ) self.uri_schemes = ["somafm"] self.quality = config["somafm"]["quality"] self.encoding = config["somafm"]["encoding"] self.dj_as_artist = config["somafm"]["dj_as_artist"] def on_start(self): self.somafm.refresh(self.encoding, self.quality) class SomaFMLibraryProvider(backend.LibraryProvider): root_directory = Ref.directory(uri="somafm:root", name="SomaFM") def lookup(self, uri): # Whatever the uri, it will always contains one track # which is a url to a pls channel_name = extract_somafm_channel_name_from_uri(uri) if channel_name is None: return None channel_data = self.backend.somafm.channels[channel_name] # Artists if self.backend.dj_as_artist: artist = Artist(name=channel_data["dj"]) else: artist = Artist() # Build album (idem as playlist, but with more metada) album = Album( artists=[artist], name=channel_data["title"], ) track = Track( artists=[artist], album=album, last_modified=channel_data["updated"], comment=channel_data["description"], genre=channel_data["genre"], name=channel_data["title"], uri="somafm:channel:/%s" % (channel_name), ) return [track] def browse(self, uri): if uri != "somafm:root": return [] result = [] for channel in self.backend.somafm.channels: result.append( Ref.track( uri="somafm:channel:/%s" % (channel), name=self.backend.somafm.channels[channel]["title"], ) ) result.sort(key=lambda ref: ref.name.lower()) return result def get_images(self, uris): images = {} for uri in uris: channel_name = extract_somafm_channel_name_from_uri(uri) if channel_name is not None: image = Image(uri=self.backend.somafm.images[channel_name]) images[uri] = [image] return images class SomaFMPlayback(backend.PlaybackProvider): def __init__(self, audio, backend, proxy_config=None, user_agent=None): super().__init__(audio=audio, backend=backend) # Build HTTP client self.http = httpx.Client( proxy=httpclient.format_proxy(proxy_config) if proxy_config else None, headers={"user-agent": httpclient.format_user_agent(user_agent)}, ) def translate_uri(self, uri): try: channel_name = extract_somafm_channel_name_from_uri(uri) if channel_name is None: return None channel_data = self.backend.somafm.channels.get(channel_name) r = self.http.get(channel_data["pls"]) if r.status_code != 200: return None pls = configparser.ConfigParser() pls.read_string(r.text) playlist = pls["playlist"] num = int(playlist["numberofentries"]) return playlist["File" + str(random.randint(1, num))] except Exception: return None ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/src/mopidy_somafm/ext.conf0000644000175100017510000000011215205664524021127 0ustar00runnerrunner[somafm] enabled = true encoding = mp3 quality = fast dj_as_artist = true ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/src/mopidy_somafm/somafm.py0000644000175100017510000001131715205664524021325 0ustar00runnerrunnerimport collections import logging import re from urllib.parse import urlsplit import httpx from mopidy import httpclient try: import xml.etree.ElementTree as ET except ImportError: import xml.etree.ElementTree as ET logger = logging.getLogger(__name__) # # Channels are playlist and Album # PLS are tracks # PLS contents for internal use # def extract_somafm_channel_name_from_uri(uri): if not uri.startswith("somafm:"): return None channel_separator = uri.find("/") if channel_separator == -1: return None return uri[channel_separator + 1 :] class SomaFMClient: CHANNELS_URI = "https://api.somafm.com/channels.xml" # All channels seem to have this combination of quality/encoding available FALLBACK_QUALITY = "fast" FALLBACK_ENCODING = "mp3" channels = {} images = {} def __init__(self, proxy_config=None, user_agent=None): super().__init__() # Build HTTP client self.http = httpx.Client( proxy=httpclient.format_proxy(proxy_config) if proxy_config else None, headers={"user-agent": httpclient.format_user_agent(user_agent)}, ) def refresh(self, encoding, quality): # clean previous data self.channels = {} # download channels xml file channels_content = self._downloadContent(self.CHANNELS_URI) if channels_content is None: logger.error("Cannot fetch %s" % (self.CHANNELS_URI)) return # parse XML root = ET.fromstring(channels_content) for child_channel in root: pls_id = child_channel.attrib["id"] channel_data = {} channel_all_pls = collections.defaultdict(dict) for child_detail in child_channel: key = child_detail.tag val = child_detail.text if key in ["title", "image", "dj", "genre", "description"]: channel_data[key] = val elif key == "updated": channel_data["updated"] = int(val) elif "pls" in key: pls_quality = key[:-3] pls_format = child_detail.attrib["format"] channel_all_pls[pls_quality][pls_format] = val # firewall playlist are fastpls+mp3 but with fw path if pls_quality == "fast" and pls_format == "mp3": r1 = urlsplit(val) channel_all_pls["firewall"]["mp3"] = "{}://{}/{}".format( r1.scheme, r1.netloc, "fw" + r1.path ) channel_pls = self._choose_pls(channel_all_pls, encoding, quality) if channel_pls is not None: channel_data["pls"] = channel_pls self.channels[pls_id] = channel_data self.images[pls_id] = channel_data["image"] logger.info("Loaded %i SomaFM channels" % (len(self.channels))) def extractStreamUrlFromPls(self, pls_uri): pls_content = self._downloadContent(pls_uri) if pls_content is None: logger.error("Cannot fetch %s" % (pls_uri)) return pls_uri # try to find FileX= try: m = re.search(r"^(File\d)=(?P\S+)", pls_content, re.MULTILINE) if m: return m.group("stream_url") return pls_uri except BaseException: return pls_uri def _choose_pls(self, all_pls, encoding, quality): if not all_pls: return None if quality in all_pls: quality_pls = all_pls[quality] elif self.FALLBACK_QUALITY in all_pls: quality_pls = all_pls[self.FALLBACK_QUALITY] else: quality_pls = all_pls[next(iter(all_pls))] if not quality_pls: return None if encoding in quality_pls: pls = quality_pls[encoding] elif self.FALLBACK_ENCODING in all_pls: pls = quality_pls[self.FALLBACK_ENCODING] else: pls = quality_pls[next(iter(quality_pls))] return pls def _downloadContent(self, url): try: r = self.http.get(url) logger.debug("Get %s : %i", url, r.status_code) if r.status_code != 200: logger.error( "SomaFM: %s is not reachable [http code:%i]", url, r.status_code, ) return None except httpx.RequestError as e: logger.error("SomaFM RequestError: %s", e) except Exception as e: logger.error("SomaFM exception: %s", e) else: return r.text return None ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779919194.1372256 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/0000755000175100017510000000000015205664532021157 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/PKG-INFO0000644000175100017510000001062115205664532022254 0ustar00runnerrunnerMetadata-Version: 2.4 Name: mopidy-somafm Version: 2.1.0 Summary: Mopidy extension for SomaFM Author-email: Alexandre Petitjean License: Apache-2.0 Project-URL: Homepage, https://github.com/AlexandrePTJ/mopidy-somafm 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>=3.4.1 Requires-Dist: pykka>=4.1 Dynamic: license-file # mopidy-somafm [![Latest PyPI version](https://img.shields.io/pypi/v/mopidy-somafm)](https://pypi.org/p/mopidy-somafm) [![CI build status](https://img.shields.io/github/actions/workflow/status/AlexandrePTJ/mopidy-somafm/ci.yml)](https://github.com/AlexandrePTJ/mopidy-somafm/actions/workflows/ci.yml) [![Test coverage](https://img.shields.io/codecov/c/gh/AlexandrePTJ/mopidy-somafm)](https://codecov.io/gh/AlexandrePTJ/mopidy-somafm) Mopidy extension for SomaFM ## Installation Install by running: ```sh python3 -m pip install mopidy-somafm ``` See https://mopidy.com/ext/somafm/ for alternative installation methods. ## Configuration Before starting Mopidy, you must add configuration for mopidy-somafm to your Mopidy configuration file: ```ini [somafm] encoding = aac quality = highest ``` - ``encoding`` must be either ``aac``, ``mp3`` or ``aacp`` - ``quality`` must be one of ``highest``, ``fast``, ``slow``, ``firewall`` If the preferred quality is not available for a channel, the extension will fallback to ``fast``. And afterwards if the preferred encoding is not available for that quality, it will fallback to using ``mp3``. It seems that all channels support the combination ``fast`` + ``mp3`` You can also choose to use the channel DJ as the reported track artist (default behavior):: ```ini [somafm] dj_as_artist = true ``` ## Project resources - [Source code](https://github.com/AlexandrePTJ/mopidy-somafm) - [Issues](https://github.com/AlexandrePTJ/mopidy-somafm/issues) - [Releases](https://github.com/AlexandrePTJ/mopidy-somafm/releases) ## Development ### Set up development environment Clone the repo using, e.g. using [gh](https://cli.github.com/): ```sh gh repo clone AlexandrePTJ/mopidy-somafm ``` Enter the directory, and install dependencies using [uv](https://docs.astral.sh/uv/): ```sh cd mopidy-somafm/ 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 . ``` ### Setup before first release Before the first release, you must [enable trusted publishing on PyPI](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/) so that the `release.yml` GitHub Action can create the PyPI project and publish releases to PyPI. When following the instructions linked above, use the following values in the form at PyPI: - Publisher: GitHub - PyPI project name: `mopidy-somafm` - Owner: `AlexandrePTJ` - Repository name: `mopidy-somafm` - Workflow name: `release.yml` - Environment name: `pypi` (must match environment name in `release.yml`) ### Making a release To make a release to PyPI, go to the project's [GitHub releases page](https://github.com/AlexandrePTJ/mopidy-somafm/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-somafm/). ## Credits - Original author: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - Current maintainer: [Alexandre Petitjean](https://github.com/AlexandrePTJ) - [Contributors](https://github.com/AlexandrePTJ/mopidy-somafm/graphs/contributors) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/SOURCES.txt0000644000175100017510000000105215205664532023041 0ustar00runnerrunner.copier-answers.yml .gitignore CHANGES.md LICENSE README.md pyproject.toml .github/workflows/ci.yml .github/workflows/release.yml src/mopidy_somafm/__init__.py src/mopidy_somafm/backend.py src/mopidy_somafm/ext.conf src/mopidy_somafm/somafm.py src/mopidy_somafm.egg-info/PKG-INFO src/mopidy_somafm.egg-info/SOURCES.txt src/mopidy_somafm.egg-info/dependency_links.txt src/mopidy_somafm.egg-info/entry_points.txt src/mopidy_somafm.egg-info/requires.txt src/mopidy_somafm.egg-info/top_level.txt tests/__init__.py tests/test_extension.py tests/test_somafm.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/dependency_links.txt0000644000175100017510000000000115205664532025225 0ustar00runnerrunner ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/entry_points.txt0000644000175100017510000000005615205664532024456 0ustar00runnerrunner[mopidy.ext] somafm = mopidy_somafm:Extension ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/requires.txt0000644000175100017510000000003115205664532023551 0ustar00runnerrunnermopidy>=3.4.1 pykka>=4.1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919194.0 mopidy_somafm-2.1.0/src/mopidy_somafm.egg-info/top_level.txt0000644000175100017510000000001615205664532023706 0ustar00runnerrunnermopidy_somafm ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779919194.137142 mopidy_somafm-2.1.0/tests/0000755000175100017510000000000015205664532015175 5ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/tests/__init__.py0000644000175100017510000000000015205664524017275 0ustar00runnerrunner././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/tests/test_extension.py0000644000175100017510000000061715205664524020627 0ustar00runnerrunnerfrom mopidy_somafm import Extension def test_get_default_config() -> None: ext = Extension() config = ext.get_default_config() assert "[somafm]" in config assert "enabled = true" in config def test_get_config_schema() -> None: ext = Extension() schema = ext.get_config_schema() assert "encoding" in schema assert "quality" in schema # TODO Write more tests ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779919188.0 mopidy_somafm-2.1.0/tests/test_somafm.py0000644000175100017510000000265515205664524020101 0ustar00runnerrunnerimport unittest from mopidy_somafm.somafm import SomaFMClient class SomaFMClientTest(unittest.TestCase): def test_refresh(self): sfmc = SomaFMClient() sfmc.refresh("mp3", "fast") self.assertIsNotNone(sfmc.channels) self.assertNotEqual(len(sfmc.channels), 0) def test_refresh_firewall(self): sfmc = SomaFMClient() sfmc.refresh("mp3", "firewall") self.assertIsNotNone(sfmc.channels) self.assertNotEqual(len(sfmc.channels), 0) def test_refresh_no_channels(self): sfmc = SomaFMClient() sfmc.CHANNELS_URI = "" sfmc.refresh("mp3", "fast") self.assertDictEqual(sfmc.channels, {}) self.assertEqual(len(sfmc.channels), 0) def test_downloadContent(self): url = "http://api.somafm.com/channels.xml" sfmc = SomaFMClient() data = sfmc._downloadContent(url) self.assertNotEqual(len(data), 0) def test_extractStreamUrlFromPls(self): url = "http://somafm.com/groovesalad.pls" sfmc = SomaFMClient() data = sfmc.extractStreamUrlFromPls(url) self.assertNotEqual(len(data), 0) self.assertNotEqual(data, url) def test_extractStreamUrlFromPls_unknown(self): url = "http://somafm.com/noneazerty.pls" sfmc = SomaFMClient() data = sfmc.extractStreamUrlFromPls(url) self.assertNotEqual(len(data), 0) self.assertEqual(data, url)