Repository navigation
Improve test coverage and fix a couple of potential bugs - #61
Merged
Merged
Conversation
parsers.py is a copy of the parsers in Mopidy's stream extension, so copy their tests too. The only changes are the import and the type annotations that our ruff rules ask for.
pytest collects classes whose name starts with Test, so the three ASX cases never ran. The base class only varied one value, which is what parametrize is for, and a plain function cannot go missing this way.
Use responses to answer the HTTP requests with payloads shaped like the ones the TuneIn API returns. The cache decorators are class attributes, so they hold results between tests. A fixture clears them before each test.
_get_playlist read the whole body unless the content type was exactly audio/mpeg. A live stream never ends, and the requests timeout only covers the wait between reads, so a station that serves, say, audio/aac made the call block until the connection dropped, with the backend thread and a cache slot held. Read the body in chunks now, and stop at the first of a size limit and a deadline. A body that does not stop is a stream, not a playlist, so report that there is no playlist. The caller then uses the URL as it is, which is what it already does for a stream.
find_playlist_parser() fell back to the content type when the URL had no known extension, but compared the whole header value, so a playlist served as "audio/x-scpls; charset=UTF-8" found no parser. Strip the parameters before the lookup, and add audio/x-mpegurl, which is what TuneIn servers send for M3U. Of 22 playlists collected from the TuneIn API, the fallback recognised 3 before this change and recognises all 22 after it. Use the same normalization for the audio/mpeg check in _get_playlist, where a content type with a charset made it read the body of a stream until the deadline passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.