././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779663007.975211 mopidy_dleyna-3.0.0/0000775000175100017510000000000015204700240013067 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/CHANGELOG.rst0000664000175100017510000001020415204700037015111 0ustar00tkemtkemv3.0.0 (2026-05-25) =================== - Require Mopidy >= 4.0.0. - Potentially improve search performance. - Update build environment. v2.1.1 (2026-04-10) =================== - Minor documentation improvements. v2.1.0 (2026-04-05) =================== - Add support for Python <= 3.14. - Fix UPNP bitrate encoding. - Modernize build environment and packages structure. - Update CI environment. v2.0.2 (2022-04-03) =================== - Support Python 3.10. v2.0.1 (2020-07-06) =================== - Add ``DisplayName`` fallback for Plex media server. v2.0.0 (2019-12-25) =================== - Depend on final release of Mopidy 3.0.0. v2.0.0a1 (2019-12-05) ===================== - Require Python >= 3.7. (PR: #66) - Require Mopidy >= 3.0.0a5. (PR: #66) - Require Pykka >= 2.0.1. (PR: #66) - Update project setup. (PR: #66) v1.2.2 (2018-05-08) =================== - Add workaround for browsing errors with certain media servers. v1.2.1 (2017-10-24) =================== - Add support for ``audioBook``, ``audioBroadcast`` and ``playlistContainer`` classes. - Improve handling of browse and search limits. v1.2.0 (2016-09-23) =================== - Add ``dbus_start_session`` configuration value for specifying the command to start a session bus. The default is to invoke ``dbus-daemon`` directly, so ``dbus-launch`` is no longer needed (but is still supported for now). - Check for ``$XDG_RUNTIME_DIR/bus`` before starting a session bus. - Update installation dependencies. - Improve log messages if search is not supported. v1.1.1 (2016-06-28) =================== - Add workaround for partially retrieved browse results with Kodi 16.0 DLNA server. v1.1.0 (2016-05-21) =================== - Add ``upnp_lookup_limit`` configuration value (experimental). - Add support for ``albumartist`` queries. - Add support for minidlna "All Albums" collections. - Add track bitrate according to DLNA specification. - Add basic unit tests for ``library`` and ``playback`` providers. - Update documentation and build environment. - Various code refactorings and improvements. v1.0.5 (2016-01-22) =================== - Specify sort order when browsing. - Add ``apt.mopidy.com`` to installation options. - Remove ``Album.images`` property (deprecated in Mopidy v1.2). - Handle exceptions in ``dLeynaPlaybackProvider``. v1.0.4 (2015-11-03) =================== - Handle uppercase characters in server UDNs. v1.0.3 (2015-10-24) =================== - Refactor server handling. - Handle persistent URIs in ``dLeynaClient``. v1.0.2 (2015-10-16) =================== - Improve startup error messages. - Performance improvements. v1.0.1 (2015-09-12) =================== - Add workaround for permanently lost media servers. v1.0.0 (2015-08-21) =================== - Add ``upnp_browse_limit`` config value. - Add ``upnp_search_limit`` config value. - Refactor ``get_images`` implementation. - Improve debug output. v0.5.3 (2015-08-19) =================== - Fix lost server handling. - Check device's `SearchCaps` when searching. - Improve log messages. v0.5.2 (2015-08-18) =================== - Move mapping helpers to translator module. - Add ``mopidy_dleyna.dleyna.__main__``. - Update `README.rst`. v0.5.1 (2015-08-14) =================== - Start/stop D-Bus daemon from backend. v0.5.0 (2015-08-14) =================== - Add support for album art. v0.4.2 (2015-08-14) =================== - Use asynchronous D-Bus calls to improve performance on Raspberry Pi. v0.4.1 (2015-08-11) =================== - Add workaround for integer conversion issues on 32 bit systems. v0.4.0 (2015-08-11) =================== - Start session bus on headless systems or when running as a daemon. - Use recursive search for container lookups. - Add browse/search filters. - Persistent URI handling. v0.3.1 (2015-04-11) =================== - Perform search asynchronously. v0.3.0 (2015-04-10) =================== - Add basic search capabilities. - Return proper reference types when browsing. v0.2.0 (2015-04-08) =================== - Add workaround for `minidlna` crashing on empty filter. v0.1.0 (2015-04-07) =================== - Initial release. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1597080907.0 mopidy_dleyna-3.0.0/LICENSE0000644000175100017510000002367613714302513014115 0ustar00tkemtkem 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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/MANIFEST.in0000664000175100017510000000007415204700037014632 0ustar00tkemtkemprune .github/ exclude .gitignore exclude .readthedocs.yaml ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9751801 mopidy_dleyna-3.0.0/PKG-INFO0000644000175100017510000001060415204700240014163 0ustar00tkemtkemMetadata-Version: 2.4 Name: Mopidy-dLeyna Version: 3.0.0 Summary: Mopidy extension for playing music from Digital Media Servers Home-page: https://github.com/tkem/mopidy-dleyna Author: Thomas Kemmer Author-email: Thomas Kemmer Maintainer-email: Thomas Kemmer License-Expression: Apache-2.0 Project-URL: Homepage, https://github.com/tkem/mopidy-dleyna/ Project-URL: Documentation, https://mopidy-dleyna.readthedocs.io/en/stable/ Project-URL: Source, https://github.com/tkem/mopidy-dleyna/ Project-URL: Repository, https://github.com/tkem/mopidy-dleyna/ Project-URL: Issues, https://github.com/tkem/mopidy-dleyna/issues Project-URL: Changelog, https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst Classifier: Environment :: No Input/Output (Daemon) Classifier: Intended Audience :: End Users/Desktop Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Classifier: Topic :: Multimedia :: Sound/Audio :: Players Requires-Python: >=3.13 Description-Content-Type: text/x-rst License-File: LICENSE Requires-Dist: mopidy>=4.0.0 Requires-Dist: pykka>=4.1 Requires-Dist: uritools>=4.0.3 Dynamic: license-file ************* Mopidy-dLeyna ************* .. image:: https://img.shields.io/pypi/v/Mopidy-dLeyna :target: https://pypi.org/project/Mopidy-dLeyna/ :alt: Latest PyPI version .. image:: https://img.shields.io/github/actions/workflow/status/tkem/mopidy-dleyna/ci.yml :target: https://github.com/tkem/mopidy-dleyna/actions/workflows/ci.yml :alt: CI build status .. image:: https://img.shields.io/readthedocs/mopidy-dleyna :target: https://mopidy-dleyna.readthedocs.io/ :alt: Documentation build status .. image:: https://img.shields.io/codecov/c/gh/tkem/mopidy-dleyna :target: https://codecov.io/gh/tkem/mopidy-dleyna :alt: Test coverage .. image:: https://img.shields.io/github/license/tkem/mopidy-dleyna :target: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE :alt: License .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black :alt: Code style: black Mopidy-dLeyna is a Mopidy_ extension that lets you play music from DLNA_ Digital Media Servers using the dLeyna_ D-Bus interface. This extension lets you browse, search, and stream music from your NAS, PC, or any other device running a UPnP/DLNA compliant media server. Compatible devices are discovered automatically on your local network, so there is no configuration needed. Installation ============ On Debian Linux and Debian-based distributions like Ubuntu or Raspbian, install the ``mopidy-dleyna`` package from apt.mopidy.com_:: apt-get install mopidy-dleyna Otherwise, first make sure the following dependencies are met on your system: - D-Bus Python bindings, such as the package ``python-dbus`` in Debian/Ubuntu/Raspbian [#footnote1]_. - The ``dleyna-server`` package available in Ubuntu 14.04 and Debian "jessie". For other platforms, please see the dLeyna `installation instructions `_. Then install the Python package from PyPI_:: pip install Mopidy-dLeyna Project resources ================= - `Documentation`_ - `Issue tracker`_ - `Source code`_ - `Change log`_ License ======= Copyright (c) 2015-2026 Thomas Kemmer. Licensed under the `Apache License, Version 2.0`_. Credits ======= - Original author: `Thomas Kemmer `__ - Current maintainer: `Thomas Kemmer `__ - `Contributors `_ .. rubric:: Footnotes .. [#footnote1] On some distributions such as Arch Linux, it may also be necessary to install the ``dbus-glib`` package. .. _Mopidy: http://www.mopidy.com/ .. _DLNA: http://www.dlna.org/ .. _dLeyna: http://01.org/dleyna .. _apt.mopidy.com: http://apt.mopidy.com/ .. _PyPI: https://pypi.python.org/pypi/Mopidy-dLeyna/ .. _Documentation: https://mopidy-dleyna.readthedocs.io/ .. _Source code: https://github.com/tkem/mopidy-dleyna .. _Issue tracker: https://github.com/tkem/mopidy-dleyna/issues .. _Change log: https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst .. _Apache License, Version 2.0: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775765748.0 mopidy_dleyna-3.0.0/README.rst0000664000175100017510000000610315166004364014571 0ustar00tkemtkem************* Mopidy-dLeyna ************* .. image:: https://img.shields.io/pypi/v/Mopidy-dLeyna :target: https://pypi.org/project/Mopidy-dLeyna/ :alt: Latest PyPI version .. image:: https://img.shields.io/github/actions/workflow/status/tkem/mopidy-dleyna/ci.yml :target: https://github.com/tkem/mopidy-dleyna/actions/workflows/ci.yml :alt: CI build status .. image:: https://img.shields.io/readthedocs/mopidy-dleyna :target: https://mopidy-dleyna.readthedocs.io/ :alt: Documentation build status .. image:: https://img.shields.io/codecov/c/gh/tkem/mopidy-dleyna :target: https://codecov.io/gh/tkem/mopidy-dleyna :alt: Test coverage .. image:: https://img.shields.io/github/license/tkem/mopidy-dleyna :target: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE :alt: License .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black :alt: Code style: black Mopidy-dLeyna is a Mopidy_ extension that lets you play music from DLNA_ Digital Media Servers using the dLeyna_ D-Bus interface. This extension lets you browse, search, and stream music from your NAS, PC, or any other device running a UPnP/DLNA compliant media server. Compatible devices are discovered automatically on your local network, so there is no configuration needed. Installation ============ On Debian Linux and Debian-based distributions like Ubuntu or Raspbian, install the ``mopidy-dleyna`` package from apt.mopidy.com_:: apt-get install mopidy-dleyna Otherwise, first make sure the following dependencies are met on your system: - D-Bus Python bindings, such as the package ``python-dbus`` in Debian/Ubuntu/Raspbian [#footnote1]_. - The ``dleyna-server`` package available in Ubuntu 14.04 and Debian "jessie". For other platforms, please see the dLeyna `installation instructions `_. Then install the Python package from PyPI_:: pip install Mopidy-dLeyna Project resources ================= - `Documentation`_ - `Issue tracker`_ - `Source code`_ - `Change log`_ License ======= Copyright (c) 2015-2026 Thomas Kemmer. Licensed under the `Apache License, Version 2.0`_. Credits ======= - Original author: `Thomas Kemmer `__ - Current maintainer: `Thomas Kemmer `__ - `Contributors `_ .. rubric:: Footnotes .. [#footnote1] On some distributions such as Arch Linux, it may also be necessary to install the ``dbus-glib`` package. .. _Mopidy: http://www.mopidy.com/ .. _DLNA: http://www.dlna.org/ .. _dLeyna: http://01.org/dleyna .. _apt.mopidy.com: http://apt.mopidy.com/ .. _PyPI: https://pypi.python.org/pypi/Mopidy-dLeyna/ .. _Documentation: https://mopidy-dleyna.readthedocs.io/ .. _Source code: https://github.com/tkem/mopidy-dleyna .. _Issue tracker: https://github.com/tkem/mopidy-dleyna/issues .. _Change log: https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst .. _Apache License, Version 2.0: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9728117 mopidy_dleyna-3.0.0/docs/0000775000175100017510000000000015204700240014017 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/docs/conf.py0000664000175100017510000000147615204700037015332 0ustar00tkemtkemimport pathlib import sys src_directory = (pathlib.Path(__file__).parent.parent / "src").resolve() sys.path.insert(0, str(src_directory)) def get_version(package): """Get the version and release from the source code.""" text = (src_directory / "mopidy_dleyna/__init__.py").read_text() for line in text.splitlines(): if not line.strip().startswith("__version__"): continue return line.partition("=")[2].strip().strip("\"'") project = "Mopidy-dLeyna" copyright = "2015-2026 Thomas Kemmer" release = get_version(project) version = ".".join(release.split(".")[:2]) extensions = [ "sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.doctest", "sphinx.ext.intersphinx", "sphinx.ext.todo", ] exclude_patterns = ["_build"] master_doc = "index" html_theme = "classic" ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775842794.0 mopidy_dleyna-3.0.0/docs/index.rst0000664000175100017510000000373315166232752015705 0ustar00tkemtkem:tocdepth: 3 ************* Mopidy-dLeyna ************* Mopidy-dLeyna is a Mopidy_ extension that lets you play music from DLNA_ Digital Media Servers using the dLeyna_ D-Bus interface. This extension lets you browse, search, and stream music from your NAS, PC, or any other device running a UPnP/DLNA compliant media server. Compatible devices are discovered automatically on your local network, so there is no configuration needed. ************* Configuration ************* This extension provides a number of configuration values that can be tweaked. However, the :ref:`default configuration ` should contain everything to get you up and running, and will usually require only a few modifications, if any, to match personal preferences. .. _confvals: Configuration Values ==================== .. confval:: enabled Whether this extension should be enabled or not. .. confval:: upnp_browse_limit The maximum number of objects to retrieve per UPnP `Browse` action, or ``0`` to retrieve all objects. .. confval:: upnp_lookup_limit The maximum number of objects to retrieve by ID in a single UPnP `Search` action, or ``0`` for no limit. Note that for this setting to have any effect, the media server must advertise that it is capable of searching for object IDs. This is an *experimental* setting and may be changed or removed in future versions. .. confval:: upnp_search_limit The maximum number of objects to retrieve per UPnP `Search` action, or ``0`` to retrieve all objects. .. confval:: dbus_start_session The command to start a D-Bus session bus if none is found, for example when running Mopidy as a service. .. _defconf: Default Configuration ===================== For reference, this is the default configuration shipped with Mopidy-dLeyna release |release|: .. literalinclude:: ../src/mopidy_dleyna/ext.conf :language: ini .. _Mopidy: http://www.mopidy.com/ .. _DLNA: http://www.dlna.org/ .. _dLeyna: http://01.org/dleyna ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/pyproject.toml0000664000175100017510000000337115204700037016013 0ustar00tkemtkem[build-system] requires = ["setuptools >= 80", "setuptools-scm >= 8.2"] build-backend = "setuptools.build_meta" [project] name = "Mopidy-dLeyna" description = "Mopidy extension for playing music from Digital Media Servers" authors = [ {name = "Thomas Kemmer", email = "tkemmer@computer.org"} ] maintainers = [ {name = "Thomas Kemmer", email = "tkemmer@computer.org"} ] readme = "README.rst" license = "Apache-2.0" license-files = ["LICENSE"] requires-python = ">= 3.13" classifiers = [ "Environment :: No Input/Output (Daemon)", "Intended Audience :: End Users/Desktop", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", "Topic :: Multimedia :: Sound/Audio :: Players", ] dependencies = [ "mopidy >= 4.0.0", "pykka >= 4.1", "uritools >= 4.0.3", ] dynamic = ["version"] [project.entry-points."mopidy.ext"] dleyna = "mopidy_dleyna:Extension" [project.urls] Homepage = "https://github.com/tkem/mopidy-dleyna/" Documentation = "https://mopidy-dleyna.readthedocs.io/en/stable/" Source = "https://github.com/tkem/mopidy-dleyna/" Repository = "https://github.com/tkem/mopidy-dleyna/" Issues = "https://github.com/tkem/mopidy-dleyna/issues" Changelog = "https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst" [tool.setuptools] package-dir = {"" = "src"} [tool.setuptools.package-data] "*" = ["*.conf"] [tool.setuptools.packages.find] where = ["src"] [tool.setuptools.dynamic] version = {attr = "mopidy_dleyna.__version__"} [tool.pyright] typeCheckingMode = "standard" #reportFunctionMemberAccess = false #reportOptionalContextManager = false #reportOptionalMemberAccess = false ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9759765 mopidy_dleyna-3.0.0/setup.cfg0000664000175100017510000000307115204700240014711 0ustar00tkemtkem[metadata] name = Mopidy-dLeyna version = 2.0.2 url = https://github.com/tkem/mopidy-dleyna author = Thomas Kemmer author_email = tkemmer@computer.org license = Apache License, Version 2.0 license_file = LICENSE description = Mopidy extension for playing music from Digital Media Servers long_description = file: README.rst classifiers = Environment :: No Input/Output (Daemon) Intended Audience :: End Users/Desktop License :: OSI Approved :: Apache Software License Operating System :: OS Independent Programming Language :: Python :: 3 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Topic :: Multimedia :: Sound/Audio :: Players [options] zip_safe = False include_package_data = True packages = find: python_requires = >= 3.7 install_requires = Mopidy >= 3.0.0 Pykka >= 2.0.1 setuptools uritools >= 1.0 [options.extras_require] docs = sphinx lint = black check-manifest flake8 flake8-black flake8-bugbear flake8-import-order isort[pyproject] release = twine wheel test = pytest pytest-cov dev = %(docs)s %(lint)s %(release)s %(test)s [options.packages.find] exclude = tests tests.* [options.entry_points] mopidy.ext = dleyna = mopidy_dleyna:Extension [flake8] application-import-names = mopidy_dleyna, tests max-line-length = 80 exclude = .git, .tox, build select = C, E, F, W B B950 N ignore = E203 E501 W503 N801 [build_sphinx] source-dir = docs/ build-dir = docs/_build all_files = 1 [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1597080907.0 mopidy_dleyna-3.0.0/setup.py0000644000175100017510000000004613714302513014604 0ustar00tkemtkemfrom setuptools import setup setup() ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9712532 mopidy_dleyna-3.0.0/src/0000775000175100017510000000000015204700240013656 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9748209 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/0000775000175100017510000000000015204700240020105 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/PKG-INFO0000644000175100017510000001060415204700237021207 0ustar00tkemtkemMetadata-Version: 2.4 Name: Mopidy-dLeyna Version: 3.0.0 Summary: Mopidy extension for playing music from Digital Media Servers Home-page: https://github.com/tkem/mopidy-dleyna Author: Thomas Kemmer Author-email: Thomas Kemmer Maintainer-email: Thomas Kemmer License-Expression: Apache-2.0 Project-URL: Homepage, https://github.com/tkem/mopidy-dleyna/ Project-URL: Documentation, https://mopidy-dleyna.readthedocs.io/en/stable/ Project-URL: Source, https://github.com/tkem/mopidy-dleyna/ Project-URL: Repository, https://github.com/tkem/mopidy-dleyna/ Project-URL: Issues, https://github.com/tkem/mopidy-dleyna/issues Project-URL: Changelog, https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst Classifier: Environment :: No Input/Output (Daemon) Classifier: Intended Audience :: End Users/Desktop Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Classifier: Topic :: Multimedia :: Sound/Audio :: Players Requires-Python: >=3.13 Description-Content-Type: text/x-rst License-File: LICENSE Requires-Dist: mopidy>=4.0.0 Requires-Dist: pykka>=4.1 Requires-Dist: uritools>=4.0.3 Dynamic: license-file ************* Mopidy-dLeyna ************* .. image:: https://img.shields.io/pypi/v/Mopidy-dLeyna :target: https://pypi.org/project/Mopidy-dLeyna/ :alt: Latest PyPI version .. image:: https://img.shields.io/github/actions/workflow/status/tkem/mopidy-dleyna/ci.yml :target: https://github.com/tkem/mopidy-dleyna/actions/workflows/ci.yml :alt: CI build status .. image:: https://img.shields.io/readthedocs/mopidy-dleyna :target: https://mopidy-dleyna.readthedocs.io/ :alt: Documentation build status .. image:: https://img.shields.io/codecov/c/gh/tkem/mopidy-dleyna :target: https://codecov.io/gh/tkem/mopidy-dleyna :alt: Test coverage .. image:: https://img.shields.io/github/license/tkem/mopidy-dleyna :target: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE :alt: License .. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black :alt: Code style: black Mopidy-dLeyna is a Mopidy_ extension that lets you play music from DLNA_ Digital Media Servers using the dLeyna_ D-Bus interface. This extension lets you browse, search, and stream music from your NAS, PC, or any other device running a UPnP/DLNA compliant media server. Compatible devices are discovered automatically on your local network, so there is no configuration needed. Installation ============ On Debian Linux and Debian-based distributions like Ubuntu or Raspbian, install the ``mopidy-dleyna`` package from apt.mopidy.com_:: apt-get install mopidy-dleyna Otherwise, first make sure the following dependencies are met on your system: - D-Bus Python bindings, such as the package ``python-dbus`` in Debian/Ubuntu/Raspbian [#footnote1]_. - The ``dleyna-server`` package available in Ubuntu 14.04 and Debian "jessie". For other platforms, please see the dLeyna `installation instructions `_. Then install the Python package from PyPI_:: pip install Mopidy-dLeyna Project resources ================= - `Documentation`_ - `Issue tracker`_ - `Source code`_ - `Change log`_ License ======= Copyright (c) 2015-2026 Thomas Kemmer. Licensed under the `Apache License, Version 2.0`_. Credits ======= - Original author: `Thomas Kemmer `__ - Current maintainer: `Thomas Kemmer `__ - `Contributors `_ .. rubric:: Footnotes .. [#footnote1] On some distributions such as Arch Linux, it may also be necessary to install the ``dbus-glib`` package. .. _Mopidy: http://www.mopidy.com/ .. _DLNA: http://www.dlna.org/ .. _dLeyna: http://01.org/dleyna .. _apt.mopidy.com: http://apt.mopidy.com/ .. _PyPI: https://pypi.python.org/pypi/Mopidy-dLeyna/ .. _Documentation: https://mopidy-dleyna.readthedocs.io/ .. _Source code: https://github.com/tkem/mopidy-dleyna .. _Issue tracker: https://github.com/tkem/mopidy-dleyna/issues .. _Change log: https://github.com/tkem/mopidy-dleyna/blob/master/CHANGELOG.rst .. _Apache License, Version 2.0: https://raw.github.com/tkem/mopidy-dleyna/master/LICENSE ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/SOURCES.txt0000664000175100017510000000147115204700237022002 0ustar00tkemtkemCHANGELOG.rst LICENSE MANIFEST.in README.rst pyproject.toml setup.cfg setup.py tox.ini docs/conf.py docs/index.rst src/Mopidy_dLeyna.egg-info/PKG-INFO src/Mopidy_dLeyna.egg-info/SOURCES.txt src/Mopidy_dLeyna.egg-info/dependency_links.txt src/Mopidy_dLeyna.egg-info/entry_points.txt src/Mopidy_dLeyna.egg-info/not-zip-safe src/Mopidy_dLeyna.egg-info/requires.txt src/Mopidy_dLeyna.egg-info/top_level.txt src/mopidy_dleyna/__init__.py src/mopidy_dleyna/backend.py src/mopidy_dleyna/client.py src/mopidy_dleyna/ext.conf src/mopidy_dleyna/library.py src/mopidy_dleyna/playback.py src/mopidy_dleyna/translator.py src/mopidy_dleyna/util.py tests/__init__.py tests/conftest.py tests/test_browse.py tests/test_extension.py tests/test_images.py tests/test_lookup.py tests/test_playback.py tests/test_search.py tests/test_translator.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/dependency_links.txt0000664000175100017510000000000115204700237024161 0ustar00tkemtkem ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/entry_points.txt0000664000175100017510000000005615204700237023412 0ustar00tkemtkem[mopidy.ext] dleyna = mopidy_dleyna:Extension ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775420577.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/not-zip-safe0000664000175100017510000000000115164542241022345 0ustar00tkemtkem ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/requires.txt0000664000175100017510000000005115204700237022507 0ustar00tkemtkemmopidy>=4.0.0 pykka>=4.1 uritools>=4.0.3 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779663007.0 mopidy_dleyna-3.0.0/src/Mopidy_dLeyna.egg-info/top_level.txt0000664000175100017510000000001615204700237022642 0ustar00tkemtkemmopidy_dleyna ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1779663007.9740572 mopidy_dleyna-3.0.0/src/mopidy_dleyna/0000775000175100017510000000000015204700240016513 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/__init__.py0000664000175100017510000000166715204700037020642 0ustar00tkemtkemimport pathlib from mopidy import config, exceptions, ext __version__ = "3.0.0" class Extension(ext.Extension): dist_name = "Mopidy-dLeyna" ext_name = "dleyna" 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["upnp_browse_limit"] = config.Integer(minimum=0) schema["upnp_lookup_limit"] = config.Integer(minimum=0) schema["upnp_search_limit"] = config.Integer(minimum=0) schema["dbus_start_session"] = config.String() return schema def setup(self, registry): from .backend import dLeynaBackend registry.add("backend", dLeynaBackend) def validate_environment(self): try: import dbus # noqa except ImportError: raise exceptions.ExtensionError("Cannot import dbus") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/backend.py0000664000175100017510000000520415204700037020461 0ustar00tkemtkemimport errno import logging import os import os.path import re import signal import stat import subprocess from mopidy import backend, exceptions import pykka from . import Extension from .client import dLeynaClient from .library import dLeynaLibraryProvider from .playback import dLeynaPlaybackProvider DBUS_SESSION_BUS_RE = re.compile( r""" ^(?:DBUS_SESSION_BUS_ADDRESS=)?(.*)\n ^(?:DBUS_SESSION_BUS_PID=)?(\d+)$ """, re.MULTILINE | re.VERBOSE, ) logger = logging.getLogger(__name__) class dLeynaBackend(pykka.ThreadingActor, backend.Backend): uri_schemes = [Extension.ext_name] __dbus_pid = None def __init__(self, config, audio): super().__init__() try: if self.__have_session_bus(): self.client = dLeynaClient() else: command = config[Extension.ext_name]["dbus_start_session"] address, self.__dbus_pid = self.__start_session_bus(command) self.client = dLeynaClient(address) except Exception as e: logger.error("Error starting %s: %s", Extension.dist_name, e) # TODO: clean way to bail out late? raise exceptions.ExtensionError("Error starting dLeyna client") self.library = dLeynaLibraryProvider(self, config) self.playback = dLeynaPlaybackProvider(audio, self) def on_stop(self): if self.__dbus_pid is not None: self.__stop_session_bus(self.__dbus_pid) def __have_session_bus(self): if "DBUS_SESSION_BUS_ADDRESS" in os.environ: return True if "XDG_RUNTIME_DIR" not in os.environ: return False try: st = os.stat(os.path.expandvars("$XDG_RUNTIME_DIR/bus")) except OSError: return False else: return stat.S_ISSOCK(st.st_mode) and st.st_uid == os.geteuid() def __start_session_bus(self, command): logger.info("Starting %s D-Bus daemon", Extension.dist_name) out = subprocess.check_output(command.split(), universal_newlines=True) logger.debug('Running "%s" returned:\n%s', command, out) match = DBUS_SESSION_BUS_RE.search(out) if not match: raise ValueError(f"{command} returned invalid output: {out}") else: return str(match.group(1)), int(match.group(2)) def __stop_session_bus(self, pid): logger.error("Stopping %s D-Bus daemon (%d)", Extension.dist_name, pid) try: os.kill(pid, signal.SIGTERM) except OSError as e: if e.errno != errno.ESRCH: raise logger.debug("Stopped %s D-Bus daemon", Extension.dist_name) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/client.py0000664000175100017510000002333415204700037020354 0ustar00tkemtkemimport logging import threading import time from collections.abc import Mapping import dbus import uritools from . import Extension, util SERVER_BUS_NAME = "com.intel.dleyna-server" SERVER_ROOT_PATH = "/com/intel/dLeynaServer" SERVER_MANAGER_IFACE = "com.intel.dLeynaServer.Manager" logger = logging.getLogger(__name__) def urifilter(fields): if "URI" in fields: objfilter = fields[:] objfilter.remove("URI") objfilter.append("Path") objfilter.append("RefPath") return objfilter else: return fields def urimapper(baseuri, prefix="/com/intel/dLeynaServer/server/"): default_index = len(prefix) def mapper(obj, index=default_index): objpath = obj.get("RefPath", obj["Path"]) assert objpath.startswith(prefix) _, sep, relpath = objpath[index:].partition("/") obj["URI"] = baseuri + sep + relpath return obj return mapper class Servers(Mapping): def __init__(self, bus): self.__bus = bus self.__lock = threading.RLock() self.__servers = {} bus.add_signal_receiver( self.__found_server, "FoundServer", bus_name=SERVER_BUS_NAME ) bus.add_signal_receiver( self.__lost_server, "LostServer", bus_name=SERVER_BUS_NAME ) self.__get_servers() def __getitem__(self, udn): key = udn.lower() with self.__lock: return self.__servers[key] def __iter__(self): with self.__lock: return iter(list(self.__servers)) def __len__(self): with self.__lock: return len(self.__servers) def __add_server(self, obj): udn = obj["UDN"] obj["URI"] = uritools.uricompose(Extension.ext_name, udn) obj["DisplayName"] = obj.get("DisplayName", obj["URI"]) key = udn.lower() if key not in self: self.__log_server_action("Found", obj) with self.__lock: self.__servers[key] = obj def __remove_server(self, obj): key = obj["UDN"].lower() with self.__lock: del self.__servers[key] self.__log_server_action("Lost", obj) def __found_server(self, path): def error_handler(e): logger.warning("Cannot access media server %s: %s", path, e) self.__bus.get_object(SERVER_BUS_NAME, path).GetAll( "", # all interfaces dbus_interface=dbus.PROPERTIES_IFACE, reply_handler=self.__add_server, error_handler=error_handler, ) def __lost_server(self, path): with self.__lock: servers = list(self.__servers.values()) for obj in servers: if obj["Path"] == path: return self.__remove_server(obj) logger.info("Lost digital media server %s", path) def __get_servers(self): def reply_handler(paths): for path in paths: self.__found_server(path) def error_handler(e): logger.error("Cannot retrieve digital media servers: %s", e) self.__bus.get_object(SERVER_BUS_NAME, SERVER_ROOT_PATH).GetServers( dbus_interface=SERVER_MANAGER_IFACE, reply_handler=reply_handler, error_handler=error_handler, ) @classmethod def __log_server_action(cls, action, obj): logger.info( "%s digital media server %s [%s]", action, obj["FriendlyName"], obj["UDN"], ) class dLeynaClient: MEDIA_CONTAINER_IFACE = "org.gnome.UPnP.MediaContainer2" MEDIA_DEVICE_IFACE = "com.intel.dLeynaServer.MediaDevice" MEDIA_ITEM_IFACE = "org.gnome.UPnP.MediaItem2" MEDIA_OBJECT_IFACE = "org.gnome.UPnP.MediaObject2" def __init__(self, address=None, mainloop=None): if address: self.__bus = dbus.bus.BusConnection(address, mainloop=mainloop) else: self.__bus = dbus.SessionBus(mainloop=mainloop) self.__servers = Servers(self.__bus) def browse(self, uri, offset=0, limit=0, filter=None, order=None): if filter is None: filter = ["*"] if order is None: order = [] baseuri, objpath = self.__parseuri(uri) future = util.Future.fromdbus( self.__bus.get_object(SERVER_BUS_NAME, objpath).ListChildrenEx, dbus.UInt32(offset), dbus.UInt32(limit), urifilter(filter), ",".join(self.__sortorder(uri, order)), dbus_interface=self.MEDIA_CONTAINER_IFACE, ) def mapper(res): if baseuri and (filter == ["*"] or "URI" in filter): objs = map(urimapper(baseuri), res) else: objs = res # dleyna does not pass TotalMatches from Browse action; # also note that a server may choose to return less than # `limit` items, so assume `more` until nothing found more = len(res) != 0 return objs, more return future.map(mapper) def properties(self, uri, iface=None): baseuri, objpath = self.__parseuri(uri) future = util.Future.fromdbus( self.__bus.get_object(SERVER_BUS_NAME, objpath).GetAll, iface or "", dbus_interface=dbus.PROPERTIES_IFACE, ) if baseuri and (not iface or iface == self.MEDIA_OBJECT_IFACE): return future.map(urimapper(baseuri)) else: return future def rescan(self): return util.Future.fromdbus( self.__bus.get_object(SERVER_BUS_NAME, SERVER_ROOT_PATH).Rescan, dbus_interface=SERVER_MANAGER_IFACE, ) def search(self, uri, query, offset=0, limit=0, filter=None, order=None): if filter is None: filter = ["*"] if order is None: order = [] baseuri, objpath = self.__parseuri(uri) future = util.Future.fromdbus( self.__bus.get_object(SERVER_BUS_NAME, objpath).SearchObjectsEx, query, dbus.UInt32(offset), dbus.UInt32(limit), urifilter(filter), ",".join(self.__sortorder(uri, order)), dbus_interface=self.MEDIA_CONTAINER_IFACE, ) def mapper(res): items, total = res if baseuri and (filter == ["*"] or "URI" in filter): objs = map(urimapper(baseuri), items) else: objs = items more = offset + len(items) < total return objs, more return future.map(mapper) def server(self, uri): # return future for consistency/future extensions return util.Future.fromvalue(self.__server(uri)) def servers(self): # return future for consistency/future extensions return util.Future.fromvalue(self.__servers.values()) def __parseuri(self, uri): try: server = self.__server(uri) except ValueError: return None, uri else: return server["URI"], server["Path"] + uritools.urisplit(uri).path def __sortorder(self, uri, order): try: server = self.__server(uri) except ValueError: sortcaps = frozenset("*") else: sortcaps = frozenset(server.get("SortCaps", [])) if "*" in sortcaps: return order else: return list(filter(lambda f: f[1:] in sortcaps, order)) def __server(self, uri): udn = uritools.urisplit(uri).gethost() if not udn: raise ValueError("Invalid URI %s" % uri) try: server = self.__servers[udn] except KeyError: raise LookupError("Unknown media server UDN %s" % udn) else: return server if __name__ == "__main__": # pragma: no cover import argparse import json import sys import dbus.mainloop.glib import gobject parser = argparse.ArgumentParser() parser.add_argument("uri", metavar="PATH | URI", nargs="?") parser.add_argument("-b", "--browse", action="store_true") parser.add_argument("-f", "--filter", default=["*"], nargs="*") parser.add_argument("-i", "--iface") parser.add_argument("-m", "--offset", default=0, type=int) parser.add_argument("-n", "--limit", default=0, type=int) parser.add_argument("-o", "--order", default=[], nargs="*") parser.add_argument("-q", "--query") parser.add_argument("-t", "--timeout", default=1.0, type=float) parser.add_argument("-v", "--verbose", action="store_true") args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.verbose else logging.WARN) client = dLeynaClient(mainloop=dbus.mainloop.glib.DBusGMainLoop()) start = time.time() while time.time() < start + args.timeout: if args.uri: try: client.server(args.uri).get() except LookupError: pass except ValueError: break # D-BUS path given else: break gobject.MainLoop().get_context().iteration(False) kwargs = { "offset": args.offset, "limit": args.limit, "filter": args.filter, "order": args.order, } if not args.uri: future = client.servers() elif args.browse: future = client.browse(args.uri, **kwargs) elif args.query: future = client.search(args.uri, args.query, **kwargs) else: future = client.properties(args.uri, iface=args.iface) while True: try: future.get(timeout=0) except util.Future.Timeout: gobject.MainLoop().get_context().iteration(True) else: break json.dump(future.get(), sys.stdout, default=vars, indent=2) sys.stdout.write("\n") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/ext.conf0000664000175100017510000000110415164544650020176 0ustar00tkemtkem[dleyna] enabled = true # maximum number of objects to retrieve per UPnP Browse action, or 0 # to retrieve all objects upnp_browse_limit = 500 # maximum number of objects to retrieve by ID in a single UPnP Search # action (if supported by device), or 0 for no limit upnp_lookup_limit = 20 # maximum number of objects to retrieve per UPnP Search action, or 0 # to retrieve all objects upnp_search_limit = 100 # command to start session bus if none found, e.g. when running Mopidy # as a service dbus_start_session = dbus-daemon --fork --session --print-address=1 --print-pid=1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/library.py0000664000175100017510000001636115204700037020544 0ustar00tkemtkemimport collections import itertools import logging import operator from mopidy import backend, models import uritools from . import Extension, translator logger = logging.getLogger(__name__) BROWSE_FILTER = ["DisplayName", "Type", "TypeEx", "URI"] IMAGES_FILTER = ["AlbumArtURL", "URI"] LOOKUP_FILTER = SEARCH_FILTER = [ "Album", "AlbumArtURL", "Artist", "Artists", "Bitrate", "Date", "DisplayName", "Duration", "Genre", "TrackNumber", "Type", "TypeEx", "URI", ] BROWSE_ORDER = { models.Ref.ALBUM: ["+TrackNumber", "+DisplayName"], models.Ref.ARTIST: ["+TypeEx", "+DisplayName"], models.Ref.DIRECTORY: ["+TypeEx", "+DisplayName"], } LOOKUP_QUERY = 'Type = "music" or Type = "audio"' # TODO: check SearchCaps def iterate(func, translate, limit): count = 0 future = func(count, limit) while future: try: objs, more = future.get() except Exception: # some media servers will raise a DBusException when # iterating beyond the last item, which may happen with # Browse due to dLeyna not passing TotalMatches... if count: break else: raise if more: objs = list(objs) count += len(objs) future = func(count, limit) else: future = None for obj in objs: try: result = translate(obj) except ValueError as e: logger.debug("Skipping %s: %s", obj.get("URI"), e) else: yield result class dLeynaLibraryProvider(backend.LibraryProvider): root_directory = models.Ref.directory( uri=uritools.uricompose(Extension.ext_name), name="Digital Media Servers", ) def __init__(self, backend, config): super().__init__(backend) ext_config = config[Extension.ext_name] self.__upnp_browse_limit = ext_config["upnp_browse_limit"] self.__upnp_lookup_limit = ext_config["upnp_lookup_limit"] self.__upnp_search_limit = ext_config["upnp_search_limit"] def browse(self, uri): if uri == self.root_directory.uri: refs = sorted(self.__servers, key=operator.attrgetter("name")) else: refs = self.__browse(uri) return list(refs) def get_images(self, uris): # TODO: suggest as API improvement uris = frozenset(uris) # group uris by authority (media server) queries = collections.defaultdict(list) for uri in uris.difference([self.root_directory.uri]): parts = uritools.urisplit(uri) baseuri = parts.scheme + "://" + parts.authority queries[baseuri].append(parts.path) # start searching - blocks only when iterating over results results = [] for baseuri, paths in queries.items(): try: iterable = self.__images(baseuri, paths) except NotImplementedError as e: logger.warning("Not retrieving images for %s: %s", baseuri, e) else: results.append(iterable) # merge results result = {} for uri, images in itertools.chain.from_iterable(results): result[uri] = tuple(images) if self.root_directory.uri in uris: result[self.root_directory.uri] = tuple() return result def lookup(self, uri): if uri == self.root_directory.uri: tracks = [] else: tracks = self.__lookup(uri) return list(tracks) def refresh(self, uri=None): logger.info("Refreshing dLeyna library") self.backend.client.rescan().get() def search(self, query=None, uris=None, exact=False): # sanitize uris - remove duplicates, replace root with server uris uris = set(uris or [self.root_directory.uri]) if self.root_directory.uri in uris: uris.update(ref.uri for ref in self.__servers) uris.remove(self.root_directory.uri) # start searching - blocks only when iterating over results results = [] for uri in uris: try: iterable = self.__search(uri, query, exact) except NotImplementedError as e: logger.warning("Not searching %s: %s", uri, e) else: results.append(iterable) if not results: return None # retrieve and merge search results - TODO: handle exceptions? result = collections.defaultdict(collections.OrderedDict) for model in itertools.chain.from_iterable(results): result[type(model)][model.uri] = model return models.SearchResult( albums=result[models.Album].values(), artists=result[models.Artist].values(), tracks=result[models.Track].values(), ) def __browse(self, uri, filter=BROWSE_FILTER): client = self.backend.client obj = client.properties(uri, iface=client.MEDIA_OBJECT_IFACE).get() order = BROWSE_ORDER[translator.ref(obj).type] def browse(offset, limit): return client.browse(uri, offset, limit, filter, order) return iterate(browse, translator.ref, self.__upnp_browse_limit) def __images(self, baseuri, paths, filter=IMAGES_FILTER): client = self.backend.client server = client.server(baseuri).get() # fall back on properties if path search is not available/enabled if self.__upnp_lookup_limit == 1 or "Path" not in server["SearchCaps"]: futures = [client.properties(baseuri + path) for path in paths] return (translator.images(f.get()) for f in futures) # use path search for retrieving multiple results at once root = server["Path"] def images(offset, limit): slice = paths[offset : offset + limit if limit else None] query = " or ".join(f'Path = "{root}{p}"' for p in slice) return client.search(baseuri, query, 0, 0, filter).map( lambda res: (res[0], limit and offset + limit < len(paths)) ) return iterate(images, translator.images, self.__upnp_lookup_limit) def __lookup(self, uri, filter=LOOKUP_FILTER): client = self.backend.client obj = client.properties(uri).get() if translator.ref(obj).type == models.Ref.TRACK: objs = [obj] else: objs, _ = client.search(uri, LOOKUP_QUERY, filter=filter).get() return map(translator.track, objs) def __search(self, uri, query, exact, filter=SEARCH_FILTER): client = self.backend.client server = client.server(uri).get() if server["SearchCaps"]: q = translator.query(query or {}, exact, server["SearchCaps"]) else: raise NotImplementedError("Search is not supported by this device") def search(offset, limit): return client.search(uri, q, offset, limit, filter) return iterate(search, translator.model, self.__upnp_search_limit) @property def __servers(self): for server in self.backend.client.servers().get(): name = server.get("FriendlyName", server["DisplayName"]) yield models.Ref.directory(name=name, uri=server["URI"]) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/playback.py0000664000175100017510000000075215164544650020677 0ustar00tkemtkemimport logging from mopidy import backend logger = logging.getLogger(__name__) class dLeynaPlaybackProvider(backend.PlaybackProvider): def translate_uri(self, uri): # TODO: GetCompatibleResources w/protocol_info client = self.backend.client try: obj = client.properties(uri, client.MEDIA_ITEM_IFACE).get() except Exception as e: logger.error("Error translating %s: %s", uri, e) else: return obj["URLs"][0] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/translator.py0000664000175100017510000000753115204700037021270 0ustar00tkemtkemfrom mopidy import models _QUERY = { "any": lambda caps: " or ".join( s + ' {0} "{1}"' for s in caps & {"DisplayName", "Album", "Artist", "Genre"} ), "album": lambda caps: 'Album {0} "{1}"' if "Album" in caps else None, "albumartist": lambda caps: ( 'Artist {0} "{1}" and TypeEx = "container.album.musicAlbum"' if "Artist" in caps and "TypeEx" in caps else None ), "artist": lambda caps: 'Artist {0} "{1}"' if "Artist" in caps else None, "date": lambda caps: 'Date = "{1}"' if "Date" in caps else None, # TODO: inexact? "genre": lambda caps: 'Genre {0} "{1}"' if "Genre" in caps else None, "track_name": lambda caps: ( 'DisplayName {0} "{1}" and Type = "music"' if "DisplayName" in caps and "Type" in caps else None ), "track_no": lambda caps: 'TrackNumber = "{1}"' if "TrackNumber" in caps else None, } _REFS = { "audio": models.Ref.track, "container": models.Ref.directory, "container.album": models.Ref.directory, "container.album.musicAlbum": models.Ref.album, "container.genre.musicGenre": models.Ref.directory, "container.person.musicArtist": models.Ref.artist, "container.playlistContainer": models.Ref.directory, "container.storageFolder": models.Ref.directory, "item.audioItem.audioBook": models.Ref.track, "item.audioItem.audioBroadcast": models.Ref.track, "music": models.Ref.track, } def _album(obj): try: name = obj["Album"] except KeyError: return None else: return models.Album(name=name, uri=None) def _artists(obj): return (models.Artist(name=name) for name in obj.get("Artists", [])) def _quote(s): return str(s).replace("\\", "\\\\").replace('"', '\\"') def ref(obj): type = obj.get("TypeEx", obj["Type"]) try: translate = _REFS[type] except KeyError: raise ValueError('Object type "%s" not supported' % type) else: return translate(name=obj.get("DisplayName", obj["URI"]), uri=obj["URI"]) def album(obj): return models.Album( uri=obj["URI"], name=obj["DisplayName"], artists=list(_artists(obj)), num_tracks=obj.get("ItemCount", obj.get("ChildCount")), ) def artist(obj): return models.Artist(name=obj["DisplayName"], uri=obj["URI"]) def track(obj): return models.Track( uri=obj["URI"], name=obj["DisplayName"], artists=list(_artists(obj)), album=_album(obj), genre=obj.get("Genre"), track_no=obj.get("TrackNumber"), date=obj.get("Date"), length=obj.get("Duration", 0) * 1000 or None, # DLNA bitrate is given in byte/s, but Mopidy wants kbit/s bitrate=int((obj.get("Bitrate", 0) * 8) / 1000) or None, ) def model(obj): type = obj.get("TypeEx", obj["Type"]) ref = _REFS.get(type) if ref == models.Ref.track: return track(obj) elif ref == models.Ref.album: return album(obj) elif ref == models.Ref.artist: return artist(obj) else: raise ValueError('Object type "%s" not supported' % type) def images(obj): if "AlbumArtURL" in obj: return obj["URI"], [models.Image(uri=str(obj["AlbumArtURL"]))] else: return obj["URI"], [] def query(query, exact, searchcaps): op = "=" if exact else "contains" terms = [] for key, values in query.items(): try: translate = _QUERY[key] except KeyError: raise NotImplementedError('Keyword "%s" not supported' % key) else: fmt = translate(frozenset(searchcaps)) if fmt: terms.extend(fmt.format(op, _quote(value)) for value in values) else: raise NotImplementedError('Keyword "%s" not searchable' % key) q = ("(%s)" % ") and (".join(terms)) or "*" return f'(Type = "music" or Type = "audio") and {q}' ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/src/mopidy_dleyna/util.py0000664000175100017510000000206615204700037020052 0ustar00tkemtkemimport logging import time import pykka logger = logging.getLogger(__name__) class Future(pykka.ThreadingFuture): Timeout = pykka.Timeout @classmethod def exception(cls, exc=None): future = cls() future.set_exception((type(exc), exc, None)) return future @classmethod def fromdbus(cls, func, *args, **kwargs): method = getattr(func, "_method_name", "") logger.debug("Calling D-Bus method %s%s", method, args) future = cls() start = time.time() def reply(*args): logger.debug("%s reply after %.3fs", method, time.time() - start) future.set(args[0] if len(args) == 1 else args) def error(e): logger.debug("%s error after %.3fs", method, time.time() - start) future.set_exception(exc_info=(type(e), e, None)) func(*args, reply_handler=reply, error_handler=error, **kwargs) return future @classmethod def fromvalue(cls, value): future = cls() future.set(value) return future ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1779663007.974744 mopidy_dleyna-3.0.0/tests/0000775000175100017510000000000015204700240014231 5ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1597080925.0 mopidy_dleyna-3.0.0/tests/__init__.py0000644000175100017510000000000013714302535016337 0ustar00tkemtkem././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1597080925.0 mopidy_dleyna-3.0.0/tests/conftest.py0000644000175100017510000000141113714302535016434 0ustar00tkemtkemfrom unittest import mock import pytest @pytest.fixture def audio(): return mock.Mock() @pytest.fixture def config(): return { "dleyna": { "upnp_browse_limit": 1000, "upnp_lookup_limit": 50, "upnp_search_limit": 100, } } @pytest.fixture def client(): client_mock = mock.Mock() return client_mock @pytest.fixture def backend(config, audio, client): from mopidy import backend from mopidy_dleyna import library, playback backend_mock = mock.Mock(spec=backend.Backend) backend_mock.client = client backend_mock.library = library.dLeynaLibraryProvider(backend_mock, config) backend_mock.playback = playback.dLeynaPlaybackProvider(audio, backend_mock) return backend_mock ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_browse.py0000664000175100017510000000357615164544650017176 0ustar00tkemtkemfrom unittest import mock from mopidy.models import Ref from mopidy_dleyna.util import Future import pytest @pytest.fixture def servers(): return [ { "FriendlyName": "Media Server #1", "DisplayName": "Media1", "URI": "dleyna://media1", }, { "FriendlyName": "Media Server #2", "DisplayName": "Media2", "URI": "dleyna://media2", }, ] @pytest.fixture def container(): return {"DisplayName": "Root", "Type": "container", "URI": "dleyna://media"} @pytest.fixture def items(): return [ {"DisplayName": "Track #1", "Type": "music", "URI": "dleyna://media/1"}, {"DisplayName": "Track #2", "Type": "audio", "URI": "dleyna://media/2"}, {"DisplayName": "Track #3", "Type": "audio", "URI": "dleyna://media/3"}, ] def test_browse_root(backend, servers): with mock.patch.object(backend, "client") as m: m.servers.return_value = Future.fromvalue(servers) assert backend.library.browse(backend.library.root_directory.uri) == [ Ref.directory(name="Media Server #1", uri="dleyna://media1"), Ref.directory(name="Media Server #2", uri="dleyna://media2"), ] def test_browse_items(backend, container, items): # FIXME: how to patch multiple object methods... with mock.patch.object(backend, "client") as m: m.properties.return_value = Future.fromvalue(container) m.browse.side_effect = [ Future.fromvalue([items[0:2], True]), Future.fromvalue([items[2:3], True]), Future.fromvalue([[], False]), ] assert backend.library.browse(container["URI"]) == [ Ref.track(name="Track #1", uri="dleyna://media/1"), Ref.track(name="Track #2", uri="dleyna://media/2"), Ref.track(name="Track #3", uri="dleyna://media/3"), ] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1597080925.0 mopidy_dleyna-3.0.0/tests/test_extension.py0000644000175100017510000000067713714302535017677 0ustar00tkemtkemfrom mopidy_dleyna import Extension def test_get_default_config(): config = Extension().get_default_config() assert "[" + Extension.ext_name + "]" in config assert "enabled = true" in config def test_get_config_schema(): schema = Extension().get_config_schema() assert "upnp_browse_limit" in schema assert "upnp_lookup_limit" in schema assert "upnp_search_limit" in schema assert "dbus_start_session" in schema ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_images.py0000664000175100017510000000220315164544650017124 0ustar00tkemtkemfrom unittest import mock from mopidy import models from mopidy_dleyna.util import Future import pytest @pytest.fixture def server(): return { "FriendlyName": "Media Server", "DisplayName": "Media", "SearchCaps": ["DisplayName", "Path"], "Path": "/com/intel/dLeynaServer/server/0", "URI": "dleyna://media", } @pytest.fixture def items(): return [ { "DisplayName": "Track #1", "Type": "music", "AlbumArtURL": "http:://example.com/1.jpg", "URI": "dleyna://media/1", }, {"DisplayName": "Track #2", "Type": "audio", "URI": "dleyna://media/2"}, ] def test_images(backend, server, items): with mock.patch.object(backend, "client") as m: m.servers.return_value = Future.fromvalue([server]) m.server.return_value = Future.fromvalue(server) m.search.return_value = Future.fromvalue([items, False]) assert backend.library.get_images(item["URI"] for item in items) == { items[0]["URI"]: (models.Image(uri=items[0]["AlbumArtURL"]),), items[1]["URI"]: tuple(), } ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_lookup.py0000664000175100017510000000266515164544650017204 0ustar00tkemtkemfrom unittest import mock from mopidy import models from mopidy_dleyna.util import Future import pytest @pytest.fixture def container(): return { "DisplayName": "Album #1", "Type": "container", "TypeEx": "container.album.musicAlbum", "URI": "dleyna://media/1", } @pytest.fixture def items(): return [ { "DisplayName": "Track #1", "Type": "music", "URI": "dleyna://media/11", }, { "DisplayName": "Track #2", "Type": "audio", "URI": "dleyna://media/12", }, ] def test_lookup_root(backend): assert backend.library.lookup(backend.library.root_directory.uri) == [] def test_lookup_item(backend, items): with mock.patch.object(backend, "client") as m: m.properties.return_value = Future.fromvalue(items[0]) assert backend.library.lookup(items[0]["URI"]) == [ models.Track(name="Track #1", uri="dleyna://media/11") ] def test_lookup_container(backend, container, items): with mock.patch.object(backend, "client") as m: m.properties.return_value = Future.fromvalue(container) m.search.return_value = Future.fromvalue([items, False]) assert backend.library.lookup(container["URI"]) == [ models.Track(name="Track #1", uri="dleyna://media/11"), models.Track(name="Track #2", uri="dleyna://media/12"), ] ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_playback.py0000664000175100017510000000133415164544650017451 0ustar00tkemtkemfrom unittest import mock from mopidy_dleyna.util import Future import pytest @pytest.fixture def item(): return { "DisplayName": "Track #1", "Type": "music", "URI": "dleyna://media/1", "URLs": ["http://example.com/1.mp3"], } def test_translate_uri(backend, item): with mock.patch.object(backend, "client") as m: m.properties.return_value = Future.fromvalue(item) assert backend.playback.translate_uri(item["URI"]) == item["URLs"][0] def test_translate_unknown_uri(backend): with mock.patch.object(backend, "client") as m: m.properties.return_value = Future.exception(LookupError("Not Found")) assert backend.playback.translate_uri("") is None ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_search.py0000664000175100017510000000335615164544650017136 0ustar00tkemtkemfrom unittest import mock from mopidy import models from mopidy_dleyna.util import Future import pytest @pytest.fixture def server(): return { "FriendlyName": "Media Server", "DisplayName": "Media", "SearchCaps": ["DisplayName"], "URI": "dleyna://media", } @pytest.fixture def result(): return [ { "DisplayName": "Album #1", "Type": "container", "TypeEx": "container.album.musicAlbum", "URI": "dleyna://media/1", }, { "DisplayName": "Track #1", "Type": "music", "URI": "dleyna://media/11", }, { "DisplayName": "Track #2", "Type": "audio", "URI": "dleyna://media/12", }, ] def test_search(backend, server, result): with mock.patch.object(backend, "client") as m: m.servers.return_value = Future.fromvalue([server]) m.server.return_value = Future.fromvalue(server) m.search.side_effect = [ Future.fromvalue([result[0:2], True]), Future.fromvalue([result[2:3], False]), ] # valid search assert backend.library.search({"any": ["foo"]}) == models.SearchResult( albums=[models.Album(name="Album #1", uri="dleyna://media/1")], tracks=[ models.Track(name="Track #1", uri="dleyna://media/11"), models.Track(name="Track #2", uri="dleyna://media/12"), ], ) # unsupported search field yields no result assert backend.library.search({"composer": ["foo"]}) is None # search field not supported by device yields no result assert backend.library.search({"genre": ["foo"]}) is None ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1775421864.0 mopidy_dleyna-3.0.0/tests/test_translator.py0000664000175100017510000000725415164544650020063 0ustar00tkemtkemfrom mopidy.models import Album, Artist, Ref, Track from mopidy_dleyna import translator import pytest BASEURI = "dleyna://foo" BASEPATH = "/com/intel/dLeynaServer/server/0" ALBUM_TYPE = "container.album.musicAlbum" ARTIST_TYPE = "container.person.musicArtist" PLAYLIST_TYPE = "container.playlistContainer" AUDIO_BOOK_TYPE = "item.audioItem.audioBook" AUDIO_BROADCAST_TYPE = "item.audioItem.audioBroadcast" def test_album_ref(): assert translator.ref( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container", "TypeEx": ALBUM_TYPE, } ) == Ref.album(uri=BASEURI + "/foo", name="Foo") def test_artist_ref(): assert translator.ref( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container", "TypeEx": ARTIST_TYPE, } ) == Ref.artist(uri=BASEURI + "/foo", name="Foo") def test_music_ref(): assert translator.ref( {"DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "music"} ) == Ref.track(uri=BASEURI + "/foo", name="Foo") def test_audio_book_ref(): assert translator.ref( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "audio", "TypeEx": AUDIO_BOOK_TYPE, } ) == Ref.track(uri=BASEURI + "/foo", name="Foo") def test_audio_broadcast_ref(): assert translator.ref( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "audio", "TypeEx": AUDIO_BROADCAST_TYPE, } ) == Ref.track(uri=BASEURI + "/foo", name="Foo") def test_container_ref(): assert translator.ref( {"DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container"} ) == Ref.directory(uri=BASEURI + "/foo", name="Foo") def test_video_ref(): with pytest.raises(ValueError): translator.ref({"DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "video"}) def test_album(): assert translator.model( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container", "TypeEx": ALBUM_TYPE, } ) == Album(uri=BASEURI + "/foo", name="Foo") def test_artist(): assert translator.model( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container", "TypeEx": ARTIST_TYPE, } ) == Artist(uri=BASEURI + "/foo", name="Foo") def test_playlist(): assert translator.ref( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "container", "TypeEx": PLAYLIST_TYPE, } ) == Ref.directory(uri=BASEURI + "/foo", name="Foo") def test_track(): assert translator.model( { "DisplayName": "Foo", "Album": "Bar", "URI": BASEURI + "/foo", "Type": "music", } ) == Track(uri=BASEURI + "/foo", name="Foo", album=Album(name="Bar")) def test_audio_book(): assert translator.model( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "audio", "TypeEx": AUDIO_BOOK_TYPE, } ) == Track(uri=BASEURI + "/foo", name="Foo") def test_audio_broadcast(): assert translator.model( { "DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "audio", "TypeEx": AUDIO_BROADCAST_TYPE, } ) == Track(uri=BASEURI + "/foo", name="Foo") def test_video(): with pytest.raises(ValueError): translator.model( {"DisplayName": "Foo", "URI": BASEURI + "/foo", "Type": "video"} ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1779662879.0 mopidy_dleyna-3.0.0/tox.ini0000664000175100017510000000107515204700037014411 0ustar00tkemtkem[tox] envlist = py,docs,ruff,ruff-format [testenv] deps = pytest pytest-cov commands = py.test --basetemp={envtmpdir} --cov=mopidy_dleyna --cov-report term-missing {posargs} [testenv:docs] deps = sphinx commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html [testenv:ruff] deps = ruff commands = ruff check {posargs} skip_install = true [testenv:ruff-format] deps = ruff commands = ruff format --diff -q {posargs} skip_install = true [testenv:pyright] deps = pyright commands = pyright {posargs}