Commits

Alan Franzoni committed 84470c3

Enh: setup next step.

Comments (0)

Files changed (3)

mp3infodetector/albumblackboard.py

         self[self._key(obj)].add(obj)
 
 
-
-
 class Candidate(object):
     OPTIMAL = 100
     WORST = 1
 #    SPECIAL_PREFIX = "6Qij4qmaWNnRs23aLD8Y" # prefixes metadata.
 
     def __init__(self, tracks_filenames, containing_dir=None, parent_dir=None):
-        self.candidates = dict( (filename, CandidateMap(lambda candidate: candidate.entry)) for filename in tracks_filenames )
+        self.candidates = dict(
+            (filename, CandidateMap(lambda candidate: candidate.entry)) for filename in tracks_filenames)
         self.containing_dir = containing_dir
         self.parent_dir = parent_dir
         self.metadata = defaultdict(lambda: CandidateMap(lambda candidate: candidate.entry))
 
-        # probably wrong way of organizing metadata. ->
-        # we could have many suggestions all with different metadata? ->
-        # album from directory name, etc...
-        # we shouldn't do it in multiple passes like tracknames, probably, otherwise?
-#        self.metadata = defaultdict(lambda: CandidateMap(lambda candidate: candidate.entry))
-#        dict( (field, )
-#                for field in ("album", "author", "year", "various_artists", "collection") )
 
-#    def set_metadata(self, key, value):
-#        self.candidates[self.SPECIAL_PREFIX + key] = value
-#
-#    def get_metadata(self, key):
-#        return self.candidates.setdefault(self.SPECIAL_PREFIX + key, CandidateMap(lambda candidate: candidate.entry))
+    def get_top_candidates(self):
+        # get dictionary top candidates, but only if their confidence is at least threshold
+        return dict(
+            [(fn, dict(
+                [(what, max(all_candidates, key=lambda c: c.confidence).value)
+                for what, all_candidates in candidatemap.iteritems()]
+                        )
+            ) for fn, candidatemap in self.candidates.iteritems()]
+        )
 
 
 

mp3infodetector/ks/chooser.py

+# -*- coding: utf-8 -*-
+
+from mp3infodetector.ks.knowledgesource import KnowledgeSource
+from mp3infodetector.albumblackboard import Candidate
+
+class AlbumChooser(KnowledgeSource):
+    @classmethod
+    def is_interested_in(cls, blackboard):
+        # album should not be picked yet with 100% confidence for all candidates
+        # there must be album info in candidates or metadata
+        raise NotImplementedError
+
+    @classmethod
+    def evaluete(cls, blackboard):
+        # check if an album entry is repeated in many (all?) songs and if that
+        # also appears in metadata candidates
+        # if yes, upvote that album name in all candidates and metadata, downvote
+        # anything else.
+        raise NotImplementedError
+

mp3infodetector/test/test_acceptance_whole.py

 import sys
 
 containing_dir_1 = "CapaRezza - Habemus Capa"
-entries_1 = """01-Mors mea tacci tua (intro).mp3
-02-Annunciatemi al pubblico.mp3
-03-Torna catalessi.mp3
-04-Gli insetti del podere.mp3
-05-Dalla parte del toro.mp3
-06-Ninna nanna di Mazzarò.mp3
-07-Il silenzio dei colpevoli.mp3
-08-Profilo psichico.mp3
-09-La mia parte intollerante.mp3
-10-Inno verdano.mp3
-11-Epocalisse.mp3
-12-Tii-Yan.mp3
-13-The auditels family.mp3
-14-Ti giri.mp3
-15-Titoli.mp3
-16-Felici ma trimoni.mp3
-17-Sssaasss.mp3
-18-Sono troppo stitico.mp3
-19-Habemus Capa.mp3""".split("\n")
+entries_1 = """01-Mors mea tacci tua (intro)
+02-Annunciatemi al pubblico
+03-Torna catalessi
+04-Gli insetti del podere
+05-Dalla parte del toro
+06-Ninna nanna di Mazzarò
+07-Il silenzio dei colpevoli
+08-Profilo psichico
+09-La mia parte intollerante
+10-Inno verdano
+11-Epocalisse
+12-Tii-Yan
+13-The auditels family
+14-Ti giri
+15-Titoli
+16-Felici ma trimoni
+17-Sssaasss
+18-Sono troppo stitico
+19-Habemus Capa""".split("\n")
 
 containing_dir_2 = "99 Posse - Cerco Tiempo"
-entries_2 = """99 Posse - Cerco Tiempo - 01 - Si Ttu.mp3
-99 Posse - Cerco Tiempo - 02 - Non C'è Tempo.mp3
-99 Posse - Cerco Tiempo - 03 - Pecche'.mp3
-99 Posse - Cerco Tiempo - 04 - Senza Ritornello.mp3
-99 Posse - Cerco Tiempo - 05 - Balla E Piensa.mp3
-99 Posse - Cerco Tiempo - 06 - La Gatta Mammona.mp3
-99 Posse - Cerco Tiempo - 07 - Fujakka.mp3
-99 Posse - Cerco Tiempo - 08 - Facendo La Storia - Making Hi.mp3
-99 Posse - Cerco Tiempo - 09 - Spara.mp3
-99 Posse - Cerco Tiempo - 10 - Avrei Voluto Conoscervi.mp3""".split("\n")
+entries_2 = """99 Posse - Cerco Tiempo - 01 - Si Ttu
+99 Posse - Cerco Tiempo - 02 - Non C'è Tempo
+99 Posse - Cerco Tiempo - 03 - Pecche'
+99 Posse - Cerco Tiempo - 04 - Senza Ritornello
+99 Posse - Cerco Tiempo - 05 - Balla E Piensa
+99 Posse - Cerco Tiempo - 06 - La Gatta Mammona
+99 Posse - Cerco Tiempo - 07 - Fujakka
+99 Posse - Cerco Tiempo - 08 - Facendo La Storia - Making Hi
+99 Posse - Cerco Tiempo - 09 - Spara
+99 Posse - Cerco Tiempo - 10 - Avrei Voluto Conoscervi""".split("\n")
 
 
 class TestRealLifeMp3Names(TestCase):
         pass
 
     def test_capa(self):
-        run_loop(entries_1, containing_dir_1).candidates
+        bb = run_loop(entries_1, containing_dir_1)
+        for key, candidates in bb.get_top_candidates().iteritems():
+            print key, candidates, "\n"
 
     def test_99(self):
         bb = run_loop(entries_2, containing_dir_2)
         #sys.stdout.write(str(bb.candidates))
-        sys.stdout.write(str(bb.metadata))
+        #sys.stdout.write(str(bb.metadata))