def filter_location (self, location):
        url = urlutil.UrlParse(location)
        
        if not url.is_local:
            return

        hints_list = []
        p = xspf.Playlist()
        try:
            p.parse (url.path)
        except Exception:
            return
            
        basename = path.basename(url.path)
        
        for t in p.tracks:
            if t.location is None:
                continue
            r = {'location': urlutil.normalize(t.location, basename)}
            if t.title is not None:
                r['title'] = t.title
            if t.creator is not None:
                r['artist'] = t.creator
            hints_list.append(r)
            
        return hints_list
Пример #2
0
    def filter_location(self, location):
        url = urlutil.UrlParse(location)

        if not url.is_local or not path.isdir(url.path):
            return

        files = glob.glob(path.join(url.path, "*"))
        files.sort()

        return [{"location": urlutil.normalize(loc)} for loc in files]
    def filter_location(self, location):
        url = urlutil.UrlParse(location)
        if not url.is_local or not path.isdir(url.path):
            return

        files = glob(path.join(location, "*"))
        files.sort()

        to_hints = lambda loc: {"location": urlutil.normalize(loc)}
        return map(to_hints, files)
    def filter_location(self, location):
        url = urlutil.UrlParse(location)
        if not url.is_local:
            fd = gnomevfs.open(url.unparse())

            def read_all():
                buff = ""
                try:
                    while 1:
                        buff += fd.read(1024)
                except gnomevfs.EOFError:
                    pass
                return buff

            fd.read = read_all
        else:
            fd = open(url.path)

        try:
            zfile = zipfile.ZipFile(fd)
        except zipfile.BadZipfile:
            return
        except IOError:
            # it's not a file
            return

        try:
            buff = zfile.read("maindata.xml")
        except KeyError:
            # zip file does not contain the file
            return

        try:
            root = minidom.parseString(buff)
        except ExpatError:
            # Malformed xml
            return

        # Iterate over tracks
        hints_list = []
        for node in Evaluate("/k3b_audio_project/contents/track", root):
            try:
                hints_list.append({"location": node.attributes["url"].value})
            except KeyError:
                # skip elements with not 'url' attribute set
                pass

        return hints_list
    def filter_location(self, location):
        url = urlutil.UrlParse(location)
        if not url.is_local:
            fd = gnomevfs.open(url.unparse())

            def read_all():
                buff = ""
                try:
                    while 1:
                        buff += fd.read(1024)
                except gnomevfs.EOFError:
                    pass
                return buff

            fd.read = read_all
        else:
            try:
                fd = open(url.path)
            except IOError:
                # Could not open the filename
                return

        try:
            zfile = zipfile.ZipFile(fd)
        except zipfile.BadZipfile:
            return
        except IOError:
            # it's not a file
            return

        try:
            buff = zfile.read("maindata.xml")
        except KeyError:
            # zip file does not contain the file
            fd.close()
            return

        fd.close()

        try:
            root = minidom.parseString(buff)
        except ExpatError:
            # Malformed xml
            return

        # Iterate over tracks
        hints_list = []
        for node in Evaluate("/k3b_audio_project/contents/track", root):
            try:
                hints_list.append({"location": node.attributes["url"].value})
            except KeyError:
                # skip elements with not 'url' attribute set
                pass

        # New versions of K3B changed the internal structure
        # since there's no version present for the file format we'll just
        # try both
        for node in Evaluate("/k3b_audio_project/contents/track/sources/file",
                             root):
            try:
                hints_list.append({"location": node.attributes["url"].value})
            except KeyError:
                # skip elements with not 'url' attribute set
                pass

        return hints_list