# Path: chirp/library/constants.py
# USER = "music-library"
# TFLT_WHITELIST = set((
#         u"MPG/3",   # MPEG 1/2 layer III (i.e. MP3)
# ))
# TOWN_FILE_OWNER = u"The Chicago Independent Radio Project"
# UFID_OWNER_IDENTIFIER = u"http://chirpradio.org/_ufid/1"
# MUTAGEN_UFID_KEY = u"UFID:%s" % UFID_OWNER_IDENTIFIER
# TXXX_ALBUM_ID_DESCRIPTION = u"CHIRP Album ID"
# TXXX_ALBUM_ID_KEY = u"TXXX:%s" % TXXX_ALBUM_ID_DESCRIPTION
# TXXX_FRAME_COUNT_DESCRIPTION = u"Frame Count"
# TXXX_FRAME_COUNT_KEY = u"TXXX:%s" % TXXX_FRAME_COUNT_DESCRIPTION
# TXXX_FRAME_SIZE_DESCRIPTION = u"Frame Size"
# TXXX_FRAME_SIZE_KEY = u"TXXX:%s" % TXXX_FRAME_SIZE_DESCRIPTION
# DEFAULT_ID3_TEXT_ENCODING = 3  # 3 == UTF-8
# TIT2_IMPORT_GUEST_FORMAT = " (w/ %(guest)s)"
# ID3_TAG_BLACKLIST = set((
#         # Terms of use frame: we do not want any files in the library that
#         # have special terms.
#         # TODO(trow): Uncomment this.
#         # "USER",
#         ))
# ID3_TAG_WHITELIST = set((
#         "TALB",  # Album/Movie/Show title
#         "TBPM",  # Beats per minute,
#         "TCOM",  # Composer
#         "TCON",  # Content type
#         "TCOP",  # Copyright
#         "TDLY",  # Playlist delay
#         "TDOR",  # Original release time
#         "TDRC",  # Recording time
#         "TDRL",  # Release time
#         "TDTG",  # Tagging time
#         "TENC",  # Encoded by
#         "TEXT",  # Lyricist/text writer
#         "TFLT",  # File type
#         "TIT1",  # Content group description
#         "TIT2",  # Title/songname/content description
#         "TIT3",  # Subtitle/Description refinement
#         "TKEY",  # Initial key
#         "TLAN",  # Language
#         "TLEN",  # Length
#         "TMED",  # Media type
#         "TOAL",  # Original album/movie/show title
#         "TOLY",  # Original lyricist(s)/text writer(s)
#         "TOPE",  # Original artist(s)/performer(s)
#         "TOWN",  # File owner
#         "TPE1",  # Lead performer(s)/Soloist(s)
#         "TPE2",  # Band/orchestra/accompaniment
#         "TPE3",  # Conductor/performer refinement
#         "TPE4",  # Interpreted, remixed, or otherwise modified by
#         "TPOS",  # Part of a set
#         "TPUB",  # Publisher
#         "TRCK",  # Track number/position in set
#         "TRSN",  # Internet radio station name
#         "TRSO",  # Internet radio station owner
#         "TSOA",  # Album sort order
#         "TSOP",  # Performer sort order
#         "TSOT",  # Title sort order
#         "TSRC",  # ISRC (international standard recording code)
#         "TSSE",  # Software/hardware and settings used when encoding
# 
#         "UFID",  # Unique file identifier
# 
#         TXXX_ALBUM_ID_KEY,  # Used to store the album's ID.
#         TXXX_FRAME_COUNT_KEY,  # The number of MP3 frames in this file.
#         TXXX_FRAME_SIZE_KEY,   # The size in bytes of all the MP3 frames.
# ))
# ID3_TAG_STRIPPED_ON_IMPORT = set((
#         "TFLT",  # File type
#         "TLEN",  # Length
#         "TOWN",  # File owner
# ))
# ID3_TAG_REQUIRED = set((
#         "TFLT",  # File type
#         "TIT2",  # Title/songname/content description
#         "TLEN",  # Length
#         "TOWN",  # File owner
#         "TPE1",  # Lead performer(s)/Soloist(s)
#         "TRCK",  # Track number/position in set
#         MUTAGEN_UFID_KEY,  # Unique file identifier for CHIRP
#         TXXX_ALBUM_ID_KEY,  # Used to store the album's ID.
#         TXXX_FRAME_COUNT_KEY,  # The number of MP3 frames in this file.
#         TXXX_FRAME_SIZE_KEY,   # The size in bytes of all the MP3 frames.
# ))
# 
# Path: chirp/library/id3_text.py
# _TWO_OR_MORE_SPACES_RE = re.compile(r"\s{2,}", re.UNICODE)
# def is_vanilla_text(tag):
# def standardize(tag):


