Skip to content

Commit

Permalink
fix: list other playlists also if some are broken
Browse files Browse the repository at this point in the history
...instead of completely failing to list playlists when one playlist is malformed.
  • Loading branch information
mgoltzsche committed Mar 20, 2024
1 parent ec07df6 commit 8c96906
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ beet webm3u

You can browse the server at [`http://localhost:8339`](http://localhost:8339).

To serve multiple beets web APIs using a single process, you can use the [webrouter plugin](https://github.com/mgoltzsche/beets-webrouter).

### CLI

```
Expand Down Expand Up @@ -99,4 +101,3 @@ To just start the server, run:
```sh
make beets-webm3u
```

24 changes: 15 additions & 9 deletions beetsplug/webm3u/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def _transform_playlist(playlist):
skipped = True
msg = f"Skipping playlist item(s) because URI format refers to missing key {e}"
current_app.logger.warning(msg)
yield f"# {msg}\n"
continue
yield f"#EXTINF:{item.duration},{item.title}\n{item_uri}\n"

Expand Down Expand Up @@ -123,7 +124,8 @@ def _serve_files(tpl, title, root_dir, path, filter, handler, infofn):
def _files(dir, filter, infofn):
l = [f for f in os.listdir(dir) if _is_file(dir, f) and filter(f)]
l.sort()
return [infofn(dir, f) for f in l]
files = [infofn(dir, f) for f in l]
return [f for f in files if f]

def _file_info(dir, filename):
st = os.stat(safe_join(dir, filename))
Expand All @@ -136,14 +138,18 @@ def _file_info(dir, filename):
def _playlist_info(dir, filename):
filepath = os.path.join(dir, filename)
relpath = os.path.relpath(filepath, playlist_provider().dir)
playlist = playlist_provider().playlist(relpath)
return {
'name': playlist.name,
'path': playlist.id,
'count': playlist.count,
'duration': playlist.duration,
'info': playlist.artists,
}
try:
playlist = playlist_provider().playlist(relpath)
return {
'name': playlist.name,
'path': playlist.id,
'count': playlist.count,
'duration': playlist.duration,
'info': playlist.artists,
}
except Exception as e:
current_app.logger.error(f"Failed to load playlist {filepath}: {e}")
return None

def _is_file(dir, filename):
f = os.path.join(dir, filename)
Expand Down

0 comments on commit 8c96906

Please sign in to comment.