Ejemplo n.º 1
0
    def write(self):
        with translate_errors():
            try:
                tag = mutagen.apev2.APEv2(self['~filename'])
            except mutagen.apev2.APENoHeaderError:
                tag = mutagen.apev2.APEv2()

        # Remove any text keys we read in
        for key in iterkeys(tag):
            value = tag[key]
            if (value.kind == mutagen.apev2.TEXT and
                key.lower() not in self.IGNORE):
                del(tag[key])

        # Write all tags we have
        lower = self.as_lowercased()
        for key in lower.realkeys():
            new_key = self.SNART.get(key, key)
            if new_key in self.IGNORE:
                continue
            new_key = self.__titlecase(new_key)
            tag[new_key] = lower.list(key)

        with translate_errors():
            tag.save(self["~filename"])
        self.sanitize()
Ejemplo n.º 2
0
 def headers(self):
     for button in iterkeys(self.__headers):
         if button.get_active():
             if button == self.__custom:
                 model_headers = [row[0] for row in self.__model]
                 self.__headers[self.__custom] = model_headers
             return self.__headers[button]
Ejemplo n.º 3
0
 def headers(self):
     for button in iterkeys(self.__headers):
         if button.get_active():
             if button == self.__custom:
                 model_headers = [row[0] for row in self.__model]
                 self.__headers[self.__custom] = model_headers
             return self.__headers[button]
Ejemplo n.º 4
0
 def test_keys(self):
     items = []
     for i in range(20):
         items.append(self.Fake(i))
         items[-1].key = i + 100
     self.library.add(items)
     self.failUnlessEqual(
         sorted(self.library.keys()), list(range(100, 120)))
     self.failUnlessEqual(
         sorted(iterkeys(self.library)), list(range(100, 120)))
Ejemplo n.º 5
0
 def iterkeys(self):
     return iterkeys(self._contents)
Ejemplo n.º 6
0
 def iterkeys(self):
     return iterkeys(self._contents)
Ejemplo n.º 7
0
    def __update_done(self, stations):
        if not stations:
            print_w("Loading remote station list failed.")
            return

        # filter stations based on quality, listenercount
        def filter_stations(station):
            peak = station.get("~#listenerpeak", 0)
            if peak < 10:
                return False
            aac = "AAC" in station("~format")
            bitrate = station("~#bitrate", 50)
            if (aac and bitrate < 40) or (not aac and bitrate < 60):
                return False
            return True

        stations = filter(filter_stations, stations)

        # group them based on the title
        groups = {}
        for s in stations:
            key = s("~title~artist")
            groups.setdefault(key, []).append(s)

        # keep at most 2 URLs for each group
        stations = []
        for key, sub in iteritems(groups):
            sub.sort(key=lambda s: s.get("~#listenerpeak", 0), reverse=True)
            stations.extend(sub[:2])

        # only keep the ones in at least one category
        all_ = [self.filters.query(k) for k in self.filters.keys()]
        assert all_
        anycat_filter = reduce(lambda x, y: x | y, all_)
        stations = list(filter(anycat_filter.search, stations))

        # remove listenerpeak
        for s in stations:
            s.pop("~#listenerpeak", None)

        # update the libraries
        stations = dict(((s.key, s) for s in stations))
        # don't add ones that are in the fav list
        for fav in iterkeys(self.__fav_stations):
            stations.pop(fav, None)

        # separate
        o, n = set(iterkeys(self.__stations)), set(stations)
        to_add, to_change, to_remove = n - o, o & n, o - n
        del o, n

        # migrate stats
        to_change = [stations.pop(k) for k in to_change]
        for new in to_change:
            old = self.__stations[new.key]
            # clear everything except stats
            AudioFile.reload(old)
            # add new metadata except stats
            for k in (x for x in iterkeys(new) if x not in MIGRATE):
                old[k] = new[k]

        to_add = [stations.pop(k) for k in to_add]
        to_remove = [self.__stations[k] for k in to_remove]

        self.__stations.remove(to_remove)
        self.__stations.changed(to_change)
        self.__stations.add(to_add)
Ejemplo n.º 8
0
    def __update_done(self, stations):
        if not stations:
            print_w("Loading remote station list failed.")
            return

        # filter stations based on quality, listenercount
        def filter_stations(station):
            peak = station.get("~#listenerpeak", 0)
            if peak < 10:
                return False
            aac = "AAC" in station("~format")
            bitrate = station("~#bitrate", 50)
            if (aac and bitrate < 40) or (not aac and bitrate < 60):
                return False
            return True
        stations = filter(filter_stations, stations)

        # group them based on the title
        groups = {}
        for s in stations:
            key = s("~title~artist")
            groups.setdefault(key, []).append(s)

        # keep at most 2 URLs for each group
        stations = []
        for key, sub in iteritems(groups):
            sub.sort(key=lambda s: s.get("~#listenerpeak", 0), reverse=True)
            stations.extend(sub[:2])

        # only keep the ones in at least one category
        all_ = [self.filters.query(k) for k in self.filters.keys()]
        assert all_
        anycat_filter = reduce(lambda x, y: x | y, all_)
        stations = filter(anycat_filter.search, stations)

        # remove listenerpeak
        for s in stations:
            s.pop("~#listenerpeak", None)

        # update the libraries
        stations = dict(((s.key, s) for s in stations))
        # don't add ones that are in the fav list
        for fav in iterkeys(self.__fav_stations):
            stations.pop(fav, None)

        # separate
        o, n = set(iterkeys(self.__stations)), set(stations)
        to_add, to_change, to_remove = n - o, o & n, o - n
        del o, n

        # migrate stats
        to_change = [stations.pop(k) for k in to_change]
        for new in to_change:
            old = self.__stations[new.key]
            # clear everything except stats
            AudioFile.reload(old)
            # add new metadata except stats
            for k in (x for x in iterkeys(new) if x not in MIGRATE):
                old[k] = new[k]

        to_add = [stations.pop(k) for k in to_add]
        to_remove = [self.__stations[k] for k in to_remove]

        self.__stations.remove(to_remove)
        self.__stations.changed(to_change)
        self.__stations.add(to_add)
Ejemplo n.º 9
0
 def test_keys(self):
     self.failUnlessEqual(list(self.fdict.keys()), list(self.rdict.keys()))
     self.failUnlessEqual(
         list(iterkeys(self.fdict)), list(iterkeys(self.rdict)))