Exemplo n.º 1
0
    def generate(cls, maxcount, *dirs):
        playlist = []
        tree = Tree()

        for f in fwalk(*dirs):
            try:
                tags = tuple([(key, tuple(value))
                              for key, value in get_tags(f)])
            except ValueError:
                continue
            h = hash(tags)
            while True:
                try:
                    tree[h] = f
                    break
                except KeyError:
                    h = h + 1 if h > 0 else h - 1
            if not len(playlist):
                playlist.append(f)

        for i in xrange(maxcount - 1):
            with open(playlist[-1], 'rb') as f:
                while True:
                    key = hash(f.read(2048))
                    g = tree.get(key, True)
                    if g not in playlist:
                        playlist.append(g)
                        break
        return iter(playlist)
Exemplo n.º 2
0
	def generate(cls, maxcount, *dirs):
		playlist = []
		tree = Tree()

		for f in fwalk(*dirs):
			try:
				tags = tuple([(key, tuple(value)) for key, value in get_tags(f)])
			except ValueError:
				continue
			h = hash(tags)
			while True:
				try:
					tree[h] = f
					break
				except KeyError:
					h = h + 1 if h > 0 else h - 1
			if not len(playlist):
				playlist.append(f)
		
		for i in xrange(maxcount - 1):
			with open(playlist[-1], 'rb') as f:
				while True:
					key = hash(f.read(2048))
					g = tree.get(key, True)
					if g not in playlist:
						playlist.append(g)
						break
		return iter(playlist)
Exemplo n.º 3
0
    def generate(cls, maxcount, *dirs):
        intracks = list(cls.get_track_tags(fwalk(*dirs)))
        tracks = cls.build_track_table(intracks)

        ntracks = len(tracks)
        track0 = choice(intracks).fname
        del intracks
        pls = cls(track0, ntracks)
        seen = set([track0])

        print >> stderr, 'Iteration started.'
        while len(pls) < maxcount:
            i = pls.next()
            if not i in tracks:
                continue
            t = tracks[i]
            i = 0
            if len(t) > 1:
                i = pls.next(1) % len(t)
            if not t[i] in seen:
                seen.add(t[i])
                pls.append(t[i])
        return iter(pls.tracks)
Exemplo n.º 4
0
	def generate(cls, maxcount, *dirs):
		intracks = list(cls.get_track_tags(fwalk(*dirs)))
		tracks = cls.build_track_table(intracks)
		
		ntracks = len(tracks)
		track0 = choice(intracks).fname
		del intracks
		pls = cls(track0, ntracks)
		seen = set([track0])


		print >>stderr, 'Iteration started.'
		while len(pls) < maxcount:
			i = pls.next()
			if not i in tracks:
				continue
			t = tracks[i]
			i = 0
			if len(t) > 1:
				i = pls.next(1) % len(t)
			if not t[i] in seen:
				seen.add(t[i])
				pls.append(t[i])
		return iter(pls.tracks)
Exemplo n.º 5
0
			self.__queue.put(track)
			self.__tracks.append(track)

Track = namedtuple('Track', ['fname', 'tags'])

if __name__ == '__main__':
	from argparse import ArgumentParser
	from random import choice
	parser = ArgumentParser(description = 'Generate a playlist')
	parser.add_argument('playlist', help = 'Playlist to generate', action = 'store')
	parser.add_argument('directories', metavar = 'dir', help = 'Directories to search', action = 'store', nargs = '+')
	parser.add_argument('-n', '--count', dest = 'count', type = int, help = 'Maximum number of tracks in generated playlist.', default = 0)
	args = parser.parse_args(argv[1:])

	intracks = []
	for t in fwalk(*args.directories):
		try:
			tags = tuple([(key, tuple(value)) for key, value in get_tags(t)])
		except ValueError:
			continue
		intracks.append(Track(t, tags))

	tracks = defaultdict(list)

	ntracks = len(intracks)
	for t in intracks:
		tracks[hash(t.tags) % ntracks].append(t.fname)
	
	track0 = choice(intracks).fname
	del intracks
	pls = Playlist(track0, ntracks)
Exemplo n.º 6
0
                        action='store')
    parser.add_argument('directories',
                        metavar='dir',
                        help='Directories to search',
                        action='store',
                        nargs='+')
    parser.add_argument('-n',
                        '--count',
                        dest='count',
                        type=int,
                        help='Maximum number of tracks in generated playlist.',
                        default=0)
    args = parser.parse_args(argv[1:])

    intracks = []
    for t in fwalk(*args.directories):
        try:
            tags = tuple([(key, tuple(value)) for key, value in get_tags(t)])
        except ValueError:
            continue
        intracks.append(Track(t, tags))

    tracks = defaultdict(list)

    ntracks = len(intracks)
    for t in intracks:
        tracks[hash(t.tags) % ntracks].append(t.fname)

    track0 = choice(intracks).fname
    del intracks
    pls = Playlist(track0, ntracks)
Exemplo n.º 7
0
        match, node = self.__get_node(key)
        if match is self.NODE_EXACT:
            return node.value
        elif match is self.NODE_APPROXIMATE and approximate:
            return node.value
        else:
            raise KeyError('No such key: %s' % key)


if __name__ == '__main__':
    root = u'/home/music'

    playlist = []
    tree = Tree()

    for f in fwalk(root):
        try:
            tags = tuple([(key, tuple(value)) for key, value in get_tags(f)])
        except ValueError:
            continue
        h = hash(tags)
        while True:
            try:
                tree[h] = f
                break
            except KeyError:
                h = h + 1 if h > 0 else h - 1
        if not len(playlist):
            playlist.append(f)

    for i in xrange(50):
Exemplo n.º 8
0
	def get(self, key, approximate = False):
		match, node = self.__get_node(key)
		if match is self.NODE_EXACT:
			return node.value
		elif match is self.NODE_APPROXIMATE and approximate:
			return node.value
		else:
			raise KeyError('No such key: %s' % key)

if __name__ == '__main__':
	root = u'/home/music'

	playlist = []
	tree = Tree()

	for f in fwalk(root):
		try:
			tags = tuple([(key, tuple(value)) for key, value in get_tags(f)])
		except ValueError:
			continue
		h = hash(tags)
		while True:
			try:
				tree[h] = f
				break
			except KeyError:
				h = h + 1 if h > 0 else h - 1
		if not len(playlist):
			playlist.append(f)
	
	for i in xrange(50):