refactor(Track): Rename extra to data, enforce type as dict

Setting data as a dictionary allows more places of code (including DASH, HLS, Services, etc) to get/set what they want by key instead of typically by index (list/tuple). Tuples or lists were typically in services because DASH and HLS stored needed data as a tuple and services did not want to interrupt or remove that data, even though it would be fine.
This commit is contained in:
rlaphoenix
2024-03-01 04:29:45 +00:00
parent a6a5699577
commit 90c544966a
3 changed files with 20 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ class Track:
name: Optional[str] = None,
drm: Optional[Iterable[DRM_T]] = None,
edition: Optional[str] = None,
extra: Optional[Any] = None,
data: Optional[dict] = None,
id_: Optional[str] = None,
) -> None:
if not isinstance(url, (str, list)):
@@ -54,6 +54,8 @@ class Track:
raise TypeError(f"Expected id_ to be a {str}, not {type(id_)}")
if not isinstance(edition, (str, type(None))):
raise TypeError(f"Expected edition to be a {str}, not {type(edition)}")
if not isinstance(data, (dict, type(None))):
raise TypeError(f"Expected data to be a {dict}, not {type(data)}")
invalid_urls = ", ".join(set(type(x) for x in url if not isinstance(x, str)))
if invalid_urls:
@@ -74,7 +76,7 @@ class Track:
self.name = name
self.drm = drm
self.edition: str = edition
self.extra: Any = extra or {} # allow anything for extra, but default to a dict
self.data = data or {}
if not id_:
this = copy(self)