Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/chained_sei_extract #124

Merged
merged 3 commits into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions ovos_plugin_manager/ocp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,42 @@ def load(self):
LOG.error(f"Failed to load {plugin}")
continue

def extract_stream(self, uri, video=True):
def _get_sei_plugs(self, uri):
return [plug for plug in self.extractors.values()
if any((uri.startswith(f"{sei}//") for sei in plug.supported_seis))]

def _extract_from_sei(self, uri, video=True):
# attempt to use a dedicated stream extractor if requested
for plug in self.extractors.values():
for plug in self._get_sei_plugs(uri):
try:
if any((uri.startswith(f"{sei}//")
for sei in plug.supported_seis)):
return plug.extract_stream(uri, video) or {"uri": uri}
return plug.extract_stream(uri, video)
except Exception as e:
LOG.exception(f"error extracting stream with {plug}")

# let plugins parse the url and see if they can handle it
def _extract_from_url(self, uri, video=True):
for plug in self.extractors.values():
try:
if plug.validate_uri(uri):
return plug.extract_stream(uri, video) or {"uri": uri}
return plug.extract_stream(uri, video)
except Exception as e:
LOG.exception(f"error extracting stream with {plug}")

# not extractor available, return raw url
return {"uri": uri}
def extract_stream(self, uri, video=True):
meta = {}

# attempt to use a dedicated stream extractor if requested
while len(self._get_sei_plugs(uri)): # support chained extractions, where one plugin calls another
meta = self._extract_from_sei(uri, video) or {}
if meta.get("uri"):
uri = meta["uri"]
else:
break

# let plugins parse the raw url and see if they want to handle it
meta = self._extract_from_url(uri, video) or meta

# no extractor available, return raw url
return meta or {"uri": uri}


if __name__ == "__main__":
Expand Down