def handle(self, *args, **options): exists = 0 update = 0 insert = 0 if len(args) > 0: dirpath = abspath(args[0]) else: return "missing path, please add path to lookup\n" if not isdir(dirpath): return "path %s does not exists\n" % dirpath for fpath in importdir(dirpath): tags = checkid3(fpath) if tags is not None: sig = sigfile(fpath) exsong = Song.objects.filter(uniq=sig) if len(exsong) > 0: if exsong[0].filename != fpath: self._updatesong(exsong[0], fpath) update += 1 else: self._donothing(exsong[0]) exists += 1 else: self._createsong(tags, sig, fpath) insert += 1 self.stdout.write("%d songs already present db\n" % exists) self.stdout.write("%d songs path updated in db\n" % update) self.stdout.write("%d songs inserted in db\n" % insert)
def test_checkid3_wrongunicode(self): """ album id3 is missing """ alpha = unicode(u"tété") beta = alpha.encode('iso8859-1') datas = checkid3(beta) self.assertEqual(datas, None)
def test_checkid3_albummissing(self): """ album id3 is missing """ datas = checkid3(path.join(path.dirname(__file__), 'samples', 'missing-album.ogg')) self.assertEqual(datas, None)
def test_checkid3_genremissing(self): """ genre id3 is missing """ datas = checkid3(path.join(path.dirname(__file__), 'samples', 'missing-genre.ogg')) self.assertNotEqual(datas, None)
def test_checkid3_notag(self): """ Good id3 """ datas = checkid3(path.join(path.dirname(__file__), 'samples', 'notag.ogg')) self.assertEqual(datas, None)
def test_checkid3(self): """ Good id3 """ first = path.join(path.dirname(__file__), 'samples', 'first', 'test.ogg') datas = checkid3(first) self.assertEqual(datas['genre'], 'Sample') self.assertEqual(datas['album'], 'Lorem')