def from_args(self, args): name = args.command if name == 'get': return GetCommand() elif name == 'set': return OperationCommand(SetOperation(args.__dict__)) elif name == 'rename': template = FreiTemplate(args.format) return OperationCommand(RenameOperation(template)) elif name == 'extract': template = FreiTemplate(args.format) return OperationCommand(ExtractOperation(template)) elif name == 'humanize': return OperationCommand(HumanizeOperation())
def __init__(self, template=FreiTemplate(DEFAULT_FORMAT)): self.template = template
def run(self, args): songs = self.get_songs(args.files) template = FreiTemplate(args.format) for song in songs: print template.format(song)
def test_extract(self): template = FreiTemplate('%tracknumber %title.mp3') string = '01 Hello World.mp3' tags = {'tracknumber': '01', 'title': 'Hello World'} self.assertEquals(tags, template.extract(string))
def test_format(self): tags = {'artist': 'Bob Marley', 'title': 'One Love'} template = FreiTemplate(' %artist - %title ') self.assertEquals('Bob Marley - One Love', template.format(tags))