Ejemplo n.º 1
0
def recursive_tracks_from_file(gfile: Gio.File) -> Iterable[Track]:
    """
        Get recursive tracks from Gio.File
        If it's a directory, expands
        Gets only valid tracks
    """
    ftype = gfile.query_info('standard::type', Gio.FileQueryInfoFlags.NONE,
                             None).get_file_type()
    if ftype == Gio.FileType.DIRECTORY:
        file_infos = gfile.enumerate_children('standard::name',
                                              Gio.FileQueryInfoFlags.NONE,
                                              None)
        files = (gfile.get_child(fi.get_name()) for fi in file_infos)
        for sub_gfile in files:
            for i in recursive_tracks_from_file(sub_gfile):
                yield i
    else:
        uri = gfile.get_uri()
        if is_valid_track(uri):
            yield Track(uri)
Ejemplo n.º 2
0
def guess_content_type(file: Gio.File) -> str:
    info: Gio.FileInfo = file.query_info(
        Gio.FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
        Gio.FileQueryInfoFlags.NONE, None)
    return info.get_attribute_as_string(
        Gio.FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)