コード例 #1
0
    def write(self, au_file):
        """Adds a an audio file to the collection.

        Args:
          au_file: An AudioFile object to add to the collection.
        """
        entry_data = {}

        entry_data["order_num"], entry_data["total_num"] = order.decode(
            str(au_file.mutagen_id3.get("TRCK")))
        if entry_data["total_num"] is None:
            entry_data["total_num"] = 100

        entry_data["artist"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TPE1", _UNKNOWN_ARTIST))
        entry_data["album"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TALB", _UNKNOWN_ALBUM))
        entry_data["song"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TIT2", _UNKNOWN_SONG))
        
        # TODO(trow): Set this somehow.
        entry_data["genre"] = "Unknown"

        entry_data["dir"] = _traktor_path_quote(
            au_file.canonical_directory(prefix=self._root_dir))
        entry_data["file"] = au_file.canonical_filename()
        entry_data["volume"] = self._file_volume_quoted

        entry_data["bitrate"] = int(
            au_file.mp3_header.bit_rate_kbps * 1000)
        entry_data["size_in_kb"] = int(au_file.frame_size / 1024)
        entry_data["duration_s"] = int(au_file.duration_ms / 1000)
            
        entry_data["import_date"] = time.strftime(
            "%Y/%m/%d", time.gmtime(au_file.import_timestamp))
        entry_data["modified_date"] = entry_data["import_date"]
        entry_data["modified_time"] = "35364"

        order_num = int(entry_data["order_num"])

        # Clean up any XML-unsafe characters and wrap each value in
        # quotes.
        for k, v in entry_data.items():
            new_v = xml.sax.saxutils.quoteattr(unicode(v))
            if new_v != v:
                entry_data[k] = new_v

        # TODO(trow): For now, we build a list of all entries so that
        # we can fix the ordering --- that is because Traktor
        # idiotically chooses to order tracks based on the order they
        # appear in the NML file, not based on the track numbering.
        entry_key = (au_file.album_id, order_num)
        self._all_entries.append((entry_key, entry_data))

        # TODO(trow): This is how we should do it!
        #self._out_fh.write(_NML_ENTRY % entry_data)

        self.num_entries += 1
コード例 #2
0
    def write(self, au_file):
        """Adds a an audio file to the collection.

        Args:
          au_file: An AudioFile object to add to the collection.
        """
        entry_data = {}

        entry_data["order_num"], entry_data["total_num"] = order.decode(
            str(au_file.mutagen_id3.get("TRCK")))
        if entry_data["total_num"] is None:
            entry_data["total_num"] = 100

        entry_data["artist"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TPE1", _UNKNOWN_ARTIST))
        entry_data["album"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TALB", _UNKNOWN_ALBUM))
        entry_data["song"] = unicode_util.simplify(
            au_file.mutagen_id3.get("TIT2", _UNKNOWN_SONG))

        # TODO(trow): Set this somehow.
        entry_data["genre"] = "Unknown"

        entry_data["dir"] = _traktor_path_quote(
            au_file.canonical_directory(prefix=self._root_dir))
        entry_data["file"] = au_file.canonical_filename()
        entry_data["volume"] = self._file_volume_quoted

        entry_data["bitrate"] = int(au_file.mp3_header.bit_rate_kbps * 1000)
        entry_data["size_in_kb"] = int(au_file.frame_size / 1024)
        entry_data["duration_s"] = int(au_file.duration_ms / 1000)

        entry_data["import_date"] = time.strftime(
            "%Y/%m/%d", time.gmtime(au_file.import_timestamp))
        entry_data["modified_date"] = entry_data["import_date"]
        entry_data["modified_time"] = "35364"

        order_num = int(entry_data["order_num"])

        # Clean up any XML-unsafe characters and wrap each value in
        # quotes.
        for k, v in entry_data.items():
            new_v = xml.sax.saxutils.quoteattr(unicode(v))
            if new_v != v:
                entry_data[k] = new_v

        # TODO(trow): For now, we build a list of all entries so that
        # we can fix the ordering --- that is because Traktor
        # idiotically chooses to order tracks based on the order they
        # appear in the NML file, not based on the track numbering.
        entry_key = (au_file.album_id, order_num)
        self._all_entries.append((entry_key, entry_data))

        # TODO(trow): This is how we should do it!
        #self._out_fh.write(_NML_ENTRY % entry_data)

        self.num_entries += 1
コード例 #3
0
 def test_simplify(self):
     CASES = (
         (u"Foo", u"Foo"),
         (u"Øåø", u"Oao"),
         (u"Allá", u"Alla"),
         (u"Björk", u"Bjork"),
         (u"Édith Piaf", u"Edith Piaf"),
         (u"Stéphane", u"Stephane"),
         (u"Maxïmo", u"Maximo"),
         (u"Hüsker Dü", u"Husker Du"),
         (u"Dâm-Funk", u"Dam-Funk"),
         (u"Françoise", "Francoise"),
     )
     for before, after in CASES:
         self.assertEqual(after, unicode_util.simplify(before))