source fix

This commit is contained in:
Jesse Bannon 2022-09-16 21:02:30 -07:00
parent 7e02e6a5d5
commit 357b3401d5

View file

@ -38,31 +38,18 @@ class EntryParent(BaseEntry):
[child.to_type(Entry) for child in self.child_entries if self.is_entry(child)] [child.to_type(Entry) for child in self.child_entries if self.is_entry(child)]
) )
def _playlist_variables( def _playlist_variables(self, idx: int, children: List[TBaseEntry], parent_type: str) -> Dict:
self, idx: int, children: List[TBaseEntry], write_playlist: bool _count = self.kwargs_get("playlist_count", len(children))
) -> Dict: _index = (children[idx].kwargs_get("playlist_index", idx + 1),)
child = children[idx]
# number of children on the current entry if parent_type == ParentType.SOURCE:
if (playlist_count := self.kwargs_get("playlist_count")) is not None: return {"source_index": _index, "source_count": _count}
assert playlist_count == len(children) return {
if (playlist_index := child.kwargs_get("playlist_index")) is not None:
assert playlist_index == idx + 1
out = {
"source_index": self.kwargs_get("source_index", 1), "source_index": self.kwargs_get("source_index", 1),
"source_count": self.kwargs_get("source_count", 1), "source_count": self.kwargs_get("source_count", 1),
"playlist_index": _index,
"playlist_count": _count,
} }
if write_playlist:
out = dict(
out,
**{
"playlist_index": idx + 1,
"playlist_count": len(children),
},
)
return out
def _parent_variables(self, parent_type: str) -> Dict: def _parent_variables(self, parent_type: str) -> Dict:
return dict( return dict(
@ -89,6 +76,9 @@ class EntryParent(BaseEntry):
def _set_child_variables(self, parents: Optional[List["EntryParent"]] = None) -> "EntryParent": def _set_child_variables(self, parents: Optional[List["EntryParent"]] = None) -> "EntryParent":
if parents is None: if parents is None:
parents = [self] parents = [self]
self.add_kwargs(
self._playlist_variables(idx=0, children=parents, parent_type=ParentType.SOURCE)
)
kwargs_to_add: Dict = {} kwargs_to_add: Dict = {}
if len(parents) >= 1: if len(parents) >= 1:
@ -105,7 +95,7 @@ class EntryParent(BaseEntry):
for idx, entry_child in enumerate(self.entry_children()): for idx, entry_child in enumerate(self.entry_children()):
entry_child.add_kwargs( entry_child.add_kwargs(
self._playlist_variables( self._playlist_variables(
idx=idx, children=self.entry_children(), write_playlist=True idx=idx, children=self.entry_children(), parent_type=ParentType.PLAYLIST
) )
) )
entry_child.add_kwargs(kwargs_to_add) entry_child.add_kwargs(kwargs_to_add)
@ -113,7 +103,7 @@ class EntryParent(BaseEntry):
for idx, parent_child in enumerate(self.parent_children()): for idx, parent_child in enumerate(self.parent_children()):
parent_child.add_kwargs( parent_child.add_kwargs(
self._playlist_variables( self._playlist_variables(
idx=idx, children=self.parent_children(), write_playlist=False idx=idx, children=self.parent_children(), parent_type=ParentType.SOURCE
) )
) )
parent_child._set_child_variables(parents=parents + [parent_child]) parent_child._set_child_variables(parents=parents + [parent_child])