Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Re-enable Python scripts to access Quodlibet library #4242

Closed
davidSchlosser opened this issue Jan 4, 2023 · 6 comments
Closed

Re-enable Python scripts to access Quodlibet library #4242

davidSchlosser opened this issue Jan 4, 2023 · 6 comments

Comments

@davidSchlosser
Copy link

The proposed change

Allow stand-alone Python script access to the Quodlibet library as @lazka described in #1939 for Quodlibet 3.6

import os, sys
sys.path.insert(0, '/home/david/quodlibet')
import quodlibet
from quodlibet import library

quodlibet.init()
lib = library.init(os.path.join(quodlibet.get_user_dir(), "songs"))

With Quodlibet 4.6.1 this script fails with the following:

/home/david/quodlibet/quodlibet/qltk/__init__.py:21: PyGIWarning: PangoCairo was imported without specifying a version first. Use gi.require_version('PangoCairo', '1.0') before import to ensure that the right version gets loaded.
  from gi.repository import GLib, GObject, PangoCairo
Traceback (most recent call last):
  File "/home/david/PycharmProjects/qlbridge/access.py", line 8, in <module>
    quodlibet.init()
  File "/home/david/quodlibet/quodlibet/_init.py", line 55, in init
    init_cli(no_translations=no_translations, config_file=config_file)
  File "/home/david/quodlibet/quodlibet/_init.py", line 136, in init_cli
    _init_gettext(no_translations)
  File "/home/david/quodlibet/quodlibet/_init.py", line 76, in _init_gettext
    i18n.init(language)
  File "/home/david/quodlibet/quodlibet/util/i18n.py", line 282, in init
    assert "gi.repository.Gtk" not in sys.modules
AssertionError

Benefits of this change

I'll continue to use a script in newer Quodlibet versions to obtain & work with the song tag values extracted from the Quodlibet library, to support remote Quodlibet operation with simplified query creation from a mobile phone or tablet.

Any issues this might cause

I'm not sure if this is a documentation request for the Development Guide or FAQ, or a code change would be required.

@declension
Copy link
Member

Sorry about the delay.

Probably best to do this within the Python console (plugin) within QL itself

@davidSchlosser
Copy link
Author

My application operates from the command line so I don't see this could work. I have a work around using the QL query json command to effectively export the library, and processing the output, but unfortunately that doesn't perform well with a large library.

@declension
Copy link
Member

Thanks, I understand a bit more now.

I guess the first thing to mention is that it's only really a curiosity of Python packaging that allows loading an application as a library (import quodlibet); note that it's not possible on newer packaging environments e.g. Snap / Flatpak (or Docker even). The upshot is that there's no drive to keep these kinds of integrations working as things change within the app itself.

So I'm not sure what your integration is but if you can use any of the supported methods then it might do better - or of course mutagen itself is a library and so will have guarantees.

If you prefer the hackier approach though:

  • Try just moving the library import down:
import os, sys
sys.path.insert(0, '/home/david/quodlibet')
import quodlibet
quodlibet.init()

from quodlibet import library
lib = library.init(os.path.join(quodlibet.get_user_dir(), "songs"))
  • To do anythign properly, make sure you have all the dependencies installed (poetry install will do this nicely) - you can't really just insert quodlibet itself into PYTHONPATH and necessarily have it all work.

@davidSchlosser
Copy link
Author

Thanks for your suggestions. I won't get back to this for a while, but will check it out. Cheers!

@Moonbase59
Copy link

Moonbase59 commented Aug 12, 2023

@davidSchlosser: Don’t know if this helps, but my little bash script ql-playlists uses the following code to find—in this case—the saved searches:

  # Get QL saved searches file location.
  # We query QL for that since there are so many possibilities.
  queriesfile=$(python3 -c "import os.path; from quodlibet import get_user_dir; print(os.path.join(get_user_dir(), 'lists', 'queries.saved'))")

  if [ $? -ne 0 ] || [ ! -r "${queriesfile}" ] ; then
    echo "$me: Couldn't read Quod Libet's saved searches file. Aborting." >&2
    exit 1
  fi

@declension
Copy link
Member

Closing this for now, as plugins are the supported entry point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants