Ejemplo 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)
Ejemplo n.º 2
0
	def get_track_tags(cls, files):
		for t in files:
			try:
				tags = tuple([(key, tuple(value)) for key, value in get_tags(t)])
			except ValueError:
				continue
			yield cls.Track(t, tags)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def get_track_tags(cls, files):
     for t in files:
         try:
             tags = tuple([(key, tuple(value))
                           for key, value in get_tags(t)])
         except ValueError:
             continue
         yield cls.Track(t, tags)
Ejemplo n.º 5
0
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)
	seen = set([track0])
Ejemplo n.º 6
0
                        nargs='+')
    parser.add_argument('--base-dir',
                        dest='basedir',
                        help='Base directory for each item in playlist',
                        action='store')
    args = parser.parse_args(argv[1:])

    for playlist in args.playlists:
        with codecs_open(playlist, 'rU', 'utf8') as f:
            for line in f:
                if line[-1] == '\n':
                    line = line[:-1]
                if args.basedir:
                    line = join(args.basedir, line)
                try:
                    tags = get_tags(line)
                except ValueError:
                    print >> stderr, 'Failed to read tags from file:', line
                    continue
                except IOError:
                    print >> stderr, 'Unable to open file:', line
                    continue
                print >> stdout, line
                for tag, values in tags:
                    if not values:
                        continue
                    print >> stdout, '   %s: %s' % (tag, values[0])
                    indent = ' ' * (len(tag) + 3)
                    for value in values[1:]:
                        print >> stdout, indent, value
Ejemplo n.º 7
0
                        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)
    seen = set([track0])
Ejemplo n.º 8
0
if __name__ == '__main__':
	from argparse import ArgumentParser
	parser = ArgumentParser(description = 'Print tag information for tracks in playlists')
	parser.add_argument('playlists', metavar = 'playlist', help = 'Playlists to read', action = 'store', nargs = '+')
	parser.add_argument('--base-dir', dest = 'basedir', help = 'Base directory for each item in playlist', action = 'store')
	args = parser.parse_args(argv[1:])

	for playlist in args.playlists:
		with codecs_open(playlist, 'rU', 'utf8') as f:
			for line in f:
				if line[-1] == '\n':
					line = line[:-1]
				if args.basedir:
					line = join(args.basedir, line)
				try:
					tags = get_tags(line)
				except ValueError:
					print >>stderr, 'Failed to read tags from file:', line
					continue
				except IOError:
					print >>stderr, 'Unable to open file:', line
					continue
				print >>stdout, line
				for tag, values in tags:
					if not values:
						continue
					print >>stdout, '   %s: %s' % (tag, values[0])
					indent = ' ' * (len(tag) + 3)
					for value in values[1:]:
						print >>stdout, indent, value