import unittest
import mutagen.id3
from chirp.library import constants
from chirp.library import id3_text



class ID3TextTest(unittest.TestCase):

    def test_is_vanilla_text(self):
        # These are vanilla text tags.
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TPE1()))
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TALB()))
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TIT2()))
        # These aren't.
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.UFID()))
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.TDRC()))
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.TLEN()))

    def test_standardize(self):
        # Check basic functionality against a vanilla tag.
        tag = mutagen.id3.TPE1(encoding=1,
                               text=["Bad whitespace   ",
                                     " ",  # Empty should be stripped out
                                     "  Bad    whitespace"])
        id3_text.standardize(tag)
        self.assertEqual(constants.DEFAULT_ID3_TEXT_ENCODING, tag.encoding)
        self.assertEqual(["Bad whitespace", "Bad whitespace"], tag.text)
        # Passing in a non-text tag should be harmless.
        id3_text.standardize(mutagen.id3.UFID())

        # Check that we fix the encoding on non-vanilla tags.
        tag = mutagen.id3.TDRC(encoding=1, year=2009)
        id3_text.standardize(tag)

# Path: chirp/library/constants.py
# USER = "music-library"
# TFLT_WHITELIST = set((
#         u"MPG/3",   # MPEG 1/2 layer III (i.e. MP3)
# ))
# TOWN_FILE_OWNER = u"The Chicago Independent Radio Project"
# UFID_OWNER_IDENTIFIER = u"http://chirpradio.org/_ufid/1"
# MUTAGEN_UFID_KEY = u"UFID:%s" % UFID_OWNER_IDENTIFIER
# TXXX_ALBUM_ID_DESCRIPTION = u"CHIRP Album ID"
# TXXX_ALBUM_ID_KEY = u"TXXX:%s" % TXXX_ALBUM_ID_DESCRIPTION
# TXXX_FRAME_COUNT_DESCRIPTION = u"Frame Count"
# TXXX_FRAME_COUNT_KEY = u"TXXX:%s" % TXXX_FRAME_COUNT_DESCRIPTION
# TXXX_FRAME_SIZE_DESCRIPTION = u"Frame Size"
# TXXX_FRAME_SIZE_KEY = u"TXXX:%s" % TXXX_FRAME_SIZE_DESCRIPTION
# DEFAULT_ID3_TEXT_ENCODING = 3  # 3 == UTF-8
# TIT2_IMPORT_GUEST_FORMAT = " (w/ %(guest)s)"
# ID3_TAG_BLACKLIST = set((
#         # Terms of use frame: we do not want any files in the library that
#         # have special terms.
#         # TODO(trow): Uncomment this.
#         # "USER",
#         ))
# ID3_TAG_WHITELIST = set((
#         "TALB",  # Album/Movie/Show title
#         "TBPM",  # Beats per minute,
#         "TCOM",  # Composer
#         "TCON",  # Content type
#         "TCOP",  # Copyright
#         "TDLY",  # Playlist delay
#         "TDOR",  # Original release time
#         "TDRC",  # Recording time
#         "TDRL",  # Release time
#         "TDTG",  # Tagging time
#         "TENC",  # Encoded by
#         "TEXT",  # Lyricist/text writer
#         "TFLT",  # File type
#         "TIT1",  # Content group description
#         "TIT2",  # Title/songname/content description
#         "TIT3",  # Subtitle/Description refinement
#         "TKEY",  # Initial key
#         "TLAN",  # Language
#         "TLEN",  # Length
#         "TMED",  # Media type
#         "TOAL",  # Original album/movie/show title
#         "TOLY",  # Original lyricist(s)/text writer(s)
#         "TOPE",  # Original artist(s)/performer(s)
#         "TOWN",  # File owner
#         "TPE1",  # Lead performer(s)/Soloist(s)
#         "TPE2",  # Band/orchestra/accompaniment
#         "TPE3",  # Conductor/performer refinement
#         "TPE4",  # Interpreted, remixed, or otherwise modified by
#         "TPOS",  # Part of a set
#         "TPUB",  # Publisher
#         "TRCK",  # Track number/position in set
#         "TRSN",  # Internet radio station name
#         "TRSO",  # Internet radio station owner
#         "TSOA",  # Album sort order
#         "TSOP",  # Performer sort order
#         "TSOT",  # Title sort order
#         "TSRC",  # ISRC (international standard recording code)
#         "TSSE",  # Software/hardware and settings used when encoding
# 
#         "UFID",  # Unique file identifier
# 
#         TXXX_ALBUM_ID_KEY,  # Used to store the album's ID.
#         TXXX_FRAME_COUNT_KEY,  # The number of MP3 frames in this file.
#         TXXX_FRAME_SIZE_KEY,   # The size in bytes of all the MP3 frames.
# ))
# ID3_TAG_STRIPPED_ON_IMPORT = set((
#         "TFLT",  # File type
#         "TLEN",  # Length
#         "TOWN",  # File owner
# ))
# ID3_TAG_REQUIRED = set((
#         "TFLT",  # File type
#         "TIT2",  # Title/songname/content description
#         "TLEN",  # Length
#         "TOWN",  # File owner
#         "TPE1",  # Lead performer(s)/Soloist(s)
#         "TRCK",  # Track number/position in set
#         MUTAGEN_UFID_KEY,  # Unique file identifier for CHIRP
#         TXXX_ALBUM_ID_KEY,  # Used to store the album's ID.
#         TXXX_FRAME_COUNT_KEY,  # The number of MP3 frames in this file.
#         TXXX_FRAME_SIZE_KEY,   # The size in bytes of all the MP3 frames.
# ))
# 
# Path: chirp/library/id3_text.py
# _TWO_OR_MORE_SPACES_RE = re.compile(r"\s{2,}", re.UNICODE)
# def is_vanilla_text(tag):
# def standardize(tag):


