def uri_is_valid(uri): """Checks if the given uri is a valid uri (of type file://) Will also check if the size is valid (> 0). @param uri: The location to check @type uri: C{URI} """ return (Gst.uri_is_valid(uri) and Gst.uri_get_protocol(uri) == "file" and len(os.path.basename(Gst.uri_get_location(uri))) > 0)
def uri_is_valid(uri): """Checks if the specified URI is usable (of type file://). Will also check if the size is valid (> 0). Args: uri (str): The location to check. """ return (Gst.uri_is_valid(uri) and Gst.uri_get_protocol(uri) == "file" and len(os.path.basename(Gst.uri_get_location(uri))) > 0)
def do_save_to_uri(self, timeline, uri, overwrite): if not Gst.uri_is_valid(uri) or Gst.uri_get_protocol(uri) != "file": Gst.error("Protocol not supported for file: %s" % uri) return False with tempfile.NamedTemporaryFile(suffix=".xges") as tmpxges: timeline.get_asset().save(timeline, "file://" + tmpxges.name, None, overwrite) linker = otio.media_linker.MediaLinkingPolicy.ForceDefaultLinker otio_timeline = otio.adapters.read_from_file(tmpxges.name, "xges", media_linker_name=linker) location = Gst.uri_get_location(uri) out_adapter = otio.adapters.from_filepath(location) otio.adapters.write_to_file(otio_timeline, Gst.uri_get_location(uri), out_adapter.name) return True
def element_make_from_uri(uri, type_=Gst.URIType.SRC): """Creates Gst element from URI locator """ if not Gst.uri_is_valid(uri): raise Exception("Invalid URI {}".format(uri)) proto = Gst.uri_get_protocol(uri) if proto == "tcp": u = Gst.uri_from_string(uri) return elmake("tcpserversrc", host=u.get_host(), port=u.get_port()) if not Gst.uri_protocol_is_supported(type_, proto): raise Exception("Protocol {} not supported, URI {}".format(proto, uri)) return Gst.Element.make_from_uri(type_, uri, None)
def do_can_load_uri(self, uri): try: if not Gst.uri_is_valid(uri) or Gst.uri_get_protocol(uri) != "file": return False except GLib.Error as e: Gst.error(str(e)) return False if uri.endswith(".xges"): return False try: return otio.adapters.from_filepath(Gst.uri_get_location(uri)) is not None except Exception as e: Gst.info("Could not load %s -> %s" % (uri, e)) return False
def get_uri(source): """ Check a media source as a valid file or uri and return the proper uri """ import gi gi.require_version('Gst', '1.0') from gi.repository import Gst src_info = source_info(source) if src_info['is_file']: # Is this a file? return get_uri(src_info['uri']) elif Gst.Uri.is_valid(source): # Is this a valid URI source for Gstreamer uri_protocol = Gst.uri_get_protocol(source) if Gst.Uri.protocol_is_supported(Gst.URIType.SRC, uri_protocol): return source else: raise IOError('Invalid URI source for Gstreamer') else: raise IOError('Failed getting uri for path %s: no such file' % source)