[generators] Fix playlist randomization
Some checks failed
Some checks failed
This commit is contained in:
@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
from typing import TYPE_CHECKING, cast
|
||||
|
||||
@ -38,6 +39,7 @@ def _mix_tracks(
|
||||
if not tracks:
|
||||
return []
|
||||
if max_per_album > 0:
|
||||
random.shuffle(tracks)
|
||||
seen: dict[str, int] = {}
|
||||
result: list[Track] = []
|
||||
for t in tracks:
|
||||
@ -50,6 +52,7 @@ def _mix_tracks(
|
||||
tracks = result
|
||||
if max_tracks > 0:
|
||||
tracks = tracks[:max_tracks]
|
||||
random.shuffle(tracks)
|
||||
return tracks
|
||||
|
||||
|
||||
@ -164,7 +167,11 @@ def save_smart_playlist(
|
||||
with open(filepath, "w") as f:
|
||||
f.write("#EXTM3U\n")
|
||||
for t in tracks:
|
||||
if t.uri:
|
||||
if not t.uri:
|
||||
continue
|
||||
name = (t.name or "").replace("\n", " ").strip()
|
||||
length = int(t.length / 1000) if t.length else -1
|
||||
f.write(f"#EXTINF:{length},{name}\n")
|
||||
f.write(f"{t.uri}\n")
|
||||
except Exception:
|
||||
logger.exception("Failed to write M3U8 file %s", filepath)
|
||||
|
||||
Reference in New Issue
Block a user