# Path: chirp/library/id3_text_test.py
import unittest
import mutagen.id3
from chirp.library import constants
from chirp.library import id3_text




class ID3TextTest(unittest.TestCase):

    def test_is_vanilla_text(self):
        # These are vanilla text tags.
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TPE1()))
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TALB()))
        self.assertTrue(id3_text.is_vanilla_text(mutagen.id3.TIT2()))
        # These aren't.
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.UFID()))
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.TDRC()))
        self.assertFalse(id3_text.is_vanilla_text(mutagen.id3.TLEN()))

    def test_standardize(self):
        # Check basic functionality against a vanilla tag.
        tag = mutagen.id3.TPE1(encoding=1,
                               text=["Bad whitespace   ",
                                     " ",  # Empty should be stripped out
                                     "  Bad    whitespace"])
        id3_text.standardize(tag)
        self.assertEqual(constants.DEFAULT_ID3_TEXT_ENCODING, tag.encoding)
        self.assertEqual(["Bad whitespace", "Bad whitespace"], tag.text)
        # Passing in a non-text tag should be harmless.
        id3_text.standardize(mutagen.id3.UFID())

        # Check that we fix the encoding on non-vanilla tags.
        tag = mutagen.id3.TDRC(encoding=1, year=2009)
        id3_text.standardize(tag)

        self.assertEqual(constants.DEFAULT_ID3_TEXT_ENCODING, tag.encoding)