mirror of https://github.com/devine-dl/devine.git
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:
parent
a6a5699577
commit
90c544966a
|
@ -207,7 +207,12 @@ class DASH:
|
||||||
language=track_lang,
|
language=track_lang,
|
||||||
is_original_lang=language and is_close_match(track_lang, [language]),
|
is_original_lang=language and is_close_match(track_lang, [language]),
|
||||||
descriptor=Video.Descriptor.DASH,
|
descriptor=Video.Descriptor.DASH,
|
||||||
extra=(rep, adaptation_set),
|
data={
|
||||||
|
"dash": {
|
||||||
|
"representation": rep,
|
||||||
|
"adaptation_set": adaptation_set
|
||||||
|
}
|
||||||
|
},
|
||||||
**track_args
|
**track_args
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,11 @@ class HLS:
|
||||||
bitrate=playlist.stream_info.average_bandwidth or playlist.stream_info.bandwidth,
|
bitrate=playlist.stream_info.average_bandwidth or playlist.stream_info.bandwidth,
|
||||||
descriptor=Video.Descriptor.HLS,
|
descriptor=Video.Descriptor.HLS,
|
||||||
drm=session_drm,
|
drm=session_drm,
|
||||||
extra=playlist,
|
data={
|
||||||
|
"hls": {
|
||||||
|
"playlist": playlist
|
||||||
|
}
|
||||||
|
},
|
||||||
# video track args
|
# video track args
|
||||||
**(dict(
|
**(dict(
|
||||||
range_=Video.Range.DV if any(
|
range_=Video.Range.DV if any(
|
||||||
|
@ -166,7 +170,11 @@ class HLS:
|
||||||
is_original_lang=language and is_close_match(track_lang, [language]),
|
is_original_lang=language and is_close_match(track_lang, [language]),
|
||||||
descriptor=Audio.Descriptor.HLS,
|
descriptor=Audio.Descriptor.HLS,
|
||||||
drm=session_drm if media.type == "AUDIO" else None,
|
drm=session_drm if media.type == "AUDIO" else None,
|
||||||
extra=media,
|
data={
|
||||||
|
"hls": {
|
||||||
|
"media": media
|
||||||
|
}
|
||||||
|
},
|
||||||
# audio track args
|
# audio track args
|
||||||
**(dict(
|
**(dict(
|
||||||
bitrate=0, # TODO: M3U doesn't seem to state bitrate?
|
bitrate=0, # TODO: M3U doesn't seem to state bitrate?
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Track:
|
||||||
name: Optional[str] = None,
|
name: Optional[str] = None,
|
||||||
drm: Optional[Iterable[DRM_T]] = None,
|
drm: Optional[Iterable[DRM_T]] = None,
|
||||||
edition: Optional[str] = None,
|
edition: Optional[str] = None,
|
||||||
extra: Optional[Any] = None,
|
data: Optional[dict] = None,
|
||||||
id_: Optional[str] = None,
|
id_: Optional[str] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
if not isinstance(url, (str, list)):
|
if not isinstance(url, (str, list)):
|
||||||
|
@ -54,6 +54,8 @@ class Track:
|
||||||
raise TypeError(f"Expected id_ to be a {str}, not {type(id_)}")
|
raise TypeError(f"Expected id_ to be a {str}, not {type(id_)}")
|
||||||
if not isinstance(edition, (str, type(None))):
|
if not isinstance(edition, (str, type(None))):
|
||||||
raise TypeError(f"Expected edition to be a {str}, not {type(edition)}")
|
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)))
|
invalid_urls = ", ".join(set(type(x) for x in url if not isinstance(x, str)))
|
||||||
if invalid_urls:
|
if invalid_urls:
|
||||||
|
@ -74,7 +76,7 @@ class Track:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.drm = drm
|
self.drm = drm
|
||||||
self.edition: str = edition
|
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_:
|
if not id_:
|
||||||
this = copy(self)
|
this = copy(self)
|
||||||
|
|
Loading…
Reference in New Issue