-
Notifications
You must be signed in to change notification settings - Fork 21
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
[WIP] Album Art and Binary Responses #49
Conversation
I've not looked at this PR properly yet but have you seen https://docs.mopidy.com/en/latest/api/ext/#mopidy.ext.Extension.get_cache_dir ? |
For this I would need to explicitly import from |
Before you go any further with the cache, what's the aim? To avoid redownloading the image for each of the MPD client's chunked requests? If so, does it need to be on disk or is it better in memory and better as part of the connection context? I'm wary of caching anything in a frontend. Especially for long periods of time. |
And there should be nothing backed specific in a frontend e.g. the mopidy-local stuff doesn't belong in here. But I'll have a proper look later. |
Hm re the import, ok definitely not. I must have misunderstood what you were doing here. |
Currently it only saves the latest image in memory, it replaces this each time a new image is requested.
It would be nice if |
Ok so yes, I misunderstood why you were trying to find the cache directory, I thought you were saving stuff there rather than trying to work out where the local backend was keeping things. I blame trying to read it on a mobile. Doesn't Mopidy-Local's
For nearly all backends it would have to download the image, just as you are doing here. Except core doesn't have any MPD context and so it'd be harder to work out what was actually in use (when caching, which it would still need to do). And this core method seems specific to Mopidy-MPD, I don't think this would be generally useful.
This should be per-context. Imagine two different clients (or one client with two active connections) requesting different images at the same time . |
two thoughts:
from urllib.request import Request, urlopen
with urlopen(Request(image_uri, headers={'range': f'bytes={offset}-{offset+context.binary_limit-1}'})) as r:
bytes = r.read(context.binary_limit)
# length = r.headers.get('content-length') |
|
Yes, this is how it works. It provides relative URIs. i.e. But then none of this works if Mopidy-HTTP is not enabled. Which is ugly. And solved by loading the images directly from the disk, like you were doing. Although we an't assume we know where those files are. Or that Mopidy-Local hasnt changed and moved them. |
On Fri, Jan 14, 2022 at 10:30:14AM -0800, Nick Steel wrote:
However, unless I am missing something, Mopidy-MPD doesn't know the
server's root URI so it is stuck.
a simple hack would be to just connect to
http://localhost:<port-from-config>. this should sort out ipv4/ipv6
automatically, as well. the only i can see this fail was if the user
bound mopidy-http to a specific (non-loopback) interface, which i'd
assume is very unlikely.
I think the only sensible thing to do there is to fix Mopidy-Local to
use absolute image URIs. Thoughts?
does mopidy-local have a way to get the bind address? i assume not,
otherwise mopidy-mpd could use the same technique to get it itself.
i don't think we can extract a useful hostname+port combination from
tornado either; when the user binds to `0.0.0.0`, we can't connect to
that. so we're back to the hack above.
99% of the time the client is going to want all parts. I would imagine
multiple small requests are going to be slower overall but removing
caching sounds nice.
i'd assume that most album cover images are way less than the 1MB
default binarylimit anyways, so the overhead from multiple requests
hopefully shouldn't matter 99% of the time.
|
I was hoping to avoid guessing what the hostname was.
I think I have a way but it's too hacky to even consider. I'm almost coming round to the idea of |
with open( | ||
os.path.join(data_path, extension, "images", file), "rb" | ||
) as image_file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the file doesn't exist or we don't have read permissions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an excellent point, I'll worry about this once we decide on what we're doing.
What's wrong with a dependency on requests? The Mopidy core already has a hard dependency on it. Everything else already has a transitive dependency on it. |
resolves #17.
Adds the
albumart
,readpicture
andbinartlimit
commands, and the ability to respond with binary data.I need help working out how to get the location of local images with the information given to a command.
Also needs tests.