Do not let the web plugin overwrite the Content-Length header with the full file length since flask/werkzeug sets the requested range's/chunk's size when handling a range request.
This allows to play large audio/opus files using e.g. a browser/firefox or gstreamer/mopidy without making a reverse-proxy/nginx emulate range request support and hide range-related headers from the backend.
cf. https://github.com/pallets/werkzeug/issues/2506
didn't check when part_isolating was introduced, but presumably, it
should be harmless to set this attribute for old werkzeug versions that
didn't have it yet
This was a helper for situations when Python 2 and 3 APIs returned bytes
and unicode, respectively. In these situation, we should nowadays know
which of the two we receive, so there's no need to wrap & hide the
`bytes.decode()` anymore (when it is still required).
Detailed justification:
beets/ui/__init__.py:
- command line options are always parsed to str
beets/ui/commands.py:
- confuse's config.dump always returns str
- open(...) defaults to text mode, read()ing str
beetsplug/keyfinder.py:
- ...
beetsplug/web/__init__.py:
- internally, paths are always bytestrings
- additionally, I took the liberty to slighlty re-arrange the code: it
makes sense to split off the basename first, since we're only
interested in the unicode conversion of that part.
test/helper.py:
- capture_stdout() gives a StringIO, which yields str
test/test_ui.py:
- self.io, from _common.TestCase, ultimately contains a
_common.DummyOut, which appears to be dealing with str (cf.
DummyOut.get)
The routing map translator `QueryConverter` was misconfigured:
* decoding (parsing a path): splitting with "/" as tokenizer
* encoding (translating back to a path): joining items with "," as separator
This caused queries containing more than one condition (separated by a
slash) to return an empty result. Queries with only a single condition
were not affected.
Instead the encoding should have used the same delimiter (the slash) for the
backward conversion.
How to reproduce:
* query: `/album/query/albumartist::%5Efoo%24/original_year%2B/year%2B/album%2B`
* resulting content in parsed argument `queries` in the `album_query` function:
* previous (wrong): `['albumartist::^foo$,original_year+,year+,album+']`
* new (correct): `['albumartist::^foo$', 'original_year+', 'year+', 'album+']`
Also simplified the setup of the `readonly` value in the tests which
fixes a test ordering issue found using --random-order.
Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
As discussed in bug #3867, backslash replacement in query strings is a bit of a
hack but it is useful (see #3566 and #3567 for more discussion). However,
it breaks many regular expressions so this patch stops the replacement if the
query term contains '::', indicating it is a regex match.
This commit fixes#3867.
Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
Track item paths and album artpaths should be removed from results unless
INCLUDE_PATHS is set. This works for items but for albums the artpath is always
removed.
This patch makes the artpath removal conditional on INCLUDE_PATHS not being set
and includes a regression test. Note: the default value for INCLUDE_PATHS is
False so no changes will be seen by users unless they already have
INCLUDE_PATHS set.
Signed-off-by: Graham R. Cobb <g+beets@cobb.uk.net>
Without this change the web plugin does not support path queries as
slashes are currently used for joining keywords in the QueryConverter.
Moreover, flask cannot distinguish between an URL encoded and a plain
'/' character during routing [0]. To work around this issue without
introducing a breaking change (i.e. removing the QueryConverter) use the
backslash character for path queries and convert it later on.
Fixes#3566
[0]: https://github.com/pallets/flask/issues/900
Converts bytes to unicode using util.text_string, assuming that the
string is a UTF-8 string.
If that fails, it falls back to a hardcoded fallback filename.
If the web plugin is behind a credential based http server and is
accessed by another in-browser client in another domain, the
specification of CORS requires the server to indicate it supports
such credentials.
flask.send_file() expects a string, g.lib.get_album() returns bytes. Added decode() to album_art().
If g.lib.get_album() gets a non-existing id, it returns None. Python would throw an error in this case. Added check to prevent this.
As suggested, changes around the for loop to make it a bit more
pythonic by using an if loop inside a normal for loop.
Signed-off-by: Mark Stenglein <mark@stengle.in>
This commit fixes issue #2532 by filtering out any byte values
added by any other extensions and decoding them to strings for the
JSON serializer.
It does not remove any of the keys, instead opting to just convert
them.
Signed-off-by: Mark Stenglein <mark@stengle.in>